From 903ae8a581fac1e6917fc3e31d2ad8fb91df80c3 Mon Sep 17 00:00:00 2001 From: ctrlaltca <> Date: Thu, 12 Jul 2012 11:21:01 +0000 Subject: standardize the use of unix eol; use svn properties to enforce native eol --- demos/address-book/index.php | 52 +- .../protected/pages/AddressProvider.php | 96 +- .../address-book/protected/pages/AddressRecord.php | 68 +- demos/address-book/protected/pages/FlexApp.php | 226 ++-- .../protected/pages/flex/bin/AC_OETags.js | 538 ++++---- .../protected/pages/flex/bin/history.js | 96 +- .../pages/flex/html-template/AC_OETags.js | 538 ++++---- .../protected/pages/flex/html-template/history.js | 96 +- demos/blog-tutorial/index.php | 34 +- demos/blog-tutorial/protected/common/InfoBox.php | 24 +- demos/blog-tutorial/protected/common/NoteBox.php | 24 +- demos/blog-tutorial/protected/common/TipBox.php | 24 +- demos/blog-tutorial/protected/common/TopicList.php | 14 +- .../blog-tutorial/protected/layout/MainLayout.php | 12 +- demos/blog-tutorial/samples/day1/blog/index.php | 42 +- .../day1/blog/protected/layouts/MainLayout.php | 12 +- .../samples/day1/blog/protected/pages/Contact.php | 58 +- demos/blog-tutorial/samples/day2/blog/index.php | 42 +- .../day2/blog/protected/database/PostRecord.php | 54 +- .../day2/blog/protected/database/UserRecord.php | 54 +- .../day2/blog/protected/layouts/MainLayout.php | 12 +- .../samples/day2/blog/protected/pages/Contact.php | 58 +- demos/blog-tutorial/samples/day3/blog/index.php | 42 +- .../samples/day3/blog/protected/BlogUser.php | 116 +- .../day3/blog/protected/database/PostRecord.php | 54 +- .../day3/blog/protected/database/UserRecord.php | 54 +- .../day3/blog/protected/layouts/MainLayout.php | 36 +- .../samples/day3/blog/protected/pages/Contact.php | 58 +- .../day3/blog/protected/pages/users/AdminUser.php | 70 +- .../day3/blog/protected/pages/users/EditUser.php | 164 +-- .../day3/blog/protected/pages/users/LoginUser.php | 72 +- .../day3/blog/protected/pages/users/NewUser.php | 88 +- demos/blog-tutorial/samples/day4/blog/index.php | 42 +- .../samples/day4/blog/protected/BlogUser.php | 116 +- .../day4/blog/protected/database/PostRecord.php | 54 +- .../day4/blog/protected/database/UserRecord.php | 54 +- .../day4/blog/protected/layouts/MainLayout.php | 36 +- .../samples/day4/blog/protected/pages/Contact.php | 58 +- .../day4/blog/protected/pages/posts/EditPost.php | 142 +- .../day4/blog/protected/pages/posts/ListPost.php | 126 +- .../day4/blog/protected/pages/posts/NewPost.php | 66 +- .../blog/protected/pages/posts/PostRenderer.php | 12 +- .../day4/blog/protected/pages/posts/ReadPost.php | 112 +- .../day4/blog/protected/pages/users/AdminUser.php | 70 +- .../day4/blog/protected/pages/users/EditUser.php | 164 +-- .../day4/blog/protected/pages/users/LoginUser.php | 72 +- .../day4/blog/protected/pages/users/NewUser.php | 88 +- demos/blog-tutorial/samples/day5/blog/index.php | 42 +- .../day5/blog/protected/BlogErrorHandler.php | 78 +- .../samples/day5/blog/protected/BlogException.php | 12 +- .../samples/day5/blog/protected/BlogUser.php | 116 +- .../day5/blog/protected/database/PostRecord.php | 54 +- .../day5/blog/protected/database/UserRecord.php | 54 +- .../day5/blog/protected/layouts/MainLayout.php | 36 +- .../samples/day5/blog/protected/pages/Contact.php | 58 +- .../day5/blog/protected/pages/posts/EditPost.php | 142 +- .../day5/blog/protected/pages/posts/ListPost.php | 126 +- .../day5/blog/protected/pages/posts/NewPost.php | 66 +- .../blog/protected/pages/posts/PostRenderer.php | 12 +- .../day5/blog/protected/pages/posts/ReadPost.php | 116 +- .../day5/blog/protected/pages/users/AdminUser.php | 70 +- .../day5/blog/protected/pages/users/EditUser.php | 164 +-- .../day5/blog/protected/pages/users/LoginUser.php | 72 +- .../day5/blog/protected/pages/users/NewUser.php | 88 +- demos/blog/index.php | 40 +- demos/blog/protected/Common/BlogDataModule.php | 1414 ++++++++++---------- demos/blog/protected/Common/BlogErrorHandler.php | 90 +- demos/blog/protected/Common/BlogException.php | 60 +- demos/blog/protected/Common/BlogPage.php | 96 +- demos/blog/protected/Common/BlogUser.php | 118 +- demos/blog/protected/Common/BlogUserManager.php | 188 +-- demos/blog/protected/Common/XListMenu.php | 252 ++-- demos/blog/protected/Layouts/MainLayout.php | 46 +- demos/blog/protected/Pages/Admin/AdminMenu.php | 46 +- demos/blog/protected/Pages/Admin/ConfigMan.php | 152 +-- demos/blog/protected/Pages/Admin/PostMan.php | 144 +- demos/blog/protected/Pages/Admin/UserMan.php | 148 +- demos/blog/protected/Pages/ErrorReport.php | 56 +- demos/blog/protected/Pages/Posts/EditCategory.php | 120 +- demos/blog/protected/Pages/Posts/EditPost.php | 154 +-- demos/blog/protected/Pages/Posts/ListPost.php | 282 ++-- demos/blog/protected/Pages/Posts/MyPost.php | 100 +- demos/blog/protected/Pages/Posts/NewCategory.php | 80 +- demos/blog/protected/Pages/Posts/NewPost.php | 112 +- demos/blog/protected/Pages/Posts/ViewPost.php | 178 +-- demos/blog/protected/Pages/SearchPost.php | 134 +- demos/blog/protected/Pages/Users/EditUser.php | 136 +- demos/blog/protected/Pages/Users/NewUser.php | 114 +- demos/blog/protected/Pages/Users/ViewUser.php | 82 +- demos/blog/protected/Portlets/AccountPortlet.php | 60 +- demos/blog/protected/Portlets/ArchivePortlet.php | 122 +- demos/blog/protected/Portlets/CategoryPortlet.php | 74 +- demos/blog/protected/Portlets/CommentPortlet.php | 78 +- demos/blog/protected/Portlets/LoginPortlet.php | 76 +- demos/blog/protected/Portlets/Portlet.php | 46 +- demos/blog/protected/Portlets/SearchPortlet.php | 76 +- demos/chat/index.php | 56 +- demos/chat/protected/App_Code/ChatBufferRecord.php | 126 +- demos/chat/protected/App_Code/ChatUserManager.php | 168 +-- demos/chat/protected/App_Code/ChatUserRecord.php | 80 +- demos/chat/protected/pages/Home.php | 110 +- demos/chat/protected/pages/Login.php | 78 +- demos/composer/index.php | 34 +- demos/composer/index2.php | 34 +- demos/composer/protected/pages/ClassDefinition.php | 740 +++++----- demos/composer/protected/pages/Home.php | 234 ++-- demos/composer/protected/pages/Layout.php | 28 +- demos/helloworld/index.php | 34 +- demos/helloworld/protected/pages/Home.php | 20 +- demos/northwind-db/index.php | 54 +- demos/northwind-db/protected/database/Category.php | 50 +- demos/northwind-db/protected/database/Customer.php | 64 +- demos/northwind-db/protected/database/Employee.php | 94 +- demos/northwind-db/protected/database/Order.php | 82 +- .../protected/database/OrderDetail.php | 52 +- demos/northwind-db/protected/database/Product.php | 70 +- demos/northwind-db/protected/database/Region.php | 48 +- demos/northwind-db/protected/database/Shipper.php | 48 +- demos/northwind-db/protected/database/Supplier.php | 66 +- .../northwind-db/protected/database/Territory.php | 118 +- .../northwind-db/protected/pages/NorthwindCrud.php | 54 +- demos/personal/index.php | 28 +- demos/personal/protected/Common/LoginPortlet.php | 36 +- demos/personal/protected/Common/MainMenu.php | 22 +- demos/personal/protected/Pages/Layout.php | 12 +- demos/personal/protected/Pages/Register.php | 36 +- demos/quickstart/index.php | 34 +- demos/quickstart/index2.php | 34 +- .../protected/QuickStartGlobalization.php | 60 +- .../protected/controls/Comments/CommentBlock.php | 212 +-- .../protected/controls/Comments/comments.js | 412 +++--- demos/quickstart/protected/controls/DocLink.php | 60 +- demos/quickstart/protected/controls/Layout.php | 94 +- .../protected/controls/RequiresVersion.php | 30 +- demos/quickstart/protected/controls/RunBar.php | 44 +- .../quickstart/protected/controls/SampleLayout.php | 24 +- demos/quickstart/protected/controls/SearchBox.php | 80 +- .../quickstart/protected/controls/SinceVersion.php | 30 +- demos/quickstart/protected/controls/TopicList.php | 14 +- demos/quickstart/protected/index/ZendSearch.php | 108 +- .../ActiveControls/Samples/TActiveButton/Home.php | 38 +- .../Samples/TActiveCheckBox/Home.php | 30 +- .../Samples/TActiveCheckBoxList/Home.php | 50 +- .../Samples/TActiveCustomValidator/Home.php | 20 +- .../Samples/TActiveDataGrid/Sample1.php | 72 +- .../Samples/TActiveDataGrid/Sample2.php | 170 +-- .../Samples/TActiveDataGrid/Sample3.php | 378 +++--- .../Samples/TActiveDataGrid/Sample4.php | 40 +- .../Samples/TActiveDataGrid/Sample5.php | 156 +-- .../Samples/TActiveDataList/Home.php | 262 ++-- .../Samples/TActiveDropDownList/Home.php | 118 +- .../Samples/TActiveFileUpload/Home.php | 40 +- .../Samples/TActiveHyperLink/Home.php | 50 +- .../ActiveControls/Samples/TActiveImage/Home.php | 32 +- .../Samples/TActiveImageButton/Home.php | 34 +- .../Samples/TActiveLinkButton/Home.php | 26 +- .../ActiveControls/Samples/TActiveListBox/Home.php | 128 +- .../Samples/TActiveMultiView/Home.php | 28 +- .../ActiveControls/Samples/TActivePanel/Home.php | 40 +- .../Samples/TActiveRadioButton/Home.php | 52 +- .../Samples/TActiveRadioButtonList/Home.php | 50 +- .../Samples/TActiveRepeater/Home.php | 156 +-- .../Samples/TActiveTableRow/Home.php | 42 +- .../ActiveControls/Samples/TAutoComplete/Home.php | 68 +- .../Samples/TCallbackClientScript/Home.php | 56 +- .../Samples/TCallbackClientSide/Home.php | 22 +- .../Samples/TCallbackOptions/Home.php | 22 +- .../protected/pages/Advanced/Samples/I18N/Home.php | 88 +- .../pages/Advanced/Samples/I18N/LanguageList.php | 36 +- .../Controls/Samples/LabeledTextBox1/Home.php | 24 +- .../Samples/LabeledTextBox1/LabeledTextBox.php | 34 +- .../Controls/Samples/LabeledTextBox2/Home.php | 24 +- .../Samples/LabeledTextBox2/LabeledTextBox.php | 64 +- .../Controls/Samples/ResetValidation/Home.php | 14 +- .../pages/Controls/Samples/TAccordion/Home.php | 32 +- .../pages/Controls/Samples/TBulletedList/Home.php | 22 +- .../pages/Controls/Samples/TButton/Home.php | 26 +- .../pages/Controls/Samples/TCaptcha/Home.php | 52 +- .../pages/Controls/Samples/TCheckBox/Home.php | 20 +- .../pages/Controls/Samples/TCheckBoxList/Home.php | 138 +- .../Controls/Samples/TClientSideValidator/Home.php | 32 +- .../Controls/Samples/TCompareValidator/Home.php | 14 +- .../pages/Controls/Samples/TConditional/Home.php | 12 +- .../Controls/Samples/TCustomValidator/Home.php | 34 +- .../pages/Controls/Samples/TDataGrid/Sample1.php | 80 +- .../pages/Controls/Samples/TDataGrid/Sample2.php | 170 +-- .../pages/Controls/Samples/TDataGrid/Sample3.php | 378 +++--- .../pages/Controls/Samples/TDataGrid/Sample4.php | 40 +- .../pages/Controls/Samples/TDataGrid/Sample5.php | 134 +- .../pages/Controls/Samples/TDataGrid/Sample6.php | 110 +- .../pages/Controls/Samples/TDataList/Sample1.php | 80 +- .../pages/Controls/Samples/TDataList/Sample2.php | 262 ++-- .../Controls/Samples/TDataTypeValidator/Home.php | 14 +- .../pages/Controls/Samples/TDropDownList/Home.php | 136 +- .../Samples/TEmailAddressValidator/Home.php | 14 +- .../pages/Controls/Samples/TFileUpload/Home.php | 40 +- .../pages/Controls/Samples/THtmlArea/Home.php | 40 +- .../pages/Controls/Samples/TImageButton/Home.php | 34 +- .../pages/Controls/Samples/TImageMap/Home.php | 20 +- .../pages/Controls/Samples/TKeyboard/Home.php | 20 +- .../pages/Controls/Samples/TLinkButton/Home.php | 26 +- .../pages/Controls/Samples/TListBox/Home.php | 156 +-- .../pages/Controls/Samples/TMultiView/Home.php | 28 +- .../pages/Controls/Samples/TPager/Sample1.php | 162 +-- .../pages/Controls/Samples/TPanel/Home.php | 20 +- .../pages/Controls/Samples/TPlaceHolder/Home.php | 30 +- .../pages/Controls/Samples/TRadioButton/Home.php | 52 +- .../Controls/Samples/TRadioButtonList/Home.php | 136 +- .../Controls/Samples/TRangeValidator/Home.php | 14 +- .../Samples/TRegularExpressionValidator/Home.php | 14 +- .../Controls/Samples/TRepeater/RegionDisplay.php | 54 +- .../pages/Controls/Samples/TRepeater/Sample1.php | 80 +- .../pages/Controls/Samples/TRepeater/Sample2.php | 156 +-- .../pages/Controls/Samples/TRepeater/Sample3.php | 156 +-- .../pages/Controls/Samples/TRepeater/Sample4.php | 72 +- .../pages/Controls/Samples/TRepeater/Sample5.php | 102 +- .../Samples/TRequiredFieldValidator/Home.php | 14 +- .../pages/Controls/Samples/TSlider/Home.php | 8 +- .../pages/Controls/Samples/TTabPanel/Home.php | 12 +- .../pages/Controls/Samples/TTable/Home.php | 64 +- .../pages/Controls/Samples/TTextBox/Home.php | 42 +- .../Controls/Samples/TValidationSummary/Home.php | 14 +- .../pages/Controls/Samples/TWizard/Sample1.php | 20 +- .../pages/Controls/Samples/TWizard/Sample2.php | 20 +- .../pages/Controls/Samples/TWizard/Sample3.php | 48 +- .../pages/Controls/Samples/TWizard/Sample4.php | 20 +- .../pages/Controls/Samples/TWizard/Sample5.php | 22 +- .../pages/Database/Samples/Scaffold/Home.php | 64 +- .../pages/Fundamentals/Samples/Hangman/Home.php | 240 ++-- demos/quickstart/protected/pages/Search.php | 110 +- demos/quickstart/protected/pages/ViewSource.php | 222 +-- demos/sqlmap/index.php | 38 +- demos/sqlmap/protected/APP_CODE/Person.php | 50 +- demos/sqlmap/protected/pages/Manual/Layout.php | 12 +- demos/sqlmap/protected/pages/Manual/TopicList.php | 14 +- demos/sqlmap/protected/pages/Sample/crud1.php | 40 +- demos/sqlmap/protected/pages/Sample/crud2.php | 154 +-- demos/time-tracker/index.php | 68 +- .../protected/App_Code/Dao/BaseDao.php | 88 +- .../protected/App_Code/Dao/CategoryDao.php | 104 +- .../protected/App_Code/Dao/CategoryRecord.php | 24 +- .../protected/App_Code/Dao/ProjectDao.php | 208 +-- .../protected/App_Code/Dao/ProjectRecord.php | 68 +- .../protected/App_Code/Dao/ReportsDao.php | 172 +-- .../protected/App_Code/Dao/TimeEntryDao.php | 74 +- .../protected/App_Code/Dao/TimeEntryRecord.php | 30 +- .../protected/App_Code/Dao/UserDao.php | 328 ++--- .../time-tracker/protected/App_Code/DaoManager.php | 156 +-- .../protected/App_Code/TimeTrackerException.php | 64 +- .../protected/App_Code/TimeTrackerUser.php | 94 +- .../protected/App_Code/TrackerAuthManager.php | 168 +-- .../protected/App_Code/UserManager.php | 178 +-- .../protected/App_Data/DateTimeTypeHandler.php | 68 +- .../App_Data/TimeTrackerUserTypeHandler.php | 106 +- .../pages/TimeTracker/CategoryDataList.php | 186 +-- .../protected/pages/TimeTracker/LogTimeEntry.php | 222 +-- .../protected/pages/TimeTracker/Login.php | 108 +- .../protected/pages/TimeTracker/Logout.php | 66 +- .../protected/pages/TimeTracker/MainLayout.php | 12 +- .../protected/pages/TimeTracker/ProjectDetails.php | 380 +++--- .../protected/pages/TimeTracker/ProjectList.php | 66 +- .../protected/pages/TimeTracker/ReportProject.php | 104 +- .../protected/pages/TimeTracker/ReportResource.php | 140 +- .../protected/pages/TimeTracker/SiteMap.php | 112 +- .../protected/pages/TimeTracker/TimeEntryList.php | 176 +-- .../protected/pages/TimeTracker/UserCreate.php | 222 +-- .../protected/pages/TimeTracker/UserList.php | 66 +- demos/time-tracker/tests/functional.php | 18 +- .../tests/functional/HelloPradoTestCase.php | 26 +- demos/time-tracker/tests/unit.php | 20 +- demos/time-tracker/tests/unit/BaseTestCase.php | 126 +- .../tests/unit/CategoryDaoTestCase.php | 400 +++--- .../time-tracker/tests/unit/ProjectDaoTestCase.php | 398 +++--- .../tests/unit/TimeEntryDaoTestCase.php | 426 +++--- demos/time-tracker/tests/unit/UserDaoTestCase.php | 540 ++++---- 275 files changed, 13474 insertions(+), 13474 deletions(-) (limited to 'demos') diff --git a/demos/address-book/index.php b/demos/address-book/index.php index 90149c02..65ace715 100644 --- a/demos/address-book/index.php +++ b/demos/address-book/index.php @@ -1,27 +1,27 @@ -run(); - +run(); + ?> \ No newline at end of file diff --git a/demos/address-book/protected/pages/AddressProvider.php b/demos/address-book/protected/pages/AddressProvider.php index 94b71e11..e903f540 100644 --- a/demos/address-book/protected/pages/AddressProvider.php +++ b/demos/address-book/protected/pages/AddressProvider.php @@ -1,50 +1,50 @@ - - * @version $Id$ - * @since 3.1 - */ -class AddressProvider -{ - /** - * @return AddressRecord[] - * @soapmethod - */ - public function getAllAddress() - { - return AddressRecord::finder()->findAll(); - } - - /** - * Update address if $data->id > 0, otherwise add new address. - * @param AddressRecord $data - * @return boolean - * @soapmethod - */ - public function saveAddress($data) - { - $finder = AddressRecord::finder(); - if($data->id > 0 && $address=$finder->findByPk($data->id)) - { - return $address->copyFrom($data)->save(); - } - else - { - $data->id = null; //nullify the id - return $data->save(); - } - } - - /** - * @param integer $id - * @return integer number of records deleted - * @soapmethod - */ - public function deleteAddress($id) - { - return AddressRecord::finder()->deleteByPk($id); - } -} + + * @version $Id$ + * @since 3.1 + */ +class AddressProvider +{ + /** + * @return AddressRecord[] + * @soapmethod + */ + public function getAllAddress() + { + return AddressRecord::finder()->findAll(); + } + + /** + * Update address if $data->id > 0, otherwise add new address. + * @param AddressRecord $data + * @return boolean + * @soapmethod + */ + public function saveAddress($data) + { + $finder = AddressRecord::finder(); + if($data->id > 0 && $address=$finder->findByPk($data->id)) + { + return $address->copyFrom($data)->save(); + } + else + { + $data->id = null; //nullify the id + return $data->save(); + } + } + + /** + * @param integer $id + * @return integer number of records deleted + * @soapmethod + */ + public function deleteAddress($id) + { + return AddressRecord::finder()->deleteByPk($id); + } +} ?> \ No newline at end of file diff --git a/demos/address-book/protected/pages/AddressRecord.php b/demos/address-book/protected/pages/AddressRecord.php index aaf8db7c..58bb53e6 100644 --- a/demos/address-book/protected/pages/AddressRecord.php +++ b/demos/address-book/protected/pages/AddressRecord.php @@ -1,35 +1,35 @@ - \ No newline at end of file diff --git a/demos/address-book/protected/pages/FlexApp.php b/demos/address-book/protected/pages/FlexApp.php index e7a5bf2a..d9b20ab7 100644 --- a/demos/address-book/protected/pages/FlexApp.php +++ b/demos/address-book/protected/pages/FlexApp.php @@ -1,114 +1,114 @@ - - * @version $Id$ - * @since 3.1 - */ -class FlexApp extends TTemplateControl -{ - private $_parameters; - - /** - * FlashVar parameter name value pairs. - * - * NOTE: parameter names must be accessed in lowercase in Flex Applications! - * - * @return TAttributeCollection - */ - public function getParameters() - { - if($this->_parameters===null) - $this->_parameters = new TAttributeCollection(); - return $this->_parameters; - } - - public function getFlashVars() - { - $params = array(); - foreach($this->getParameters() as $name=>$value) - $params[] = $name.'='.$value; - return implode('&', $params); - } - - public function getWidth() - { - return $this->getViewState('Width', '450'); - } - - public function setWidth($value) - { - $this->setViewState('Width', $value, '450'); - } - - public function getHeight() - { - return $this->getViewState('Height', '300'); - } - - public function setHeight($value) - { - $this->setViewState('Height', $value, '300'); - } - - public function getBinDirectory() - { - return $this->getViewState('Bin'); - } - - public function setBinDirectory($value) - { - $this->setViewState('Bin', $value); - } - - public function getAppName() - { - return $this->getViewState('AppName'); - } - - public function setAppName($value) - { - $this->setViewState('AppName', $value); - } - - public function getQuality() - { - return $this->getViewState('Quality', 'high'); - } - - public function setQuality($value) - { - $this->setViewState('Quality', $value, 'high'); - } - - public function getBgcolor() - { - return $this->getViewState('bgcolor', '#ffffff'); - } - - public function setBgColor($value) - { - $this->setViewState('bgcolor', $value, '#ffffff'); - } - - public function getAlign() - { - return $this->getViewState('align', 'middle'); - } - - public function setAlign($value) - { - $this->setViewState('align', $value, 'middle'); - } - - public function getAllowScriptAccess() - { - return $this->getViewState('allowScriptAccess', 'sameDomain'); - } - - public function setAllowScriptAccess($value) - { - $this->setViewState('allowScriptAccess', $value, 'sameDomain'); - } -} - + + * @version $Id$ + * @since 3.1 + */ +class FlexApp extends TTemplateControl +{ + private $_parameters; + + /** + * FlashVar parameter name value pairs. + * + * NOTE: parameter names must be accessed in lowercase in Flex Applications! + * + * @return TAttributeCollection + */ + public function getParameters() + { + if($this->_parameters===null) + $this->_parameters = new TAttributeCollection(); + return $this->_parameters; + } + + public function getFlashVars() + { + $params = array(); + foreach($this->getParameters() as $name=>$value) + $params[] = $name.'='.$value; + return implode('&', $params); + } + + public function getWidth() + { + return $this->getViewState('Width', '450'); + } + + public function setWidth($value) + { + $this->setViewState('Width', $value, '450'); + } + + public function getHeight() + { + return $this->getViewState('Height', '300'); + } + + public function setHeight($value) + { + $this->setViewState('Height', $value, '300'); + } + + public function getBinDirectory() + { + return $this->getViewState('Bin'); + } + + public function setBinDirectory($value) + { + $this->setViewState('Bin', $value); + } + + public function getAppName() + { + return $this->getViewState('AppName'); + } + + public function setAppName($value) + { + $this->setViewState('AppName', $value); + } + + public function getQuality() + { + return $this->getViewState('Quality', 'high'); + } + + public function setQuality($value) + { + $this->setViewState('Quality', $value, 'high'); + } + + public function getBgcolor() + { + return $this->getViewState('bgcolor', '#ffffff'); + } + + public function setBgColor($value) + { + $this->setViewState('bgcolor', $value, '#ffffff'); + } + + public function getAlign() + { + return $this->getViewState('align', 'middle'); + } + + public function setAlign($value) + { + $this->setViewState('align', $value, 'middle'); + } + + public function getAllowScriptAccess() + { + return $this->getViewState('allowScriptAccess', 'sameDomain'); + } + + public function setAllowScriptAccess($value) + { + $this->setViewState('allowScriptAccess', $value, 'sameDomain'); + } +} + ?> \ No newline at end of file diff --git a/demos/address-book/protected/pages/flex/bin/AC_OETags.js b/demos/address-book/protected/pages/flex/bin/AC_OETags.js index 157eb218..f72d7e29 100644 --- a/demos/address-book/protected/pages/flex/bin/AC_OETags.js +++ b/demos/address-book/protected/pages/flex/bin/AC_OETags.js @@ -1,269 +1,269 @@ -// Flash Player Version Detection - Rev 1.5 -// Detect Client Browser type -// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved. -var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false; -var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false; -var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false; - -function ControlVersion() -{ - var version; - var axo; - var e; - - // NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry - - try { - // version will be set for 7.X or greater players - axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7"); - version = axo.GetVariable("$version"); - } catch (e) { - } - - if (!version) - { - try { - // version will be set for 6.X players only - axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"); - - // installed player is some revision of 6.0 - // GetVariable("$version") crashes for versions 6.0.22 through 6.0.29, - // so we have to be careful. - - // default to the first public version - version = "WIN 6,0,21,0"; - - // throws if AllowScripAccess does not exist (introduced in 6.0r47) - axo.AllowScriptAccess = "always"; - - // safe to call for 6.0r47 or greater - version = axo.GetVariable("$version"); - - } catch (e) { - } - } - - if (!version) - { - try { - // version will be set for 4.X or 5.X player - axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3"); - version = axo.GetVariable("$version"); - } catch (e) { - } - } - - if (!version) - { - try { - // version will be set for 3.X player - axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3"); - version = "WIN 3,0,18,0"; - } catch (e) { - } - } - - if (!version) - { - try { - // version will be set for 2.X player - axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); - version = "WIN 2,0,0,11"; - } catch (e) { - version = -1; - } - } - - return version; -} - -// JavaScript helper required to detect Flash Player PlugIn version information -function GetSwfVer(){ - // NS/Opera version >= 3 check for Flash plugin in plugin array - var flashVer = -1; - - if (navigator.plugins != null && navigator.plugins.length > 0) { - if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) { - var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : ""; - var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description; - var descArray = flashDescription.split(" "); - var tempArrayMajor = descArray[2].split("."); - var versionMajor = tempArrayMajor[0]; - var versionMinor = tempArrayMajor[1]; - if ( descArray[3] != "" ) { - tempArrayMinor = descArray[3].split("r"); - } else { - tempArrayMinor = descArray[4].split("r"); - } - var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0; - var flashVer = versionMajor + "." + versionMinor + "." + versionRevision; - } - } - // MSN/WebTV 2.6 supports Flash 4 - else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4; - // WebTV 2.5 supports Flash 3 - else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3; - // older WebTV supports Flash 2 - else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2; - else if ( isIE && isWin && !isOpera ) { - flashVer = ControlVersion(); - } - return flashVer; -} - -// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available -function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) -{ - versionStr = GetSwfVer(); - if (versionStr == -1 ) { - return false; - } else if (versionStr != 0) { - if(isIE && isWin && !isOpera) { - // Given "WIN 2,0,0,11" - tempArray = versionStr.split(" "); // ["WIN", "2,0,0,11"] - tempString = tempArray[1]; // "2,0,0,11" - versionArray = tempString.split(","); // ['2', '0', '0', '11'] - } else { - versionArray = versionStr.split("."); - } - var versionMajor = versionArray[0]; - var versionMinor = versionArray[1]; - var versionRevision = versionArray[2]; - - // is the major.revision >= requested major.revision AND the minor version >= requested minor - if (versionMajor > parseFloat(reqMajorVer)) { - return true; - } else if (versionMajor == parseFloat(reqMajorVer)) { - if (versionMinor > parseFloat(reqMinorVer)) - return true; - else if (versionMinor == parseFloat(reqMinorVer)) { - if (versionRevision >= parseFloat(reqRevision)) - return true; - } - } - return false; - } -} - -function AC_AddExtension(src, ext) -{ - if (src.indexOf('?') != -1) - return src.replace(/\?/, ext+'?'); - else - return src + ext; -} - -function AC_Generateobj(objAttrs, params, embedAttrs) -{ - var str = ''; - if (isIE && isWin && !isOpera) - { - str += ' '; - str += '>'; - } else { - str += '= 3 check for Flash plugin in plugin array + var flashVer = -1; + + if (navigator.plugins != null && navigator.plugins.length > 0) { + if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) { + var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : ""; + var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description; + var descArray = flashDescription.split(" "); + var tempArrayMajor = descArray[2].split("."); + var versionMajor = tempArrayMajor[0]; + var versionMinor = tempArrayMajor[1]; + if ( descArray[3] != "" ) { + tempArrayMinor = descArray[3].split("r"); + } else { + tempArrayMinor = descArray[4].split("r"); + } + var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0; + var flashVer = versionMajor + "." + versionMinor + "." + versionRevision; + } + } + // MSN/WebTV 2.6 supports Flash 4 + else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4; + // WebTV 2.5 supports Flash 3 + else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3; + // older WebTV supports Flash 2 + else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2; + else if ( isIE && isWin && !isOpera ) { + flashVer = ControlVersion(); + } + return flashVer; +} + +// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available +function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) +{ + versionStr = GetSwfVer(); + if (versionStr == -1 ) { + return false; + } else if (versionStr != 0) { + if(isIE && isWin && !isOpera) { + // Given "WIN 2,0,0,11" + tempArray = versionStr.split(" "); // ["WIN", "2,0,0,11"] + tempString = tempArray[1]; // "2,0,0,11" + versionArray = tempString.split(","); // ['2', '0', '0', '11'] + } else { + versionArray = versionStr.split("."); + } + var versionMajor = versionArray[0]; + var versionMinor = versionArray[1]; + var versionRevision = versionArray[2]; + + // is the major.revision >= requested major.revision AND the minor version >= requested minor + if (versionMajor > parseFloat(reqMajorVer)) { + return true; + } else if (versionMajor == parseFloat(reqMajorVer)) { + if (versionMinor > parseFloat(reqMinorVer)) + return true; + else if (versionMinor == parseFloat(reqMinorVer)) { + if (versionRevision >= parseFloat(reqRevision)) + return true; + } + } + return false; + } +} + +function AC_AddExtension(src, ext) +{ + if (src.indexOf('?') != -1) + return src.replace(/\?/, ext+'?'); + else + return src + ext; +} + +function AC_Generateobj(objAttrs, params, embedAttrs) +{ + var str = ''; + if (isIE && isWin && !isOpera) + { + str += ' '; + str += '>'; + } else { + str += ' 0 && value.length > 0) { - this[name] = value; - this.numVars++; - } - } - } - } -} -Vars.prototype.toString = function(pre) { - var result = ''; - if(pre == null) { pre = ''; } - for(var i in this) { - if(this[i] != null && typeof(this[i]) != 'object' && typeof(this[i]) != 'function' && i != 'numVars') { - result += pre + i + '=' + this[i] + '&'; - } - } - if(result.length > 0) result = result.substr(0, result.length-1); - return result; -} -function getSearch(wRef) { - var searchStr = ''; - if(wRef.location.search.length > 1) { - searchStr = new String(wRef.location.search); - searchStr = searchStr.substring(1, searchStr.length); - } - return searchStr; -} -var lc_id = Math.floor(Math.random() * 100000).toString(16); -if (this != top) -{ - top.Vars = Vars; - top.getSearch = getSearch; - top.lc_id = lc_id; -} +// $Revision: 1.49 $ +// Vars +Vars = function(qStr) { + this.numVars = 0; + if(qStr != null) { + var nameValue, name; + var pairs = qStr.split('&'); + var pairLen = pairs.length; + for(var i = 0; i < pairLen; i++) { + var pair = pairs[i]; + if( (pair.indexOf('=')!= -1) && (pair.length > 3) ) { + var nameValue = pair.split('='); + var name = nameValue[0]; + var value = nameValue[1]; + if(this[name] == null && name.length > 0 && value.length > 0) { + this[name] = value; + this.numVars++; + } + } + } + } +} +Vars.prototype.toString = function(pre) { + var result = ''; + if(pre == null) { pre = ''; } + for(var i in this) { + if(this[i] != null && typeof(this[i]) != 'object' && typeof(this[i]) != 'function' && i != 'numVars') { + result += pre + i + '=' + this[i] + '&'; + } + } + if(result.length > 0) result = result.substr(0, result.length-1); + return result; +} +function getSearch(wRef) { + var searchStr = ''; + if(wRef.location.search.length > 1) { + searchStr = new String(wRef.location.search); + searchStr = searchStr.substring(1, searchStr.length); + } + return searchStr; +} +var lc_id = Math.floor(Math.random() * 100000).toString(16); +if (this != top) +{ + top.Vars = Vars; + top.getSearch = getSearch; + top.lc_id = lc_id; +} diff --git a/demos/address-book/protected/pages/flex/html-template/AC_OETags.js b/demos/address-book/protected/pages/flex/html-template/AC_OETags.js index 157eb218..f72d7e29 100644 --- a/demos/address-book/protected/pages/flex/html-template/AC_OETags.js +++ b/demos/address-book/protected/pages/flex/html-template/AC_OETags.js @@ -1,269 +1,269 @@ -// Flash Player Version Detection - Rev 1.5 -// Detect Client Browser type -// Copyright(c) 2005-2006 Adobe Macromedia Software, LLC. All rights reserved. -var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false; -var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false; -var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false; - -function ControlVersion() -{ - var version; - var axo; - var e; - - // NOTE : new ActiveXObject(strFoo) throws an exception if strFoo isn't in the registry - - try { - // version will be set for 7.X or greater players - axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7"); - version = axo.GetVariable("$version"); - } catch (e) { - } - - if (!version) - { - try { - // version will be set for 6.X players only - axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6"); - - // installed player is some revision of 6.0 - // GetVariable("$version") crashes for versions 6.0.22 through 6.0.29, - // so we have to be careful. - - // default to the first public version - version = "WIN 6,0,21,0"; - - // throws if AllowScripAccess does not exist (introduced in 6.0r47) - axo.AllowScriptAccess = "always"; - - // safe to call for 6.0r47 or greater - version = axo.GetVariable("$version"); - - } catch (e) { - } - } - - if (!version) - { - try { - // version will be set for 4.X or 5.X player - axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3"); - version = axo.GetVariable("$version"); - } catch (e) { - } - } - - if (!version) - { - try { - // version will be set for 3.X player - axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3"); - version = "WIN 3,0,18,0"; - } catch (e) { - } - } - - if (!version) - { - try { - // version will be set for 2.X player - axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); - version = "WIN 2,0,0,11"; - } catch (e) { - version = -1; - } - } - - return version; -} - -// JavaScript helper required to detect Flash Player PlugIn version information -function GetSwfVer(){ - // NS/Opera version >= 3 check for Flash plugin in plugin array - var flashVer = -1; - - if (navigator.plugins != null && navigator.plugins.length > 0) { - if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) { - var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : ""; - var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description; - var descArray = flashDescription.split(" "); - var tempArrayMajor = descArray[2].split("."); - var versionMajor = tempArrayMajor[0]; - var versionMinor = tempArrayMajor[1]; - if ( descArray[3] != "" ) { - tempArrayMinor = descArray[3].split("r"); - } else { - tempArrayMinor = descArray[4].split("r"); - } - var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0; - var flashVer = versionMajor + "." + versionMinor + "." + versionRevision; - } - } - // MSN/WebTV 2.6 supports Flash 4 - else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4; - // WebTV 2.5 supports Flash 3 - else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3; - // older WebTV supports Flash 2 - else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2; - else if ( isIE && isWin && !isOpera ) { - flashVer = ControlVersion(); - } - return flashVer; -} - -// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available -function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) -{ - versionStr = GetSwfVer(); - if (versionStr == -1 ) { - return false; - } else if (versionStr != 0) { - if(isIE && isWin && !isOpera) { - // Given "WIN 2,0,0,11" - tempArray = versionStr.split(" "); // ["WIN", "2,0,0,11"] - tempString = tempArray[1]; // "2,0,0,11" - versionArray = tempString.split(","); // ['2', '0', '0', '11'] - } else { - versionArray = versionStr.split("."); - } - var versionMajor = versionArray[0]; - var versionMinor = versionArray[1]; - var versionRevision = versionArray[2]; - - // is the major.revision >= requested major.revision AND the minor version >= requested minor - if (versionMajor > parseFloat(reqMajorVer)) { - return true; - } else if (versionMajor == parseFloat(reqMajorVer)) { - if (versionMinor > parseFloat(reqMinorVer)) - return true; - else if (versionMinor == parseFloat(reqMinorVer)) { - if (versionRevision >= parseFloat(reqRevision)) - return true; - } - } - return false; - } -} - -function AC_AddExtension(src, ext) -{ - if (src.indexOf('?') != -1) - return src.replace(/\?/, ext+'?'); - else - return src + ext; -} - -function AC_Generateobj(objAttrs, params, embedAttrs) -{ - var str = ''; - if (isIE && isWin && !isOpera) - { - str += ' '; - str += '>'; - } else { - str += '= 3 check for Flash plugin in plugin array + var flashVer = -1; + + if (navigator.plugins != null && navigator.plugins.length > 0) { + if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) { + var swVer2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : ""; + var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description; + var descArray = flashDescription.split(" "); + var tempArrayMajor = descArray[2].split("."); + var versionMajor = tempArrayMajor[0]; + var versionMinor = tempArrayMajor[1]; + if ( descArray[3] != "" ) { + tempArrayMinor = descArray[3].split("r"); + } else { + tempArrayMinor = descArray[4].split("r"); + } + var versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0; + var flashVer = versionMajor + "." + versionMinor + "." + versionRevision; + } + } + // MSN/WebTV 2.6 supports Flash 4 + else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1) flashVer = 4; + // WebTV 2.5 supports Flash 3 + else if (navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1) flashVer = 3; + // older WebTV supports Flash 2 + else if (navigator.userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 2; + else if ( isIE && isWin && !isOpera ) { + flashVer = ControlVersion(); + } + return flashVer; +} + +// When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available +function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision) +{ + versionStr = GetSwfVer(); + if (versionStr == -1 ) { + return false; + } else if (versionStr != 0) { + if(isIE && isWin && !isOpera) { + // Given "WIN 2,0,0,11" + tempArray = versionStr.split(" "); // ["WIN", "2,0,0,11"] + tempString = tempArray[1]; // "2,0,0,11" + versionArray = tempString.split(","); // ['2', '0', '0', '11'] + } else { + versionArray = versionStr.split("."); + } + var versionMajor = versionArray[0]; + var versionMinor = versionArray[1]; + var versionRevision = versionArray[2]; + + // is the major.revision >= requested major.revision AND the minor version >= requested minor + if (versionMajor > parseFloat(reqMajorVer)) { + return true; + } else if (versionMajor == parseFloat(reqMajorVer)) { + if (versionMinor > parseFloat(reqMinorVer)) + return true; + else if (versionMinor == parseFloat(reqMinorVer)) { + if (versionRevision >= parseFloat(reqRevision)) + return true; + } + } + return false; + } +} + +function AC_AddExtension(src, ext) +{ + if (src.indexOf('?') != -1) + return src.replace(/\?/, ext+'?'); + else + return src + ext; +} + +function AC_Generateobj(objAttrs, params, embedAttrs) +{ + var str = ''; + if (isIE && isWin && !isOpera) + { + str += ' '; + str += '>'; + } else { + str += ' 0 && value.length > 0) { - this[name] = value; - this.numVars++; - } - } - } - } -} -Vars.prototype.toString = function(pre) { - var result = ''; - if(pre == null) { pre = ''; } - for(var i in this) { - if(this[i] != null && typeof(this[i]) != 'object' && typeof(this[i]) != 'function' && i != 'numVars') { - result += pre + i + '=' + this[i] + '&'; - } - } - if(result.length > 0) result = result.substr(0, result.length-1); - return result; -} -function getSearch(wRef) { - var searchStr = ''; - if(wRef.location.search.length > 1) { - searchStr = new String(wRef.location.search); - searchStr = searchStr.substring(1, searchStr.length); - } - return searchStr; -} -var lc_id = Math.floor(Math.random() * 100000).toString(16); -if (this != top) -{ - top.Vars = Vars; - top.getSearch = getSearch; - top.lc_id = lc_id; -} +// $Revision: 1.49 $ +// Vars +Vars = function(qStr) { + this.numVars = 0; + if(qStr != null) { + var nameValue, name; + var pairs = qStr.split('&'); + var pairLen = pairs.length; + for(var i = 0; i < pairLen; i++) { + var pair = pairs[i]; + if( (pair.indexOf('=')!= -1) && (pair.length > 3) ) { + var nameValue = pair.split('='); + var name = nameValue[0]; + var value = nameValue[1]; + if(this[name] == null && name.length > 0 && value.length > 0) { + this[name] = value; + this.numVars++; + } + } + } + } +} +Vars.prototype.toString = function(pre) { + var result = ''; + if(pre == null) { pre = ''; } + for(var i in this) { + if(this[i] != null && typeof(this[i]) != 'object' && typeof(this[i]) != 'function' && i != 'numVars') { + result += pre + i + '=' + this[i] + '&'; + } + } + if(result.length > 0) result = result.substr(0, result.length-1); + return result; +} +function getSearch(wRef) { + var searchStr = ''; + if(wRef.location.search.length > 1) { + searchStr = new String(wRef.location.search); + searchStr = searchStr.substring(1, searchStr.length); + } + return searchStr; +} +var lc_id = Math.floor(Math.random() * 100000).toString(16); +if (this != top) +{ + top.Vars = Vars; + top.getSearch = getSearch; + top.lc_id = lc_id; +} diff --git a/demos/blog-tutorial/index.php b/demos/blog-tutorial/index.php index 43c0b436..6efff1af 100644 --- a/demos/blog-tutorial/index.php +++ b/demos/blog-tutorial/index.php @@ -1,18 +1,18 @@ -run(); - +run(); + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/protected/common/InfoBox.php b/demos/blog-tutorial/protected/common/InfoBox.php index 271ce1e7..97b66067 100644 --- a/demos/blog-tutorial/protected/common/InfoBox.php +++ b/demos/blog-tutorial/protected/common/InfoBox.php @@ -1,13 +1,13 @@ -write("
Info:\n"); - $body=$this->renderChildren($writer); - $writer->write("
"); - } -} - +write("
Info:\n"); + $body=$this->renderChildren($writer); + $writer->write("
"); + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/protected/common/NoteBox.php b/demos/blog-tutorial/protected/common/NoteBox.php index f5123380..90d5faab 100644 --- a/demos/blog-tutorial/protected/common/NoteBox.php +++ b/demos/blog-tutorial/protected/common/NoteBox.php @@ -1,13 +1,13 @@ -write("
Note:\n"); - $body=$this->renderChildren($writer); - $writer->write("
"); - } -} - +write("
Note:\n"); + $body=$this->renderChildren($writer); + $writer->write("
"); + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/protected/common/TipBox.php b/demos/blog-tutorial/protected/common/TipBox.php index 2464a61a..58f79db8 100644 --- a/demos/blog-tutorial/protected/common/TipBox.php +++ b/demos/blog-tutorial/protected/common/TipBox.php @@ -1,13 +1,13 @@ -write("
Tip:\n"); - $body=$this->renderChildren($writer); - $writer->write("
"); - } -} - +write("
Tip:\n"); + $body=$this->renderChildren($writer); + $writer->write("
"); + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/protected/common/TopicList.php b/demos/blog-tutorial/protected/common/TopicList.php index ce827cc0..eb5976a9 100644 --- a/demos/blog-tutorial/protected/common/TopicList.php +++ b/demos/blog-tutorial/protected/common/TopicList.php @@ -1,8 +1,8 @@ - \ No newline at end of file diff --git a/demos/blog-tutorial/protected/layout/MainLayout.php b/demos/blog-tutorial/protected/layout/MainLayout.php index 4b5890de..d6ea146d 100644 --- a/demos/blog-tutorial/protected/layout/MainLayout.php +++ b/demos/blog-tutorial/protected/layout/MainLayout.php @@ -1,6 +1,6 @@ -Application->Globalization->Culture == $params['lang']) $item->link->CssClass="active"; } - } -} - + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day1/blog/index.php b/demos/blog-tutorial/samples/day1/blog/index.php index 7ccffe49..bffafde2 100644 --- a/demos/blog-tutorial/samples/day1/blog/index.php +++ b/demos/blog-tutorial/samples/day1/blog/index.php @@ -1,22 +1,22 @@ -run(); - +run(); + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day1/blog/protected/layouts/MainLayout.php b/demos/blog-tutorial/samples/day1/blog/protected/layouts/MainLayout.php index 253d6c03..c966ba85 100644 --- a/demos/blog-tutorial/samples/day1/blog/protected/layouts/MainLayout.php +++ b/demos/blog-tutorial/samples/day1/blog/protected/layouts/MainLayout.php @@ -1,7 +1,7 @@ - \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day1/blog/protected/pages/Contact.php b/demos/blog-tutorial/samples/day1/blog/protected/pages/Contact.php index b6ce575e..77d7374a 100644 --- a/demos/blog-tutorial/samples/day1/blog/protected/pages/Contact.php +++ b/demos/blog-tutorial/samples/day1/blog/protected/pages/Contact.php @@ -1,30 +1,30 @@ -IsValid) // check if input validation is successful - { - // obtain the user name, email, feedback from the textboxes - $name = $this->Name->Text; - $email = $this->Email->Text; - $feedback = $this->Feedback->Text; - - // send an email to administrator with the above information - $this->mailFeedback($name, $email, $feedback); - } - } - - protected function mailFeedback($name, $email, $feedback) - { - // implementation of sending the feedback email - } -} - +IsValid) // check if input validation is successful + { + // obtain the user name, email, feedback from the textboxes + $name = $this->Name->Text; + $email = $this->Email->Text; + $feedback = $this->Feedback->Text; + + // send an email to administrator with the above information + $this->mailFeedback($name, $email, $feedback); + } + } + + protected function mailFeedback($name, $email, $feedback) + { + // implementation of sending the feedback email + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day2/blog/index.php b/demos/blog-tutorial/samples/day2/blog/index.php index 7ccffe49..bffafde2 100644 --- a/demos/blog-tutorial/samples/day2/blog/index.php +++ b/demos/blog-tutorial/samples/day2/blog/index.php @@ -1,22 +1,22 @@ -run(); - +run(); + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day2/blog/protected/database/PostRecord.php b/demos/blog-tutorial/samples/day2/blog/protected/database/PostRecord.php index 25702727..3407c09b 100644 --- a/demos/blog-tutorial/samples/day2/blog/protected/database/PostRecord.php +++ b/demos/blog-tutorial/samples/day2/blog/protected/database/PostRecord.php @@ -1,28 +1,28 @@ - array(self::BELONGS_TO, 'UserRecord'), - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} + array(self::BELONGS_TO, 'UserRecord'), + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day2/blog/protected/database/UserRecord.php b/demos/blog-tutorial/samples/day2/blog/protected/database/UserRecord.php index 2051e5de..021f8b09 100644 --- a/demos/blog-tutorial/samples/day2/blog/protected/database/UserRecord.php +++ b/demos/blog-tutorial/samples/day2/blog/protected/database/UserRecord.php @@ -1,28 +1,28 @@ - array(self::HAS_MANY, 'PostRecord'), - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} + array(self::HAS_MANY, 'PostRecord'), + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day2/blog/protected/layouts/MainLayout.php b/demos/blog-tutorial/samples/day2/blog/protected/layouts/MainLayout.php index 253d6c03..c966ba85 100644 --- a/demos/blog-tutorial/samples/day2/blog/protected/layouts/MainLayout.php +++ b/demos/blog-tutorial/samples/day2/blog/protected/layouts/MainLayout.php @@ -1,7 +1,7 @@ - \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day2/blog/protected/pages/Contact.php b/demos/blog-tutorial/samples/day2/blog/protected/pages/Contact.php index b6ce575e..77d7374a 100644 --- a/demos/blog-tutorial/samples/day2/blog/protected/pages/Contact.php +++ b/demos/blog-tutorial/samples/day2/blog/protected/pages/Contact.php @@ -1,30 +1,30 @@ -IsValid) // check if input validation is successful - { - // obtain the user name, email, feedback from the textboxes - $name = $this->Name->Text; - $email = $this->Email->Text; - $feedback = $this->Feedback->Text; - - // send an email to administrator with the above information - $this->mailFeedback($name, $email, $feedback); - } - } - - protected function mailFeedback($name, $email, $feedback) - { - // implementation of sending the feedback email - } -} - +IsValid) // check if input validation is successful + { + // obtain the user name, email, feedback from the textboxes + $name = $this->Name->Text; + $email = $this->Email->Text; + $feedback = $this->Feedback->Text; + + // send an email to administrator with the above information + $this->mailFeedback($name, $email, $feedback); + } + } + + protected function mailFeedback($name, $email, $feedback) + { + // implementation of sending the feedback email + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day3/blog/index.php b/demos/blog-tutorial/samples/day3/blog/index.php index 7ccffe49..bffafde2 100644 --- a/demos/blog-tutorial/samples/day3/blog/index.php +++ b/demos/blog-tutorial/samples/day3/blog/index.php @@ -1,22 +1,22 @@ -run(); - +run(); + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day3/blog/protected/BlogUser.php b/demos/blog-tutorial/samples/day3/blog/protected/BlogUser.php index 6b9e0a23..4f094a0c 100644 --- a/demos/blog-tutorial/samples/day3/blog/protected/BlogUser.php +++ b/demos/blog-tutorial/samples/day3/blog/protected/BlogUser.php @@ -1,59 +1,59 @@ -findByPk($username); - if($userRecord instanceof UserRecord) // if found - { - $user=new BlogUser($this->Manager); - $user->Name=$username; // set username - $user->Roles=($userRecord->role==1?'admin':'user'); // set role - $user->IsGuest=false; // the user is not a guest - return $user; - } - else - return null; - } - - /** - * Checks if the specified (username, password) is valid. - * This method is required by TDbUser. - * @param string username - * @param string password - * @return boolean whether the username and password are valid. - */ - public function validateUser($username,$password) - { - // use UserRecord Active Record to look for the (username, password) pair. - return UserRecord::finder()->findBy_username_AND_password($username,$password)!==null; - } - - /** - * @return boolean whether this user is an administrator. - */ - public function getIsAdmin() - { - return $this->isInRole('admin'); - } -} - +findByPk($username); + if($userRecord instanceof UserRecord) // if found + { + $user=new BlogUser($this->Manager); + $user->Name=$username; // set username + $user->Roles=($userRecord->role==1?'admin':'user'); // set role + $user->IsGuest=false; // the user is not a guest + return $user; + } + else + return null; + } + + /** + * Checks if the specified (username, password) is valid. + * This method is required by TDbUser. + * @param string username + * @param string password + * @return boolean whether the username and password are valid. + */ + public function validateUser($username,$password) + { + // use UserRecord Active Record to look for the (username, password) pair. + return UserRecord::finder()->findBy_username_AND_password($username,$password)!==null; + } + + /** + * @return boolean whether this user is an administrator. + */ + public function getIsAdmin() + { + return $this->isInRole('admin'); + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day3/blog/protected/database/PostRecord.php b/demos/blog-tutorial/samples/day3/blog/protected/database/PostRecord.php index 25702727..3407c09b 100644 --- a/demos/blog-tutorial/samples/day3/blog/protected/database/PostRecord.php +++ b/demos/blog-tutorial/samples/day3/blog/protected/database/PostRecord.php @@ -1,28 +1,28 @@ - array(self::BELONGS_TO, 'UserRecord'), - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} + array(self::BELONGS_TO, 'UserRecord'), + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day3/blog/protected/database/UserRecord.php b/demos/blog-tutorial/samples/day3/blog/protected/database/UserRecord.php index 2051e5de..021f8b09 100644 --- a/demos/blog-tutorial/samples/day3/blog/protected/database/UserRecord.php +++ b/demos/blog-tutorial/samples/day3/blog/protected/database/UserRecord.php @@ -1,28 +1,28 @@ - array(self::HAS_MANY, 'PostRecord'), - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} + array(self::HAS_MANY, 'PostRecord'), + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day3/blog/protected/layouts/MainLayout.php b/demos/blog-tutorial/samples/day3/blog/protected/layouts/MainLayout.php index 46c1483d..f605f75c 100644 --- a/demos/blog-tutorial/samples/day3/blog/protected/layouts/MainLayout.php +++ b/demos/blog-tutorial/samples/day3/blog/protected/layouts/MainLayout.php @@ -1,19 +1,19 @@ -Application->getModule('auth')->logout(); - $url=$this->Service->constructUrl($this->Service->DefaultPage); - $this->Response->redirect($url); - } -} - +Application->getModule('auth')->logout(); + $url=$this->Service->constructUrl($this->Service->DefaultPage); + $this->Response->redirect($url); + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day3/blog/protected/pages/Contact.php b/demos/blog-tutorial/samples/day3/blog/protected/pages/Contact.php index b6ce575e..77d7374a 100644 --- a/demos/blog-tutorial/samples/day3/blog/protected/pages/Contact.php +++ b/demos/blog-tutorial/samples/day3/blog/protected/pages/Contact.php @@ -1,30 +1,30 @@ -IsValid) // check if input validation is successful - { - // obtain the user name, email, feedback from the textboxes - $name = $this->Name->Text; - $email = $this->Email->Text; - $feedback = $this->Feedback->Text; - - // send an email to administrator with the above information - $this->mailFeedback($name, $email, $feedback); - } - } - - protected function mailFeedback($name, $email, $feedback) - { - // implementation of sending the feedback email - } -} - +IsValid) // check if input validation is successful + { + // obtain the user name, email, feedback from the textboxes + $name = $this->Name->Text; + $email = $this->Email->Text; + $feedback = $this->Feedback->Text; + + // send an email to administrator with the above information + $this->mailFeedback($name, $email, $feedback); + } + } + + protected function mailFeedback($name, $email, $feedback) + { + // implementation of sending the feedback email + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day3/blog/protected/pages/users/AdminUser.php b/demos/blog-tutorial/samples/day3/blog/protected/pages/users/AdminUser.php index ad8f6e3d..ad668e1a 100644 --- a/demos/blog-tutorial/samples/day3/blog/protected/pages/users/AdminUser.php +++ b/demos/blog-tutorial/samples/day3/blog/protected/pages/users/AdminUser.php @@ -1,36 +1,36 @@ -UserGrid->DataSource=UserRecord::finder()->findAll(); - // binds the data to interface components - $this->UserGrid->dataBind(); - } - - /** - * Deletes a specified user record. - * This method responds to the datagrid's OnDeleteCommand event. - * @param TDataGrid the event sender - * @param TDataGridCommandEventParameter the event parameter - */ - public function deleteButtonClicked($sender,$param) - { - // obtains the datagrid item that contains the clicked delete button - $item=$param->Item; - // obtains the primary key corresponding to the datagrid item - $username=$this->UserGrid->DataKeys[$item->ItemIndex]; - // deletes the user record with the specified username primary key - UserRecord::finder()->deleteByPk($username); - } -} - +UserGrid->DataSource=UserRecord::finder()->findAll(); + // binds the data to interface components + $this->UserGrid->dataBind(); + } + + /** + * Deletes a specified user record. + * This method responds to the datagrid's OnDeleteCommand event. + * @param TDataGrid the event sender + * @param TDataGridCommandEventParameter the event parameter + */ + public function deleteButtonClicked($sender,$param) + { + // obtains the datagrid item that contains the clicked delete button + $item=$param->Item; + // obtains the primary key corresponding to the datagrid item + $username=$this->UserGrid->DataKeys[$item->ItemIndex]; + // deletes the user record with the specified username primary key + UserRecord::finder()->deleteByPk($username); + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day3/blog/protected/pages/users/EditUser.php b/demos/blog-tutorial/samples/day3/blog/protected/pages/users/EditUser.php index 81538c33..f8c61463 100644 --- a/demos/blog-tutorial/samples/day3/blog/protected/pages/users/EditUser.php +++ b/demos/blog-tutorial/samples/day3/blog/protected/pages/users/EditUser.php @@ -1,83 +1,83 @@ -IsPostBack) // if the page is initially requested - { - // Retrieves the existing user data. This is equivalent to: - // $userRecord=$this->getUserRecord(); - $userRecord=$this->UserRecord; - - // Populates the input controls with the existing user data - $this->Username->Text=$userRecord->username; - $this->Email->Text=$userRecord->email; - $this->Role->SelectedValue=$userRecord->role; - $this->FirstName->Text=$userRecord->first_name; - $this->LastName->Text=$userRecord->last_name; - } - } - - /** - * Saves the user account if all inputs are valid. - * This method responds to the OnClick event of the "save" button. - * @param mixed event sender - * @param mixed event parameter - */ - public function saveButtonClicked($sender,$param) - { - if($this->IsValid) // when all validations succeed - { - // Retrieves the existing user data. This is equivalent to: - $userRecord=$this->UserRecord; - - // Fetches the input data - $userRecord->username=$this->Username->Text; - // update password when the input is not empty - if(!empty($this->Password->Text)) - $userRecord->password=$this->Password->Text; - $userRecord->email=$this->Email->Text; - // update the role if the current user is an administrator - if($this->User->IsAdmin) - $userRecord->role=(int)$this->Role->SelectedValue; - $userRecord->first_name=$this->FirstName->Text; - $userRecord->last_name=$this->LastName->Text; - - // saves to the database via Active Record mechanism - $userRecord->save(); - - // redirects the browser to the homepage - $this->Response->redirect($this->Service->DefaultPageUrl); - } - } - - /** - * Returns the user data to be editted. - * @return UserRecord the user data to be editted. - * @throws THttpException if the user data is not found. - */ - protected function getUserRecord() - { - // the user to be editted is the currently logged-in user - $username=$this->User->Name; - // if the 'username' GET var is not empty and the current user - // is an administrator, we use the GET var value instead. - if($this->User->IsAdmin && $this->Request['username']!==null) - $username=$this->Request['username']; - - // use Active Record to look for the specified username - $userRecord=UserRecord::finder()->findByPk($username); - if(!($userRecord instanceof UserRecord)) - throw new THttpException(500,'Username is invalid.'); - return $userRecord; - } -} - +IsPostBack) // if the page is initially requested + { + // Retrieves the existing user data. This is equivalent to: + // $userRecord=$this->getUserRecord(); + $userRecord=$this->UserRecord; + + // Populates the input controls with the existing user data + $this->Username->Text=$userRecord->username; + $this->Email->Text=$userRecord->email; + $this->Role->SelectedValue=$userRecord->role; + $this->FirstName->Text=$userRecord->first_name; + $this->LastName->Text=$userRecord->last_name; + } + } + + /** + * Saves the user account if all inputs are valid. + * This method responds to the OnClick event of the "save" button. + * @param mixed event sender + * @param mixed event parameter + */ + public function saveButtonClicked($sender,$param) + { + if($this->IsValid) // when all validations succeed + { + // Retrieves the existing user data. This is equivalent to: + $userRecord=$this->UserRecord; + + // Fetches the input data + $userRecord->username=$this->Username->Text; + // update password when the input is not empty + if(!empty($this->Password->Text)) + $userRecord->password=$this->Password->Text; + $userRecord->email=$this->Email->Text; + // update the role if the current user is an administrator + if($this->User->IsAdmin) + $userRecord->role=(int)$this->Role->SelectedValue; + $userRecord->first_name=$this->FirstName->Text; + $userRecord->last_name=$this->LastName->Text; + + // saves to the database via Active Record mechanism + $userRecord->save(); + + // redirects the browser to the homepage + $this->Response->redirect($this->Service->DefaultPageUrl); + } + } + + /** + * Returns the user data to be editted. + * @return UserRecord the user data to be editted. + * @throws THttpException if the user data is not found. + */ + protected function getUserRecord() + { + // the user to be editted is the currently logged-in user + $username=$this->User->Name; + // if the 'username' GET var is not empty and the current user + // is an administrator, we use the GET var value instead. + if($this->User->IsAdmin && $this->Request['username']!==null) + $username=$this->Request['username']; + + // use Active Record to look for the specified username + $userRecord=UserRecord::finder()->findByPk($username); + if(!($userRecord instanceof UserRecord)) + throw new THttpException(500,'Username is invalid.'); + return $userRecord; + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day3/blog/protected/pages/users/LoginUser.php b/demos/blog-tutorial/samples/day3/blog/protected/pages/users/LoginUser.php index a0955490..407906ae 100644 --- a/demos/blog-tutorial/samples/day3/blog/protected/pages/users/LoginUser.php +++ b/demos/blog-tutorial/samples/day3/blog/protected/pages/users/LoginUser.php @@ -1,37 +1,37 @@ -Application->getModule('auth'); - if(!$authManager->login($this->Username->Text,$this->Password->Text)) - $param->IsValid=false; // tell the validator that validation fails - } - - /** - * Redirects the user's browser to appropriate URL if login succeeds. - * This method responds to the login button's OnClick event. - * @param mixed event sender - * @param mixed event parameter - */ - public function loginButtonClicked($sender,$param) - { - if($this->Page->IsValid) // all validations succeed - { - // obtain the URL of the privileged page that the user wanted to visit originally - $url=$this->Application->getModule('auth')->ReturnUrl; - if(empty($url)) // the user accesses the login page directly - $url=$this->Service->DefaultPageUrl; - $this->Response->redirect($url); - } - } -} - +Application->getModule('auth'); + if(!$authManager->login($this->Username->Text,$this->Password->Text)) + $param->IsValid=false; // tell the validator that validation fails + } + + /** + * Redirects the user's browser to appropriate URL if login succeeds. + * This method responds to the login button's OnClick event. + * @param mixed event sender + * @param mixed event parameter + */ + public function loginButtonClicked($sender,$param) + { + if($this->Page->IsValid) // all validations succeed + { + // obtain the URL of the privileged page that the user wanted to visit originally + $url=$this->Application->getModule('auth')->ReturnUrl; + if(empty($url)) // the user accesses the login page directly + $url=$this->Service->DefaultPageUrl; + $this->Response->redirect($url); + } + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day3/blog/protected/pages/users/NewUser.php b/demos/blog-tutorial/samples/day3/blog/protected/pages/users/NewUser.php index 76e8cb88..3bf6768a 100644 --- a/demos/blog-tutorial/samples/day3/blog/protected/pages/users/NewUser.php +++ b/demos/blog-tutorial/samples/day3/blog/protected/pages/users/NewUser.php @@ -1,45 +1,45 @@ -IsValid=UserRecord::finder()->findByPk($this->Username->Text)===null; - } - - /** - * Creates a new user account if all inputs are valid. - * This method responds to the OnClick event of the "create" button. - * @param mixed event sender - * @param mixed event parameter - */ - public function createButtonClicked($sender,$param) - { - if($this->IsValid) // when all validations succeed - { - // populates a UserRecord object with user inputs - $userRecord=new UserRecord; - $userRecord->username=$this->Username->Text; - $userRecord->password=$this->Password->Text; - $userRecord->email=$this->Email->Text; - $userRecord->role=(int)$this->Role->SelectedValue; - $userRecord->first_name=$this->FirstName->Text; - $userRecord->last_name=$this->LastName->Text; - - // saves to the database via Active Record mechanism - $userRecord->save(); - - // redirects the browser to the homepage - $this->Response->redirect($this->Service->DefaultPageUrl); - } - } -} - +IsValid=UserRecord::finder()->findByPk($this->Username->Text)===null; + } + + /** + * Creates a new user account if all inputs are valid. + * This method responds to the OnClick event of the "create" button. + * @param mixed event sender + * @param mixed event parameter + */ + public function createButtonClicked($sender,$param) + { + if($this->IsValid) // when all validations succeed + { + // populates a UserRecord object with user inputs + $userRecord=new UserRecord; + $userRecord->username=$this->Username->Text; + $userRecord->password=$this->Password->Text; + $userRecord->email=$this->Email->Text; + $userRecord->role=(int)$this->Role->SelectedValue; + $userRecord->first_name=$this->FirstName->Text; + $userRecord->last_name=$this->LastName->Text; + + // saves to the database via Active Record mechanism + $userRecord->save(); + + // redirects the browser to the homepage + $this->Response->redirect($this->Service->DefaultPageUrl); + } + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day4/blog/index.php b/demos/blog-tutorial/samples/day4/blog/index.php index 7ccffe49..bffafde2 100644 --- a/demos/blog-tutorial/samples/day4/blog/index.php +++ b/demos/blog-tutorial/samples/day4/blog/index.php @@ -1,22 +1,22 @@ -run(); - +run(); + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day4/blog/protected/BlogUser.php b/demos/blog-tutorial/samples/day4/blog/protected/BlogUser.php index 6b9e0a23..4f094a0c 100644 --- a/demos/blog-tutorial/samples/day4/blog/protected/BlogUser.php +++ b/demos/blog-tutorial/samples/day4/blog/protected/BlogUser.php @@ -1,59 +1,59 @@ -findByPk($username); - if($userRecord instanceof UserRecord) // if found - { - $user=new BlogUser($this->Manager); - $user->Name=$username; // set username - $user->Roles=($userRecord->role==1?'admin':'user'); // set role - $user->IsGuest=false; // the user is not a guest - return $user; - } - else - return null; - } - - /** - * Checks if the specified (username, password) is valid. - * This method is required by TDbUser. - * @param string username - * @param string password - * @return boolean whether the username and password are valid. - */ - public function validateUser($username,$password) - { - // use UserRecord Active Record to look for the (username, password) pair. - return UserRecord::finder()->findBy_username_AND_password($username,$password)!==null; - } - - /** - * @return boolean whether this user is an administrator. - */ - public function getIsAdmin() - { - return $this->isInRole('admin'); - } -} - +findByPk($username); + if($userRecord instanceof UserRecord) // if found + { + $user=new BlogUser($this->Manager); + $user->Name=$username; // set username + $user->Roles=($userRecord->role==1?'admin':'user'); // set role + $user->IsGuest=false; // the user is not a guest + return $user; + } + else + return null; + } + + /** + * Checks if the specified (username, password) is valid. + * This method is required by TDbUser. + * @param string username + * @param string password + * @return boolean whether the username and password are valid. + */ + public function validateUser($username,$password) + { + // use UserRecord Active Record to look for the (username, password) pair. + return UserRecord::finder()->findBy_username_AND_password($username,$password)!==null; + } + + /** + * @return boolean whether this user is an administrator. + */ + public function getIsAdmin() + { + return $this->isInRole('admin'); + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day4/blog/protected/database/PostRecord.php b/demos/blog-tutorial/samples/day4/blog/protected/database/PostRecord.php index 25702727..3407c09b 100644 --- a/demos/blog-tutorial/samples/day4/blog/protected/database/PostRecord.php +++ b/demos/blog-tutorial/samples/day4/blog/protected/database/PostRecord.php @@ -1,28 +1,28 @@ - array(self::BELONGS_TO, 'UserRecord'), - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} + array(self::BELONGS_TO, 'UserRecord'), + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day4/blog/protected/database/UserRecord.php b/demos/blog-tutorial/samples/day4/blog/protected/database/UserRecord.php index 2051e5de..021f8b09 100644 --- a/demos/blog-tutorial/samples/day4/blog/protected/database/UserRecord.php +++ b/demos/blog-tutorial/samples/day4/blog/protected/database/UserRecord.php @@ -1,28 +1,28 @@ - array(self::HAS_MANY, 'PostRecord'), - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} + array(self::HAS_MANY, 'PostRecord'), + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day4/blog/protected/layouts/MainLayout.php b/demos/blog-tutorial/samples/day4/blog/protected/layouts/MainLayout.php index 46c1483d..f605f75c 100644 --- a/demos/blog-tutorial/samples/day4/blog/protected/layouts/MainLayout.php +++ b/demos/blog-tutorial/samples/day4/blog/protected/layouts/MainLayout.php @@ -1,19 +1,19 @@ -Application->getModule('auth')->logout(); - $url=$this->Service->constructUrl($this->Service->DefaultPage); - $this->Response->redirect($url); - } -} - +Application->getModule('auth')->logout(); + $url=$this->Service->constructUrl($this->Service->DefaultPage); + $this->Response->redirect($url); + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day4/blog/protected/pages/Contact.php b/demos/blog-tutorial/samples/day4/blog/protected/pages/Contact.php index b6ce575e..77d7374a 100644 --- a/demos/blog-tutorial/samples/day4/blog/protected/pages/Contact.php +++ b/demos/blog-tutorial/samples/day4/blog/protected/pages/Contact.php @@ -1,30 +1,30 @@ -IsValid) // check if input validation is successful - { - // obtain the user name, email, feedback from the textboxes - $name = $this->Name->Text; - $email = $this->Email->Text; - $feedback = $this->Feedback->Text; - - // send an email to administrator with the above information - $this->mailFeedback($name, $email, $feedback); - } - } - - protected function mailFeedback($name, $email, $feedback) - { - // implementation of sending the feedback email - } -} - +IsValid) // check if input validation is successful + { + // obtain the user name, email, feedback from the textboxes + $name = $this->Name->Text; + $email = $this->Email->Text; + $feedback = $this->Feedback->Text; + + // send an email to administrator with the above information + $this->mailFeedback($name, $email, $feedback); + } + } + + protected function mailFeedback($name, $email, $feedback) + { + // implementation of sending the feedback email + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/EditPost.php b/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/EditPost.php index e137b85e..1b0f82b6 100644 --- a/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/EditPost.php +++ b/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/EditPost.php @@ -1,72 +1,72 @@ -getPost(); - $postRecord=$this->Post; - // Authorization check: only the author or the administrator can edit the post - if($postRecord->author_id!==$this->User->Name && !$this->User->IsAdmin) - throw new THttpException(500,'You are not allowed to edit this post.'); - - if(!$this->IsPostBack) // if the page is initially requested - { - // Populates the input controls with the existing post data - $this->TitleEdit->Text=$postRecord->title; - $this->ContentEdit->Text=$postRecord->content; - } - } - - /** - * Saves the post if all inputs are valid. - * This method responds to the OnClick event of the "Save" button. - * @param mixed event sender - * @param mixed event parameter - */ - public function saveButtonClicked($sender,$param) - { - if($this->IsValid) // when all validations succeed - { - // Retrieves the existing user data. This is equivalent to: - // $postRecord=$this->getPost(); - $postRecord=$this->Post; - - // Fetches the input data - $postRecord->title=$this->TitleEdit->SafeText; - $postRecord->content=$this->ContentEdit->SafeText; - - // saves to the database via Active Record mechanism - $postRecord->save(); - - // redirects the browser to the ReadPost page - $url=$this->Service->constructUrl('posts.ReadPost',array('id'=>$postRecord->post_id)); - $this->Response->redirect($url); - } - } - - /** - * Returns the post data to be editted. - * @return PostRecord the post data to be editted. - * @throws THttpException if the post data is not found. - */ - protected function getPost() - { - // the ID of the post to be editted is passed via GET parameter 'id' - $postID=(int)$this->Request['id']; - // use Active Record to look for the specified post ID - $postRecord=PostRecord::finder()->findByPk($postID); - if($postRecord===null) - throw new THttpException(500,'Post is not found.'); - return $postRecord; - } -} - +getPost(); + $postRecord=$this->Post; + // Authorization check: only the author or the administrator can edit the post + if($postRecord->author_id!==$this->User->Name && !$this->User->IsAdmin) + throw new THttpException(500,'You are not allowed to edit this post.'); + + if(!$this->IsPostBack) // if the page is initially requested + { + // Populates the input controls with the existing post data + $this->TitleEdit->Text=$postRecord->title; + $this->ContentEdit->Text=$postRecord->content; + } + } + + /** + * Saves the post if all inputs are valid. + * This method responds to the OnClick event of the "Save" button. + * @param mixed event sender + * @param mixed event parameter + */ + public function saveButtonClicked($sender,$param) + { + if($this->IsValid) // when all validations succeed + { + // Retrieves the existing user data. This is equivalent to: + // $postRecord=$this->getPost(); + $postRecord=$this->Post; + + // Fetches the input data + $postRecord->title=$this->TitleEdit->SafeText; + $postRecord->content=$this->ContentEdit->SafeText; + + // saves to the database via Active Record mechanism + $postRecord->save(); + + // redirects the browser to the ReadPost page + $url=$this->Service->constructUrl('posts.ReadPost',array('id'=>$postRecord->post_id)); + $this->Response->redirect($url); + } + } + + /** + * Returns the post data to be editted. + * @return PostRecord the post data to be editted. + * @throws THttpException if the post data is not found. + */ + protected function getPost() + { + // the ID of the post to be editted is passed via GET parameter 'id' + $postID=(int)$this->Request['id']; + // use Active Record to look for the specified post ID + $postRecord=PostRecord::finder()->findByPk($postID); + if($postRecord===null) + throw new THttpException(500,'Post is not found.'); + return $postRecord; + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/ListPost.php b/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/ListPost.php index 7402dace..ae5a7eeb 100644 --- a/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/ListPost.php +++ b/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/ListPost.php @@ -1,64 +1,64 @@ -IsPostBack) // if the page is requested the first time - { - // get the total number of posts available - $this->Repeater->VirtualItemCount=PostRecord::finder()->count(); - // populates post data into the repeater - $this->populateData(); - } - } - - /** - * Event handler to the OnPageIndexChanged event of the pager. - * This method is invoked when the user clicks on a page button - * and thus changes the page of posts to display. - */ - public function pageChanged($sender,$param) - { - // change the current page index to the new one - $this->Repeater->CurrentPageIndex=$param->NewPageIndex; - // re-populate data into the repeater - $this->populateData(); - } - - /** - * Determines which page of posts to be displayed and - * populates the repeater with the fetched data. - */ - protected function populateData() - { - $offset=$this->Repeater->CurrentPageIndex*$this->Repeater->PageSize; - $limit=$this->Repeater->PageSize; - if($offset+$limit>$this->Repeater->VirtualItemCount) - $limit=$this->Repeater->VirtualItemCount-$offset; - $this->Repeater->DataSource=$this->getPosts($offset,$limit); - $this->Repeater->dataBind(); - } - - /** - * Fetches posts from database with offset and limit. - */ - protected function getPosts($offset, $limit) - { - // Construts a query criteria - $criteria=new TActiveRecordCriteria; - $criteria->OrdersBy['create_time']='desc'; - $criteria->Limit=$limit; - $criteria->Offset=$offset; - // query for the posts with the above criteria and with author information - return PostRecord::finder()->withAuthor()->findAll($criteria); - } -} - +IsPostBack) // if the page is requested the first time + { + // get the total number of posts available + $this->Repeater->VirtualItemCount=PostRecord::finder()->count(); + // populates post data into the repeater + $this->populateData(); + } + } + + /** + * Event handler to the OnPageIndexChanged event of the pager. + * This method is invoked when the user clicks on a page button + * and thus changes the page of posts to display. + */ + public function pageChanged($sender,$param) + { + // change the current page index to the new one + $this->Repeater->CurrentPageIndex=$param->NewPageIndex; + // re-populate data into the repeater + $this->populateData(); + } + + /** + * Determines which page of posts to be displayed and + * populates the repeater with the fetched data. + */ + protected function populateData() + { + $offset=$this->Repeater->CurrentPageIndex*$this->Repeater->PageSize; + $limit=$this->Repeater->PageSize; + if($offset+$limit>$this->Repeater->VirtualItemCount) + $limit=$this->Repeater->VirtualItemCount-$offset; + $this->Repeater->DataSource=$this->getPosts($offset,$limit); + $this->Repeater->dataBind(); + } + + /** + * Fetches posts from database with offset and limit. + */ + protected function getPosts($offset, $limit) + { + // Construts a query criteria + $criteria=new TActiveRecordCriteria; + $criteria->OrdersBy['create_time']='desc'; + $criteria->Limit=$limit; + $criteria->Offset=$offset; + // query for the posts with the above criteria and with author information + return PostRecord::finder()->withAuthor()->findAll($criteria); + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/NewPost.php b/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/NewPost.php index a5e3ea4d..d3a36133 100644 --- a/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/NewPost.php +++ b/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/NewPost.php @@ -1,34 +1,34 @@ -IsValid) // when all validations succeed - { - // populates a PostRecord object with user inputs - $postRecord=new PostRecord; - // using SafeText instead of Text avoids Cross Site Scripting attack - $postRecord->title=$this->TitleEdit->SafeText; - $postRecord->content=$this->ContentEdit->SafeText; - $postRecord->author_id=$this->User->Name; - $postRecord->create_time=time(); - $postRecord->status=0; - - // saves to the database via Active Record mechanism - $postRecord->save(); - - // redirects the browser to the newly created post page - $url=$this->Service->constructUrl('posts.ReadPost',array('id'=>$postRecord->post_id)); - $this->Response->redirect($url); - } - } -} - +IsValid) // when all validations succeed + { + // populates a PostRecord object with user inputs + $postRecord=new PostRecord; + // using SafeText instead of Text avoids Cross Site Scripting attack + $postRecord->title=$this->TitleEdit->SafeText; + $postRecord->content=$this->ContentEdit->SafeText; + $postRecord->author_id=$this->User->Name; + $postRecord->create_time=time(); + $postRecord->status=0; + + // saves to the database via Active Record mechanism + $postRecord->save(); + + // redirects the browser to the newly created post page + $url=$this->Service->constructUrl('posts.ReadPost',array('id'=>$postRecord->post_id)); + $this->Response->redirect($url); + } + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/PostRenderer.php b/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/PostRenderer.php index cf0539a1..ed80f10c 100644 --- a/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/PostRenderer.php +++ b/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/PostRenderer.php @@ -1,7 +1,7 @@ - \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/ReadPost.php b/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/ReadPost.php index 2aeaa4d3..4c2035e6 100644 --- a/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/ReadPost.php +++ b/demos/blog-tutorial/samples/day4/blog/protected/pages/posts/ReadPost.php @@ -1,57 +1,57 @@ -Request['id']; - // retrieves PostRecord with author information filled in - $this->_post=PostRecord::finder()->withAuthor()->findByPk($postID); - if($this->_post===null) // if post id is invalid - throw new THttpException(500,'Unable to find the specified post.'); - // set the page title as the post title - $this->Title=$this->_post->title; - } - - /** - * @return PostRecord the PostRecord currently being viewed - */ - public function getPost() - { - return $this->_post; - } - - /** - * Deletes the post currently being viewed - * This method is invoked when the user clicks on the "Delete" button - */ - public function deletePost($sender,$param) - { - // only the author or the administrator can delete a post - if(!$this->canEdit()) - throw new THttpException('You are not allowed to perform this action.'); - // delete it from DB - $this->_post->delete(); - // redirect the browser to the homepage - $this->Response->redirect($this->Service->DefaultPageUrl); - } - - /** - * @return boolean whether the current user can edit/delete the post being viewed - */ - public function canEdit() - { - // only the author or the administrator can edit/delete a post - return $this->User->Name===$this->Post->author_id || $this->User->IsAdmin; - } -} - +Request['id']; + // retrieves PostRecord with author information filled in + $this->_post=PostRecord::finder()->withAuthor()->findByPk($postID); + if($this->_post===null) // if post id is invalid + throw new THttpException(500,'Unable to find the specified post.'); + // set the page title as the post title + $this->Title=$this->_post->title; + } + + /** + * @return PostRecord the PostRecord currently being viewed + */ + public function getPost() + { + return $this->_post; + } + + /** + * Deletes the post currently being viewed + * This method is invoked when the user clicks on the "Delete" button + */ + public function deletePost($sender,$param) + { + // only the author or the administrator can delete a post + if(!$this->canEdit()) + throw new THttpException('You are not allowed to perform this action.'); + // delete it from DB + $this->_post->delete(); + // redirect the browser to the homepage + $this->Response->redirect($this->Service->DefaultPageUrl); + } + + /** + * @return boolean whether the current user can edit/delete the post being viewed + */ + public function canEdit() + { + // only the author or the administrator can edit/delete a post + return $this->User->Name===$this->Post->author_id || $this->User->IsAdmin; + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day4/blog/protected/pages/users/AdminUser.php b/demos/blog-tutorial/samples/day4/blog/protected/pages/users/AdminUser.php index ad8f6e3d..ad668e1a 100644 --- a/demos/blog-tutorial/samples/day4/blog/protected/pages/users/AdminUser.php +++ b/demos/blog-tutorial/samples/day4/blog/protected/pages/users/AdminUser.php @@ -1,36 +1,36 @@ -UserGrid->DataSource=UserRecord::finder()->findAll(); - // binds the data to interface components - $this->UserGrid->dataBind(); - } - - /** - * Deletes a specified user record. - * This method responds to the datagrid's OnDeleteCommand event. - * @param TDataGrid the event sender - * @param TDataGridCommandEventParameter the event parameter - */ - public function deleteButtonClicked($sender,$param) - { - // obtains the datagrid item that contains the clicked delete button - $item=$param->Item; - // obtains the primary key corresponding to the datagrid item - $username=$this->UserGrid->DataKeys[$item->ItemIndex]; - // deletes the user record with the specified username primary key - UserRecord::finder()->deleteByPk($username); - } -} - +UserGrid->DataSource=UserRecord::finder()->findAll(); + // binds the data to interface components + $this->UserGrid->dataBind(); + } + + /** + * Deletes a specified user record. + * This method responds to the datagrid's OnDeleteCommand event. + * @param TDataGrid the event sender + * @param TDataGridCommandEventParameter the event parameter + */ + public function deleteButtonClicked($sender,$param) + { + // obtains the datagrid item that contains the clicked delete button + $item=$param->Item; + // obtains the primary key corresponding to the datagrid item + $username=$this->UserGrid->DataKeys[$item->ItemIndex]; + // deletes the user record with the specified username primary key + UserRecord::finder()->deleteByPk($username); + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day4/blog/protected/pages/users/EditUser.php b/demos/blog-tutorial/samples/day4/blog/protected/pages/users/EditUser.php index 81538c33..f8c61463 100644 --- a/demos/blog-tutorial/samples/day4/blog/protected/pages/users/EditUser.php +++ b/demos/blog-tutorial/samples/day4/blog/protected/pages/users/EditUser.php @@ -1,83 +1,83 @@ -IsPostBack) // if the page is initially requested - { - // Retrieves the existing user data. This is equivalent to: - // $userRecord=$this->getUserRecord(); - $userRecord=$this->UserRecord; - - // Populates the input controls with the existing user data - $this->Username->Text=$userRecord->username; - $this->Email->Text=$userRecord->email; - $this->Role->SelectedValue=$userRecord->role; - $this->FirstName->Text=$userRecord->first_name; - $this->LastName->Text=$userRecord->last_name; - } - } - - /** - * Saves the user account if all inputs are valid. - * This method responds to the OnClick event of the "save" button. - * @param mixed event sender - * @param mixed event parameter - */ - public function saveButtonClicked($sender,$param) - { - if($this->IsValid) // when all validations succeed - { - // Retrieves the existing user data. This is equivalent to: - $userRecord=$this->UserRecord; - - // Fetches the input data - $userRecord->username=$this->Username->Text; - // update password when the input is not empty - if(!empty($this->Password->Text)) - $userRecord->password=$this->Password->Text; - $userRecord->email=$this->Email->Text; - // update the role if the current user is an administrator - if($this->User->IsAdmin) - $userRecord->role=(int)$this->Role->SelectedValue; - $userRecord->first_name=$this->FirstName->Text; - $userRecord->last_name=$this->LastName->Text; - - // saves to the database via Active Record mechanism - $userRecord->save(); - - // redirects the browser to the homepage - $this->Response->redirect($this->Service->DefaultPageUrl); - } - } - - /** - * Returns the user data to be editted. - * @return UserRecord the user data to be editted. - * @throws THttpException if the user data is not found. - */ - protected function getUserRecord() - { - // the user to be editted is the currently logged-in user - $username=$this->User->Name; - // if the 'username' GET var is not empty and the current user - // is an administrator, we use the GET var value instead. - if($this->User->IsAdmin && $this->Request['username']!==null) - $username=$this->Request['username']; - - // use Active Record to look for the specified username - $userRecord=UserRecord::finder()->findByPk($username); - if(!($userRecord instanceof UserRecord)) - throw new THttpException(500,'Username is invalid.'); - return $userRecord; - } -} - +IsPostBack) // if the page is initially requested + { + // Retrieves the existing user data. This is equivalent to: + // $userRecord=$this->getUserRecord(); + $userRecord=$this->UserRecord; + + // Populates the input controls with the existing user data + $this->Username->Text=$userRecord->username; + $this->Email->Text=$userRecord->email; + $this->Role->SelectedValue=$userRecord->role; + $this->FirstName->Text=$userRecord->first_name; + $this->LastName->Text=$userRecord->last_name; + } + } + + /** + * Saves the user account if all inputs are valid. + * This method responds to the OnClick event of the "save" button. + * @param mixed event sender + * @param mixed event parameter + */ + public function saveButtonClicked($sender,$param) + { + if($this->IsValid) // when all validations succeed + { + // Retrieves the existing user data. This is equivalent to: + $userRecord=$this->UserRecord; + + // Fetches the input data + $userRecord->username=$this->Username->Text; + // update password when the input is not empty + if(!empty($this->Password->Text)) + $userRecord->password=$this->Password->Text; + $userRecord->email=$this->Email->Text; + // update the role if the current user is an administrator + if($this->User->IsAdmin) + $userRecord->role=(int)$this->Role->SelectedValue; + $userRecord->first_name=$this->FirstName->Text; + $userRecord->last_name=$this->LastName->Text; + + // saves to the database via Active Record mechanism + $userRecord->save(); + + // redirects the browser to the homepage + $this->Response->redirect($this->Service->DefaultPageUrl); + } + } + + /** + * Returns the user data to be editted. + * @return UserRecord the user data to be editted. + * @throws THttpException if the user data is not found. + */ + protected function getUserRecord() + { + // the user to be editted is the currently logged-in user + $username=$this->User->Name; + // if the 'username' GET var is not empty and the current user + // is an administrator, we use the GET var value instead. + if($this->User->IsAdmin && $this->Request['username']!==null) + $username=$this->Request['username']; + + // use Active Record to look for the specified username + $userRecord=UserRecord::finder()->findByPk($username); + if(!($userRecord instanceof UserRecord)) + throw new THttpException(500,'Username is invalid.'); + return $userRecord; + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day4/blog/protected/pages/users/LoginUser.php b/demos/blog-tutorial/samples/day4/blog/protected/pages/users/LoginUser.php index a0955490..407906ae 100644 --- a/demos/blog-tutorial/samples/day4/blog/protected/pages/users/LoginUser.php +++ b/demos/blog-tutorial/samples/day4/blog/protected/pages/users/LoginUser.php @@ -1,37 +1,37 @@ -Application->getModule('auth'); - if(!$authManager->login($this->Username->Text,$this->Password->Text)) - $param->IsValid=false; // tell the validator that validation fails - } - - /** - * Redirects the user's browser to appropriate URL if login succeeds. - * This method responds to the login button's OnClick event. - * @param mixed event sender - * @param mixed event parameter - */ - public function loginButtonClicked($sender,$param) - { - if($this->Page->IsValid) // all validations succeed - { - // obtain the URL of the privileged page that the user wanted to visit originally - $url=$this->Application->getModule('auth')->ReturnUrl; - if(empty($url)) // the user accesses the login page directly - $url=$this->Service->DefaultPageUrl; - $this->Response->redirect($url); - } - } -} - +Application->getModule('auth'); + if(!$authManager->login($this->Username->Text,$this->Password->Text)) + $param->IsValid=false; // tell the validator that validation fails + } + + /** + * Redirects the user's browser to appropriate URL if login succeeds. + * This method responds to the login button's OnClick event. + * @param mixed event sender + * @param mixed event parameter + */ + public function loginButtonClicked($sender,$param) + { + if($this->Page->IsValid) // all validations succeed + { + // obtain the URL of the privileged page that the user wanted to visit originally + $url=$this->Application->getModule('auth')->ReturnUrl; + if(empty($url)) // the user accesses the login page directly + $url=$this->Service->DefaultPageUrl; + $this->Response->redirect($url); + } + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day4/blog/protected/pages/users/NewUser.php b/demos/blog-tutorial/samples/day4/blog/protected/pages/users/NewUser.php index 76e8cb88..3bf6768a 100644 --- a/demos/blog-tutorial/samples/day4/blog/protected/pages/users/NewUser.php +++ b/demos/blog-tutorial/samples/day4/blog/protected/pages/users/NewUser.php @@ -1,45 +1,45 @@ -IsValid=UserRecord::finder()->findByPk($this->Username->Text)===null; - } - - /** - * Creates a new user account if all inputs are valid. - * This method responds to the OnClick event of the "create" button. - * @param mixed event sender - * @param mixed event parameter - */ - public function createButtonClicked($sender,$param) - { - if($this->IsValid) // when all validations succeed - { - // populates a UserRecord object with user inputs - $userRecord=new UserRecord; - $userRecord->username=$this->Username->Text; - $userRecord->password=$this->Password->Text; - $userRecord->email=$this->Email->Text; - $userRecord->role=(int)$this->Role->SelectedValue; - $userRecord->first_name=$this->FirstName->Text; - $userRecord->last_name=$this->LastName->Text; - - // saves to the database via Active Record mechanism - $userRecord->save(); - - // redirects the browser to the homepage - $this->Response->redirect($this->Service->DefaultPageUrl); - } - } -} - +IsValid=UserRecord::finder()->findByPk($this->Username->Text)===null; + } + + /** + * Creates a new user account if all inputs are valid. + * This method responds to the OnClick event of the "create" button. + * @param mixed event sender + * @param mixed event parameter + */ + public function createButtonClicked($sender,$param) + { + if($this->IsValid) // when all validations succeed + { + // populates a UserRecord object with user inputs + $userRecord=new UserRecord; + $userRecord->username=$this->Username->Text; + $userRecord->password=$this->Password->Text; + $userRecord->email=$this->Email->Text; + $userRecord->role=(int)$this->Role->SelectedValue; + $userRecord->first_name=$this->FirstName->Text; + $userRecord->last_name=$this->LastName->Text; + + // saves to the database via Active Record mechanism + $userRecord->save(); + + // redirects the browser to the homepage + $this->Response->redirect($this->Service->DefaultPageUrl); + } + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/index.php b/demos/blog-tutorial/samples/day5/blog/index.php index 7ccffe49..bffafde2 100644 --- a/demos/blog-tutorial/samples/day5/blog/index.php +++ b/demos/blog-tutorial/samples/day5/blog/index.php @@ -1,22 +1,22 @@ -run(); - +run(); + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/protected/BlogErrorHandler.php b/demos/blog-tutorial/samples/day5/blog/protected/BlogErrorHandler.php index 56b71f8a..e8908ba7 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/BlogErrorHandler.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/BlogErrorHandler.php @@ -1,40 +1,40 @@ -getErrorMessage(),TLogger::ERROR,'BlogApplication'); - // call parent implementation to display the error - parent::handleExternalError($statusCode,$exception); - } -} - +getErrorMessage(),TLogger::ERROR,'BlogApplication'); + // call parent implementation to display the error + parent::handleExternalError($statusCode,$exception); + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/protected/BlogException.php b/demos/blog-tutorial/samples/day5/blog/protected/BlogException.php index fd17fc84..946a1bfe 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/BlogException.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/BlogException.php @@ -1,7 +1,7 @@ - \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/protected/BlogUser.php b/demos/blog-tutorial/samples/day5/blog/protected/BlogUser.php index 6b9e0a23..4f094a0c 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/BlogUser.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/BlogUser.php @@ -1,59 +1,59 @@ -findByPk($username); - if($userRecord instanceof UserRecord) // if found - { - $user=new BlogUser($this->Manager); - $user->Name=$username; // set username - $user->Roles=($userRecord->role==1?'admin':'user'); // set role - $user->IsGuest=false; // the user is not a guest - return $user; - } - else - return null; - } - - /** - * Checks if the specified (username, password) is valid. - * This method is required by TDbUser. - * @param string username - * @param string password - * @return boolean whether the username and password are valid. - */ - public function validateUser($username,$password) - { - // use UserRecord Active Record to look for the (username, password) pair. - return UserRecord::finder()->findBy_username_AND_password($username,$password)!==null; - } - - /** - * @return boolean whether this user is an administrator. - */ - public function getIsAdmin() - { - return $this->isInRole('admin'); - } -} - +findByPk($username); + if($userRecord instanceof UserRecord) // if found + { + $user=new BlogUser($this->Manager); + $user->Name=$username; // set username + $user->Roles=($userRecord->role==1?'admin':'user'); // set role + $user->IsGuest=false; // the user is not a guest + return $user; + } + else + return null; + } + + /** + * Checks if the specified (username, password) is valid. + * This method is required by TDbUser. + * @param string username + * @param string password + * @return boolean whether the username and password are valid. + */ + public function validateUser($username,$password) + { + // use UserRecord Active Record to look for the (username, password) pair. + return UserRecord::finder()->findBy_username_AND_password($username,$password)!==null; + } + + /** + * @return boolean whether this user is an administrator. + */ + public function getIsAdmin() + { + return $this->isInRole('admin'); + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/protected/database/PostRecord.php b/demos/blog-tutorial/samples/day5/blog/protected/database/PostRecord.php index 25702727..3407c09b 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/database/PostRecord.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/database/PostRecord.php @@ -1,28 +1,28 @@ - array(self::BELONGS_TO, 'UserRecord'), - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} + array(self::BELONGS_TO, 'UserRecord'), + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/protected/database/UserRecord.php b/demos/blog-tutorial/samples/day5/blog/protected/database/UserRecord.php index 2051e5de..021f8b09 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/database/UserRecord.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/database/UserRecord.php @@ -1,28 +1,28 @@ - array(self::HAS_MANY, 'PostRecord'), - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} + array(self::HAS_MANY, 'PostRecord'), + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/protected/layouts/MainLayout.php b/demos/blog-tutorial/samples/day5/blog/protected/layouts/MainLayout.php index 46c1483d..f605f75c 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/layouts/MainLayout.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/layouts/MainLayout.php @@ -1,19 +1,19 @@ -Application->getModule('auth')->logout(); - $url=$this->Service->constructUrl($this->Service->DefaultPage); - $this->Response->redirect($url); - } -} - +Application->getModule('auth')->logout(); + $url=$this->Service->constructUrl($this->Service->DefaultPage); + $this->Response->redirect($url); + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/Contact.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/Contact.php index b6ce575e..77d7374a 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/pages/Contact.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/Contact.php @@ -1,30 +1,30 @@ -IsValid) // check if input validation is successful - { - // obtain the user name, email, feedback from the textboxes - $name = $this->Name->Text; - $email = $this->Email->Text; - $feedback = $this->Feedback->Text; - - // send an email to administrator with the above information - $this->mailFeedback($name, $email, $feedback); - } - } - - protected function mailFeedback($name, $email, $feedback) - { - // implementation of sending the feedback email - } -} - +IsValid) // check if input validation is successful + { + // obtain the user name, email, feedback from the textboxes + $name = $this->Name->Text; + $email = $this->Email->Text; + $feedback = $this->Feedback->Text; + + // send an email to administrator with the above information + $this->mailFeedback($name, $email, $feedback); + } + } + + protected function mailFeedback($name, $email, $feedback) + { + // implementation of sending the feedback email + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/EditPost.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/EditPost.php index e137b85e..1b0f82b6 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/EditPost.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/EditPost.php @@ -1,72 +1,72 @@ -getPost(); - $postRecord=$this->Post; - // Authorization check: only the author or the administrator can edit the post - if($postRecord->author_id!==$this->User->Name && !$this->User->IsAdmin) - throw new THttpException(500,'You are not allowed to edit this post.'); - - if(!$this->IsPostBack) // if the page is initially requested - { - // Populates the input controls with the existing post data - $this->TitleEdit->Text=$postRecord->title; - $this->ContentEdit->Text=$postRecord->content; - } - } - - /** - * Saves the post if all inputs are valid. - * This method responds to the OnClick event of the "Save" button. - * @param mixed event sender - * @param mixed event parameter - */ - public function saveButtonClicked($sender,$param) - { - if($this->IsValid) // when all validations succeed - { - // Retrieves the existing user data. This is equivalent to: - // $postRecord=$this->getPost(); - $postRecord=$this->Post; - - // Fetches the input data - $postRecord->title=$this->TitleEdit->SafeText; - $postRecord->content=$this->ContentEdit->SafeText; - - // saves to the database via Active Record mechanism - $postRecord->save(); - - // redirects the browser to the ReadPost page - $url=$this->Service->constructUrl('posts.ReadPost',array('id'=>$postRecord->post_id)); - $this->Response->redirect($url); - } - } - - /** - * Returns the post data to be editted. - * @return PostRecord the post data to be editted. - * @throws THttpException if the post data is not found. - */ - protected function getPost() - { - // the ID of the post to be editted is passed via GET parameter 'id' - $postID=(int)$this->Request['id']; - // use Active Record to look for the specified post ID - $postRecord=PostRecord::finder()->findByPk($postID); - if($postRecord===null) - throw new THttpException(500,'Post is not found.'); - return $postRecord; - } -} - +getPost(); + $postRecord=$this->Post; + // Authorization check: only the author or the administrator can edit the post + if($postRecord->author_id!==$this->User->Name && !$this->User->IsAdmin) + throw new THttpException(500,'You are not allowed to edit this post.'); + + if(!$this->IsPostBack) // if the page is initially requested + { + // Populates the input controls with the existing post data + $this->TitleEdit->Text=$postRecord->title; + $this->ContentEdit->Text=$postRecord->content; + } + } + + /** + * Saves the post if all inputs are valid. + * This method responds to the OnClick event of the "Save" button. + * @param mixed event sender + * @param mixed event parameter + */ + public function saveButtonClicked($sender,$param) + { + if($this->IsValid) // when all validations succeed + { + // Retrieves the existing user data. This is equivalent to: + // $postRecord=$this->getPost(); + $postRecord=$this->Post; + + // Fetches the input data + $postRecord->title=$this->TitleEdit->SafeText; + $postRecord->content=$this->ContentEdit->SafeText; + + // saves to the database via Active Record mechanism + $postRecord->save(); + + // redirects the browser to the ReadPost page + $url=$this->Service->constructUrl('posts.ReadPost',array('id'=>$postRecord->post_id)); + $this->Response->redirect($url); + } + } + + /** + * Returns the post data to be editted. + * @return PostRecord the post data to be editted. + * @throws THttpException if the post data is not found. + */ + protected function getPost() + { + // the ID of the post to be editted is passed via GET parameter 'id' + $postID=(int)$this->Request['id']; + // use Active Record to look for the specified post ID + $postRecord=PostRecord::finder()->findByPk($postID); + if($postRecord===null) + throw new THttpException(500,'Post is not found.'); + return $postRecord; + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/ListPost.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/ListPost.php index 7402dace..ae5a7eeb 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/ListPost.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/ListPost.php @@ -1,64 +1,64 @@ -IsPostBack) // if the page is requested the first time - { - // get the total number of posts available - $this->Repeater->VirtualItemCount=PostRecord::finder()->count(); - // populates post data into the repeater - $this->populateData(); - } - } - - /** - * Event handler to the OnPageIndexChanged event of the pager. - * This method is invoked when the user clicks on a page button - * and thus changes the page of posts to display. - */ - public function pageChanged($sender,$param) - { - // change the current page index to the new one - $this->Repeater->CurrentPageIndex=$param->NewPageIndex; - // re-populate data into the repeater - $this->populateData(); - } - - /** - * Determines which page of posts to be displayed and - * populates the repeater with the fetched data. - */ - protected function populateData() - { - $offset=$this->Repeater->CurrentPageIndex*$this->Repeater->PageSize; - $limit=$this->Repeater->PageSize; - if($offset+$limit>$this->Repeater->VirtualItemCount) - $limit=$this->Repeater->VirtualItemCount-$offset; - $this->Repeater->DataSource=$this->getPosts($offset,$limit); - $this->Repeater->dataBind(); - } - - /** - * Fetches posts from database with offset and limit. - */ - protected function getPosts($offset, $limit) - { - // Construts a query criteria - $criteria=new TActiveRecordCriteria; - $criteria->OrdersBy['create_time']='desc'; - $criteria->Limit=$limit; - $criteria->Offset=$offset; - // query for the posts with the above criteria and with author information - return PostRecord::finder()->withAuthor()->findAll($criteria); - } -} - +IsPostBack) // if the page is requested the first time + { + // get the total number of posts available + $this->Repeater->VirtualItemCount=PostRecord::finder()->count(); + // populates post data into the repeater + $this->populateData(); + } + } + + /** + * Event handler to the OnPageIndexChanged event of the pager. + * This method is invoked when the user clicks on a page button + * and thus changes the page of posts to display. + */ + public function pageChanged($sender,$param) + { + // change the current page index to the new one + $this->Repeater->CurrentPageIndex=$param->NewPageIndex; + // re-populate data into the repeater + $this->populateData(); + } + + /** + * Determines which page of posts to be displayed and + * populates the repeater with the fetched data. + */ + protected function populateData() + { + $offset=$this->Repeater->CurrentPageIndex*$this->Repeater->PageSize; + $limit=$this->Repeater->PageSize; + if($offset+$limit>$this->Repeater->VirtualItemCount) + $limit=$this->Repeater->VirtualItemCount-$offset; + $this->Repeater->DataSource=$this->getPosts($offset,$limit); + $this->Repeater->dataBind(); + } + + /** + * Fetches posts from database with offset and limit. + */ + protected function getPosts($offset, $limit) + { + // Construts a query criteria + $criteria=new TActiveRecordCriteria; + $criteria->OrdersBy['create_time']='desc'; + $criteria->Limit=$limit; + $criteria->Offset=$offset; + // query for the posts with the above criteria and with author information + return PostRecord::finder()->withAuthor()->findAll($criteria); + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/NewPost.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/NewPost.php index a5e3ea4d..d3a36133 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/NewPost.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/NewPost.php @@ -1,34 +1,34 @@ -IsValid) // when all validations succeed - { - // populates a PostRecord object with user inputs - $postRecord=new PostRecord; - // using SafeText instead of Text avoids Cross Site Scripting attack - $postRecord->title=$this->TitleEdit->SafeText; - $postRecord->content=$this->ContentEdit->SafeText; - $postRecord->author_id=$this->User->Name; - $postRecord->create_time=time(); - $postRecord->status=0; - - // saves to the database via Active Record mechanism - $postRecord->save(); - - // redirects the browser to the newly created post page - $url=$this->Service->constructUrl('posts.ReadPost',array('id'=>$postRecord->post_id)); - $this->Response->redirect($url); - } - } -} - +IsValid) // when all validations succeed + { + // populates a PostRecord object with user inputs + $postRecord=new PostRecord; + // using SafeText instead of Text avoids Cross Site Scripting attack + $postRecord->title=$this->TitleEdit->SafeText; + $postRecord->content=$this->ContentEdit->SafeText; + $postRecord->author_id=$this->User->Name; + $postRecord->create_time=time(); + $postRecord->status=0; + + // saves to the database via Active Record mechanism + $postRecord->save(); + + // redirects the browser to the newly created post page + $url=$this->Service->constructUrl('posts.ReadPost',array('id'=>$postRecord->post_id)); + $this->Response->redirect($url); + } + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/PostRenderer.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/PostRenderer.php index cf0539a1..ed80f10c 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/PostRenderer.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/PostRenderer.php @@ -1,7 +1,7 @@ - \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/ReadPost.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/ReadPost.php index 0c120824..ab7429c3 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/ReadPost.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/posts/ReadPost.php @@ -1,59 +1,59 @@ -Request['id']; - // retrieves PostRecord with author information filled in - $this->_post=PostRecord::finder()->withAuthor()->findByPk($postID); - if($this->_post===null) // if post id is invalid - throw new BlogException(500,'Unable to find the specified post.'); - // set the page title as the post title - $this->Title=$this->_post->title; - } - - /** - * @return PostRecord the PostRecord currently being viewed - */ - public function getPost() - { - return $this->_post; - } - - /** - * Deletes the post currently being viewed - * This method is invoked when the user clicks on the "Delete" button - */ - public function deletePost($sender,$param) - { - // only the author or the administrator can delete a post - if(!$this->canEdit()) - throw new THttpException('You are not allowed to perform this action.'); - // delete it from DB - $this->_post->delete(); - // redirect the browser to the homepage - $this->Response->redirect($this->Service->DefaultPageUrl); - } - - /** - * @return boolean whether the current user can edit/delete the post being viewed - */ - public function canEdit() - { - // only the author or the administrator can edit/delete a post - return $this->User->Name===$this->Post->author_id || $this->User->IsAdmin; - } -} - +Request['id']; + // retrieves PostRecord with author information filled in + $this->_post=PostRecord::finder()->withAuthor()->findByPk($postID); + if($this->_post===null) // if post id is invalid + throw new BlogException(500,'Unable to find the specified post.'); + // set the page title as the post title + $this->Title=$this->_post->title; + } + + /** + * @return PostRecord the PostRecord currently being viewed + */ + public function getPost() + { + return $this->_post; + } + + /** + * Deletes the post currently being viewed + * This method is invoked when the user clicks on the "Delete" button + */ + public function deletePost($sender,$param) + { + // only the author or the administrator can delete a post + if(!$this->canEdit()) + throw new THttpException('You are not allowed to perform this action.'); + // delete it from DB + $this->_post->delete(); + // redirect the browser to the homepage + $this->Response->redirect($this->Service->DefaultPageUrl); + } + + /** + * @return boolean whether the current user can edit/delete the post being viewed + */ + public function canEdit() + { + // only the author or the administrator can edit/delete a post + return $this->User->Name===$this->Post->author_id || $this->User->IsAdmin; + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/users/AdminUser.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/AdminUser.php index ad8f6e3d..ad668e1a 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/pages/users/AdminUser.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/AdminUser.php @@ -1,36 +1,36 @@ -UserGrid->DataSource=UserRecord::finder()->findAll(); - // binds the data to interface components - $this->UserGrid->dataBind(); - } - - /** - * Deletes a specified user record. - * This method responds to the datagrid's OnDeleteCommand event. - * @param TDataGrid the event sender - * @param TDataGridCommandEventParameter the event parameter - */ - public function deleteButtonClicked($sender,$param) - { - // obtains the datagrid item that contains the clicked delete button - $item=$param->Item; - // obtains the primary key corresponding to the datagrid item - $username=$this->UserGrid->DataKeys[$item->ItemIndex]; - // deletes the user record with the specified username primary key - UserRecord::finder()->deleteByPk($username); - } -} - +UserGrid->DataSource=UserRecord::finder()->findAll(); + // binds the data to interface components + $this->UserGrid->dataBind(); + } + + /** + * Deletes a specified user record. + * This method responds to the datagrid's OnDeleteCommand event. + * @param TDataGrid the event sender + * @param TDataGridCommandEventParameter the event parameter + */ + public function deleteButtonClicked($sender,$param) + { + // obtains the datagrid item that contains the clicked delete button + $item=$param->Item; + // obtains the primary key corresponding to the datagrid item + $username=$this->UserGrid->DataKeys[$item->ItemIndex]; + // deletes the user record with the specified username primary key + UserRecord::finder()->deleteByPk($username); + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/users/EditUser.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/EditUser.php index 81538c33..f8c61463 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/pages/users/EditUser.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/EditUser.php @@ -1,83 +1,83 @@ -IsPostBack) // if the page is initially requested - { - // Retrieves the existing user data. This is equivalent to: - // $userRecord=$this->getUserRecord(); - $userRecord=$this->UserRecord; - - // Populates the input controls with the existing user data - $this->Username->Text=$userRecord->username; - $this->Email->Text=$userRecord->email; - $this->Role->SelectedValue=$userRecord->role; - $this->FirstName->Text=$userRecord->first_name; - $this->LastName->Text=$userRecord->last_name; - } - } - - /** - * Saves the user account if all inputs are valid. - * This method responds to the OnClick event of the "save" button. - * @param mixed event sender - * @param mixed event parameter - */ - public function saveButtonClicked($sender,$param) - { - if($this->IsValid) // when all validations succeed - { - // Retrieves the existing user data. This is equivalent to: - $userRecord=$this->UserRecord; - - // Fetches the input data - $userRecord->username=$this->Username->Text; - // update password when the input is not empty - if(!empty($this->Password->Text)) - $userRecord->password=$this->Password->Text; - $userRecord->email=$this->Email->Text; - // update the role if the current user is an administrator - if($this->User->IsAdmin) - $userRecord->role=(int)$this->Role->SelectedValue; - $userRecord->first_name=$this->FirstName->Text; - $userRecord->last_name=$this->LastName->Text; - - // saves to the database via Active Record mechanism - $userRecord->save(); - - // redirects the browser to the homepage - $this->Response->redirect($this->Service->DefaultPageUrl); - } - } - - /** - * Returns the user data to be editted. - * @return UserRecord the user data to be editted. - * @throws THttpException if the user data is not found. - */ - protected function getUserRecord() - { - // the user to be editted is the currently logged-in user - $username=$this->User->Name; - // if the 'username' GET var is not empty and the current user - // is an administrator, we use the GET var value instead. - if($this->User->IsAdmin && $this->Request['username']!==null) - $username=$this->Request['username']; - - // use Active Record to look for the specified username - $userRecord=UserRecord::finder()->findByPk($username); - if(!($userRecord instanceof UserRecord)) - throw new THttpException(500,'Username is invalid.'); - return $userRecord; - } -} - +IsPostBack) // if the page is initially requested + { + // Retrieves the existing user data. This is equivalent to: + // $userRecord=$this->getUserRecord(); + $userRecord=$this->UserRecord; + + // Populates the input controls with the existing user data + $this->Username->Text=$userRecord->username; + $this->Email->Text=$userRecord->email; + $this->Role->SelectedValue=$userRecord->role; + $this->FirstName->Text=$userRecord->first_name; + $this->LastName->Text=$userRecord->last_name; + } + } + + /** + * Saves the user account if all inputs are valid. + * This method responds to the OnClick event of the "save" button. + * @param mixed event sender + * @param mixed event parameter + */ + public function saveButtonClicked($sender,$param) + { + if($this->IsValid) // when all validations succeed + { + // Retrieves the existing user data. This is equivalent to: + $userRecord=$this->UserRecord; + + // Fetches the input data + $userRecord->username=$this->Username->Text; + // update password when the input is not empty + if(!empty($this->Password->Text)) + $userRecord->password=$this->Password->Text; + $userRecord->email=$this->Email->Text; + // update the role if the current user is an administrator + if($this->User->IsAdmin) + $userRecord->role=(int)$this->Role->SelectedValue; + $userRecord->first_name=$this->FirstName->Text; + $userRecord->last_name=$this->LastName->Text; + + // saves to the database via Active Record mechanism + $userRecord->save(); + + // redirects the browser to the homepage + $this->Response->redirect($this->Service->DefaultPageUrl); + } + } + + /** + * Returns the user data to be editted. + * @return UserRecord the user data to be editted. + * @throws THttpException if the user data is not found. + */ + protected function getUserRecord() + { + // the user to be editted is the currently logged-in user + $username=$this->User->Name; + // if the 'username' GET var is not empty and the current user + // is an administrator, we use the GET var value instead. + if($this->User->IsAdmin && $this->Request['username']!==null) + $username=$this->Request['username']; + + // use Active Record to look for the specified username + $userRecord=UserRecord::finder()->findByPk($username); + if(!($userRecord instanceof UserRecord)) + throw new THttpException(500,'Username is invalid.'); + return $userRecord; + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/users/LoginUser.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/LoginUser.php index a0955490..407906ae 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/pages/users/LoginUser.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/LoginUser.php @@ -1,37 +1,37 @@ -Application->getModule('auth'); - if(!$authManager->login($this->Username->Text,$this->Password->Text)) - $param->IsValid=false; // tell the validator that validation fails - } - - /** - * Redirects the user's browser to appropriate URL if login succeeds. - * This method responds to the login button's OnClick event. - * @param mixed event sender - * @param mixed event parameter - */ - public function loginButtonClicked($sender,$param) - { - if($this->Page->IsValid) // all validations succeed - { - // obtain the URL of the privileged page that the user wanted to visit originally - $url=$this->Application->getModule('auth')->ReturnUrl; - if(empty($url)) // the user accesses the login page directly - $url=$this->Service->DefaultPageUrl; - $this->Response->redirect($url); - } - } -} - +Application->getModule('auth'); + if(!$authManager->login($this->Username->Text,$this->Password->Text)) + $param->IsValid=false; // tell the validator that validation fails + } + + /** + * Redirects the user's browser to appropriate URL if login succeeds. + * This method responds to the login button's OnClick event. + * @param mixed event sender + * @param mixed event parameter + */ + public function loginButtonClicked($sender,$param) + { + if($this->Page->IsValid) // all validations succeed + { + // obtain the URL of the privileged page that the user wanted to visit originally + $url=$this->Application->getModule('auth')->ReturnUrl; + if(empty($url)) // the user accesses the login page directly + $url=$this->Service->DefaultPageUrl; + $this->Response->redirect($url); + } + } +} + ?> \ No newline at end of file diff --git a/demos/blog-tutorial/samples/day5/blog/protected/pages/users/NewUser.php b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/NewUser.php index 76e8cb88..3bf6768a 100644 --- a/demos/blog-tutorial/samples/day5/blog/protected/pages/users/NewUser.php +++ b/demos/blog-tutorial/samples/day5/blog/protected/pages/users/NewUser.php @@ -1,45 +1,45 @@ -IsValid=UserRecord::finder()->findByPk($this->Username->Text)===null; - } - - /** - * Creates a new user account if all inputs are valid. - * This method responds to the OnClick event of the "create" button. - * @param mixed event sender - * @param mixed event parameter - */ - public function createButtonClicked($sender,$param) - { - if($this->IsValid) // when all validations succeed - { - // populates a UserRecord object with user inputs - $userRecord=new UserRecord; - $userRecord->username=$this->Username->Text; - $userRecord->password=$this->Password->Text; - $userRecord->email=$this->Email->Text; - $userRecord->role=(int)$this->Role->SelectedValue; - $userRecord->first_name=$this->FirstName->Text; - $userRecord->last_name=$this->LastName->Text; - - // saves to the database via Active Record mechanism - $userRecord->save(); - - // redirects the browser to the homepage - $this->Response->redirect($this->Service->DefaultPageUrl); - } - } -} - +IsValid=UserRecord::finder()->findByPk($this->Username->Text)===null; + } + + /** + * Creates a new user account if all inputs are valid. + * This method responds to the OnClick event of the "create" button. + * @param mixed event sender + * @param mixed event parameter + */ + public function createButtonClicked($sender,$param) + { + if($this->IsValid) // when all validations succeed + { + // populates a UserRecord object with user inputs + $userRecord=new UserRecord; + $userRecord->username=$this->Username->Text; + $userRecord->password=$this->Password->Text; + $userRecord->email=$this->Email->Text; + $userRecord->role=(int)$this->Role->SelectedValue; + $userRecord->first_name=$this->FirstName->Text; + $userRecord->last_name=$this->LastName->Text; + + // saves to the database via Active Record mechanism + $userRecord->save(); + + // redirects the browser to the homepage + $this->Response->redirect($this->Service->DefaultPageUrl); + } + } +} + ?> \ No newline at end of file diff --git a/demos/blog/index.php b/demos/blog/index.php index 6bec1512..269b67ed 100644 --- a/demos/blog/index.php +++ b/demos/blog/index.php @@ -1,21 +1,21 @@ -run(); - +run(); + ?> \ No newline at end of file diff --git a/demos/blog/protected/Common/BlogDataModule.php b/demos/blog/protected/Common/BlogDataModule.php index 26dfc5cf..a071ba9a 100644 --- a/demos/blog/protected/Common/BlogDataModule.php +++ b/demos/blog/protected/Common/BlogDataModule.php @@ -1,708 +1,708 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * BlogDataModule class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class BlogDataModule extends TModule -{ - const DB_FILE_EXT='.db'; - const DEFAULT_DB_FILE='Application.Data.Blog'; - private $_db=null; - private $_dbFile=null; - - public function init($config) - { - $this->connectDatabase(); - } - - public function getDbFile() - { - if($this->_dbFile===null) - $this->_dbFile=Prado::getPathOfNamespace(self::DEFAULT_DB_FILE,self::DB_FILE_EXT); - return $this->_dbFile; - } - - public function setDbFile($value) - { - if(($this->_dbFile=Prado::getPathOfNamespace($value,self::DB_FILE_EXT))===null) - throw new BlogException(500,'blogdatamodule_dbfile_invalid',$value); - } - - protected function createDatabase() - { - $schemaFile=dirname(__FILE__).'/schema.sql'; - $statements=explode(';',file_get_contents($schemaFile)); - foreach($statements as $statement) - { - if(trim($statement)!=='') - { - try { - $command=$this->_db->createCommand($statement); - $command->execute(); - } - catch(TDbException $e) - { - throw new BlogException(500,'blogdatamodule_createdatabase_failed',$e->getErrorMessage(),$statement); - } - } - } - } - - protected function connectDatabase() - { - $dbFile=$this->getDbFile(); - $newDb=!is_file($dbFile); - - try { - $this->_db=new TDbConnection("sqlite:".$dbFile); - $this->_db->Active=true; - } - catch(TDbException $e) - { - throw new BlogException(500,'blogdatamodule_dbconnect_failed',$e->getErrorMessage()); - } - - if($newDb) - $this->createDatabase(); - } - - protected function generateModifier($filter,$orderBy,$limit) - { - $modifier=''; - if($filter!=='') - $modifier=' WHERE '.$filter; - if($orderBy!=='') - $modifier.=' ORDER BY '.$orderBy; - if($limit!=='') - $modifier.=' LIMIT '.$limit; - return $modifier; - } - - public function query($sql) - { - try { - $command=$this->_db->createCommand($sql); - return $command->query(); - } - catch(TDbException $e) - { - throw new BlogException(500,'blogdatamodule_query_failed',$e->getErrorMessage(),$sql); - } - } - - protected function populateUserRecord($row) - { - $userRecord=new UserRecord; - $userRecord->ID=(integer)$row['id']; - $userRecord->Name=$row['name']; - $userRecord->FullName=$row['full_name']; - $userRecord->Role=(integer)$row['role']; - $userRecord->Password=$row['passwd']; - $userRecord->VerifyCode=$row['vcode']; - $userRecord->Email=$row['email']; - $userRecord->CreateTime=(integer)$row['reg_time']; - $userRecord->Status=(integer)$row['status']; - $userRecord->Website=$row['website']; - return $userRecord; - } - - public function queryUsers($filter='',$orderBy='',$limit='') - { - if($filter!=='') - $filter='WHERE '.$filter; - $sql="SELECT * FROM tblUsers $filter $orderBy $limit"; - $rows=$this->query($sql); - $users=array(); - foreach($rows as $row) - $users[]=$this->populateUserRecord($row); - return $users; - } - - public function queryUserCount($filter) - { - if($filter!=='') - $filter='WHERE '.$filter; - $sql="SELECT COUNT(id) AS user_count FROM tblUsers $filter"; - $result=$this->query($sql); - if(($row=$result->read())!==false) - return $row['user_count']; - else - return 0; - } - - public function queryUserByID($id) - { - $sql="SELECT * FROM tblUsers WHERE id=$id"; - $result=$this->query($sql); - if(($row=$result->read())!==false) - return $this->populateUserRecord($row); - else - return null; - } - - public function queryUserByName($name) - { - $command=$this->_db->createCommand("SELECT * FROM tblUsers WHERE name=?"); - $command->bindValue(1, $name); - - $result=$command->query(); - - if(($row=$result->read())!==false) - return $this->populateUserRecord($row); - else - return null; - } - - public function insertUser($user) - { - $command=$this->_db->createCommand("INSERT INTO tblUsers ". - "(name,full_name,role,passwd,email,reg_time,status,website) ". - "VALUES (?,?,?,?,?,?,?,?)"); - $command->bindValue(1, $user->Name); - $command->bindValue(2, $user->FullName); - $command->bindValue(3, $user->Role); - $command->bindValue(4, $user->Password); - $command->bindValue(5, $user->Email); - $command->bindValue(6, time()); - $command->bindValue(7, $user->Status); - $command->bindValue(8, $user->Website); - $command->execute(); - - $user->ID=$this->_db->getLastInsertID(); - } - - public function updateUser($user) - { - $command=$this->_db->createCommand("UPDATE tblUsers SET - name=?, - full_name=?, - role=?, - passwd=?, - vcode=?, - email=?, - status=?, - website=? - WHERE id=?"); - $command->bindValue(1, $user->Name); - $command->bindValue(2, $user->FullName); - $command->bindValue(3, $user->Role); - $command->bindValue(4, $user->Password); - $command->bindValue(5, $user->VerifyCode); - $command->bindValue(6, $user->Email); - $command->bindValue(7, $user->Status); - $command->bindValue(8, $user->Website); - $command->bindValue(9, $user->ID); - $command->execute(); - } - - public function deleteUser($id) - { - $command=$this->_db->createCommand("DELETE FROM tblUsers WHERE id=?"); - $command->bindValue(1, $id); - $command->execute(); - } - - protected function populatePostRecord($row) - { - $postRecord=new PostRecord; - $postRecord->ID=(integer)$row['id']; - $postRecord->AuthorID=(integer)$row['author_id']; - if($row['author_full_name']!=='') - $postRecord->AuthorName=$row['author_full_name']; - else - $postRecord->AuthorName=$row['author_name']; - $postRecord->CreateTime=(integer)$row['create_time']; - $postRecord->ModifyTime=(integer)$row['modify_time']; - $postRecord->Title=$row['title']; - $postRecord->Content=$row['content']; - $postRecord->Status=(integer)$row['status']; - $postRecord->CommentCount=(integer)$row['comment_count']; - return $postRecord; - } - - public function queryPosts($postFilter,$categoryFilter,$orderBy,$limit) - { - //FIXME this is insecure by design since it misses proper escaping - $filter=''; - if($postFilter!=='') - $filter.=" AND $postFilter"; - if($categoryFilter!=='') - $filter.=" AND a.id IN (SELECT post_id AS id FROM tblPost2Category WHERE $categoryFilter)"; - $sql="SELECT a.id AS id, - a.author_id AS author_id, - b.name AS author_name, - b.full_name AS author_full_name, - a.create_time AS create_time, - a.modify_time AS modify_time, - a.title AS title, - a.content AS content, - a.status AS status, - a.comment_count AS comment_count - FROM tblPosts a, tblUsers b - WHERE a.author_id=b.id $filter $orderBy $limit"; - $rows=$this->query($sql); - $posts=array(); - foreach($rows as $row) - $posts[]=$this->populatePostRecord($row); - return $posts; - } - - public function queryPostsSearch($keywords,$orderBy,$limit) - { - $sql="SELECT a.id AS id, - a.author_id AS author_id, - b.name AS author_name, - b.full_name AS author_full_name, - a.create_time AS create_time, - a.modify_time AS modify_time, - a.title AS title, - a.content AS content, - a.status AS status, - a.comment_count AS comment_count - FROM tblPosts a, tblUsers b - WHERE a.author_id=b.id AND a.status=0"; - - foreach($keywords as $keyword) - $sql.=" AND (content LIKE ? OR title LIKE ?)"; - - $sql.=" $orderBy $limit"; - - $command=$this->_db->createCommand($sql); - - $i=1; - foreach($keywords as $keyword) - { - $command->bindValue($i, "%".$keyword."%"); - $i++; - } - - $rows=$command->query(); - - $posts=array(); - foreach($rows as $row) - $posts[]=$this->populatePostRecord($row); - return $posts; - - } - - public function queryPostCount($postFilter,$categoryFilter) - { - //FIXME this is insecure by design since it misses proper escaping - $filter=''; - if($postFilter!=='') - $filter.=" AND $postFilter"; - if($categoryFilter!=='') - $filter.=" AND a.id IN (SELECT post_id AS id FROM tblPost2Category WHERE $categoryFilter)"; - $sql="SELECT COUNT(a.id) AS post_count - FROM tblPosts a, tblUsers b - WHERE a.author_id=b.id $filter"; - $result=$this->query($sql); - if(($row=$result->read())!==false) - return $row['post_count']; - else - return 0; - } - - public function queryPostByID($id) - { - $sql="SELECT a.id AS id, - a.author_id AS author_id, - b.name AS author_name, - b.full_name AS author_full_name, - a.create_time AS create_time, - a.modify_time AS modify_time, - a.title AS title, - a.content AS content, - a.status AS status, - a.comment_count AS comment_count - FROM tblPosts a, tblUsers b - WHERE a.id=? AND a.author_id=b.id"; - - $command=$this->_db->createCommand($sql); - $command->bindValue(1, $id); - - $result=$command->query(); - - if(($row=$result->read())!==false) - return $this->populatePostRecord($row); - else - return null; - } - - public function insertPost($post,$catIDs) - { - $command=$this->_db->createCommand("INSERT INTO tblPosts - (author_id,create_time,modify_time,title,content,status) - VALUES (?,?,?,?,?,?)"); - $command->bindValue(1, $post->AuthorID); - $command->bindValue(2, $post->CreateTime); - $command->bindValue(3, $post->ModifyTime); - $command->bindValue(4, $post->Title); - $command->bindValue(5, $post->Content); - $command->bindValue(6, $post->Status); - - $command->execute(); - $post->ID=$this->_db->getLastInsertID(); - foreach($catIDs as $catID) - $this->insertPostCategory($post->ID,$catID); - } - - public function updatePost($post,$newCatIDs=null) - { - if($newCatIDs!==null) - { - $cats=$this->queryCategoriesByPostID($post->ID); - $catIDs=array(); - foreach($cats as $cat) - $catIDs[]=$cat->ID; - $deleteIDs=array_diff($catIDs,$newCatIDs); - foreach($deleteIDs as $id) - $this->deletePostCategory($post->ID,$id); - $insertIDs=array_diff($newCatIDs,$catIDs); - foreach($insertIDs as $id) - $this->insertPostCategory($post->ID,$id); - } - - $command=$this->_db->createCommand("UPDATE tblPosts SET - modify_time=?, - title=?, - content=?, - status=? - WHERE id=?"); - $command->bindValue(1, $post->ModifyTime); - $command->bindValue(2, $post->Title); - $command->bindValue(3, $post->Content); - $command->bindValue(4, $post->Status); - $command->bindValue(5, $post->ID); - - $command->execute(); - } - - public function deletePost($id) - { - $cats=$this->queryCategoriesByPostID($id); - foreach($cats as $cat) - $this->deletePostCategory($id,$cat->ID); - - $command=$this->_db->createCommand("DELETE FROM tblComments WHERE post_id=?"); - $command->bindValue(1, $id); - $command->execute(); - - $command=$this->_db->createCommand("DELETE FROM tblPosts WHERE id=?"); - $command->bindValue(1, $id); - $command->execute(); - } - - protected function populateCommentRecord($row) - { - $commentRecord=new CommentRecord; - $commentRecord->ID=(integer)$row['id']; - $commentRecord->PostID=(integer)$row['post_id']; - $commentRecord->AuthorName=$row['author_name']; - $commentRecord->AuthorEmail=$row['author_email']; - $commentRecord->AuthorWebsite=$row['author_website']; - $commentRecord->AuthorIP=$row['author_ip']; - $commentRecord->CreateTime=(integer)$row['create_time']; - $commentRecord->Content=$row['content']; - $commentRecord->Status=(integer)$row['status']; - return $commentRecord; - } - - public function queryComments($filter,$orderBy,$limit) - { - //FIXME this is insecure by design since it misses proper escaping - if($filter!=='') - $filter='WHERE '.$filter; - $sql="SELECT * FROM tblComments $filter $orderBy $limit"; - $rows=$this->query($sql); - $comments=array(); - foreach($rows as $row) - $comments[]=$this->populateCommentRecord($row); - return $comments; - } - - public function queryCommentsByPostID($id) - { - $sql="SELECT * FROM tblComments WHERE post_id=? ORDER BY create_time DESC"; - $command=$this->_db->createCommand($sql); - $command->bindValue(1, $id); - - $rows=$command->query(); - - $comments=array(); - foreach($rows as $row) - $comments[]=$this->populateCommentRecord($row); - return $comments; - } - - public function insertComment($comment) - { - $sql="INSERT INTO tblComments - (post_id,author_name,author_email,author_website,author_ip,create_time,status,content) - VALUES (?,?,?,?,?,?,?,?)"; - $command=$this->_db->createCommand($sql); - $command->bindValue(1, $comment->PostID); - $command->bindValue(2, $comment->AuthorName); - $command->bindValue(3, $comment->AuthorEmail); - $command->bindValue(4, $comment->AuthorWebsite); - $command->bindValue(5, $comment->AuthorIP); - $command->bindValue(6, $comment->CreateTime); - $command->bindValue(7, $comment->Status); - $command->bindValue(8, $comment->Content); - - $command->execute(); - $comment->ID=$this->_db->getLastInsertID(); - $this->query("UPDATE tblPosts SET comment_count=comment_count+1 WHERE id={$comment->PostID}"); - } - - public function updateComment($comment) - { - $sql="UPDATE tblComments SET status=? WHERE id=?"; - $command=$this->_db->createCommand($sql); - $command->bindValue(1, $comment->Status); - $command->bindValue(2, $comment->ID); - - $command->execute(); - } - - public function deleteComment($id) - { - $sql="SELECT post_id FROM tblComments WHERE id=?"; - $command=$this->_db->createCommand($sql); - $command->bindValue(1, $id); - $result=$command->query(); - - if(($row=$result->read())!==false) - { - $command=$this->_db->createCommand("DELETE FROM tblComments WHERE id=?"); - $command->bindValue(1, $id); - $command->execute(); - - $command=$this->_db->createCommand("UPDATE tblPosts SET comment_count=comment_count-1 WHERE id=?"); - $command->bindValue(1, $row['post_id']); - $command->execute(); - } - } - - protected function populateCategoryRecord($row) - { - $catRecord=new CategoryRecord; - $catRecord->ID=(integer)$row['id']; - $catRecord->Name=$row['name']; - $catRecord->Description=$row['description']; - $catRecord->PostCount=$row['post_count']; - return $catRecord; - } - - public function queryCategories() - { - $sql="SELECT * FROM tblCategories ORDER BY name ASC"; - $rows=$this->query($sql); - $cats=array(); - foreach($rows as $row) - $cats[]=$this->populateCategoryRecord($row); - return $cats; - } - - public function queryCategoriesByPostID($postID) - { - $sql="SELECT a.id AS id, - a.name AS name, - a.description AS description, - a.post_count AS post_count - FROM tblCategories a, tblPost2Category b - WHERE a.id=b.category_id AND b.post_id=? ORDER BY a.name"; - - $command=$this->_db->createCommand($sql); - $command->bindValue(1, $postID); - $rows=$command->query(); - - $cats=array(); - foreach($rows as $row) - $cats[]=$this->populateCategoryRecord($row); - return $cats; - } - - public function queryCategoryByID($id) - { - $sql="SELECT * FROM tblCategories WHERE id=?"; - - $command=$this->_db->createCommand($sql); - $command->bindValue(1, $id); - $result=$command->query(); - - if(($row=$result->read())!==false) - return $this->populateCategoryRecord($row); - else - return null; - } - - public function queryCategoryByName($name) - { - $sql="SELECT * FROM tblCategories WHERE name=?"; - - $command=$this->_db->createCommand($sql); - $command->bindValue(1, $name); - $result=$command->query(); - - if(($row=$result->read())!==false) - return $this->populateCategoryRecord($row); - else - return null; - } - - public function insertCategory($category) - { - $sql="INSERT INTO tblCategories - (name,description) - VALUES (?,?)"; - - $command=$this->_db->createCommand($sql); - $command->bindValue(1, $category->Name); - $command->bindValue(2, $category->Description); - $command->execute(); - - $category->ID=$this->_db->getLastInsertID(); - } - - public function updateCategory($category) - { - $sql="UPDATE tblCategories SET name=?, description=?, post_count=? WHERE id=?"; - - $command=$this->_db->createCommand($sql); - $command->bindValue(1, $category->Name); - $command->bindValue(2, $category->Description); - $command->bindValue(3, $category->PostCount); - $command->bindValue(4, $category->ID); - - $command->execute(); - } - - public function deleteCategory($id) - { - $sql="DELETE FROM tblPost2Category WHERE category_id=?"; - $command=$this->_db->createCommand($sql); - $command->bindValue(1, $id); - $command->execute(); - - $sql="DELETE FROM tblCategories WHERE id=?"; - $command=$this->_db->createCommand($sql); - $command->bindValue(1, $id); - $command->execute(); - } - - public function insertPostCategory($postID,$categoryID) - { - $sql="INSERT INTO tblPost2Category (post_id, category_id) VALUES (?, ?)"; - $command=$this->_db->createCommand($sql); - $command->bindValue(1, $postID); - $command->bindValue(2, $categoryID); - $command->execute(); - - $sql="UPDATE tblCategories SET post_count=post_count+1 WHERE id=?"; - $command=$this->_db->createCommand($sql); - $command->bindValue(1, $categoryID); - $command->execute(); - - } - - public function deletePostCategory($postID,$categoryID) - { - $sql="DELETE FROM tblPost2Category WHERE post_id=? AND category_id=?"; - $command=$this->_db->createCommand($sql); - $command->bindValue(1, $postID); - $command->bindValue(2, $categoryID); - $result=$command->query(); - - if($result->getRowCount()>0) - { - $sql="UPDATE tblCategories SET post_count=post_count-1 WHERE id=?"; - $command=$this->_db->createCommand($sql); - $command->bindValue(1, $categoryID); - $command->execute(); - } - } - - public function queryEarliestPostTime() - { - $sql="SELECT MIN(create_time) AS create_time FROM tblPosts"; - $result=$this->query($sql); - if(($row=$result->read())!==false) - return $row['create_time']; - else - return time(); - } -} - -class UserRecord -{ - const ROLE_USER=0; - const ROLE_ADMIN=1; - const STATUS_NORMAL=0; - const STATUS_DISABLED=1; - const STATUS_PENDING=2; - public $ID; - public $Name; - public $FullName; - public $Role; - public $Password; - public $VerifyCode; - public $Email; - public $CreateTime; - public $Status; - public $Website; -} - -class PostRecord -{ - const STATUS_PUBLISHED=0; - const STATUS_DRAFT=1; - const STATUS_PENDING=2; - const STATUS_STICKY=3; - public $ID; - public $AuthorID; - public $AuthorName; - public $CreateTime; - public $ModifyTime; - public $Title; - public $Content; - public $Status; - public $CommentCount; -} - -class CommentRecord -{ - public $ID; - public $PostID; - public $AuthorName; - public $AuthorEmail; - public $AuthorWebsite; - public $AuthorIP; - public $CreateTime; - public $Status; - public $Content; -} - -class CategoryRecord -{ - public $ID; - public $Name; - public $Description; - public $PostCount; -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * BlogDataModule class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class BlogDataModule extends TModule +{ + const DB_FILE_EXT='.db'; + const DEFAULT_DB_FILE='Application.Data.Blog'; + private $_db=null; + private $_dbFile=null; + + public function init($config) + { + $this->connectDatabase(); + } + + public function getDbFile() + { + if($this->_dbFile===null) + $this->_dbFile=Prado::getPathOfNamespace(self::DEFAULT_DB_FILE,self::DB_FILE_EXT); + return $this->_dbFile; + } + + public function setDbFile($value) + { + if(($this->_dbFile=Prado::getPathOfNamespace($value,self::DB_FILE_EXT))===null) + throw new BlogException(500,'blogdatamodule_dbfile_invalid',$value); + } + + protected function createDatabase() + { + $schemaFile=dirname(__FILE__).'/schema.sql'; + $statements=explode(';',file_get_contents($schemaFile)); + foreach($statements as $statement) + { + if(trim($statement)!=='') + { + try { + $command=$this->_db->createCommand($statement); + $command->execute(); + } + catch(TDbException $e) + { + throw new BlogException(500,'blogdatamodule_createdatabase_failed',$e->getErrorMessage(),$statement); + } + } + } + } + + protected function connectDatabase() + { + $dbFile=$this->getDbFile(); + $newDb=!is_file($dbFile); + + try { + $this->_db=new TDbConnection("sqlite:".$dbFile); + $this->_db->Active=true; + } + catch(TDbException $e) + { + throw new BlogException(500,'blogdatamodule_dbconnect_failed',$e->getErrorMessage()); + } + + if($newDb) + $this->createDatabase(); + } + + protected function generateModifier($filter,$orderBy,$limit) + { + $modifier=''; + if($filter!=='') + $modifier=' WHERE '.$filter; + if($orderBy!=='') + $modifier.=' ORDER BY '.$orderBy; + if($limit!=='') + $modifier.=' LIMIT '.$limit; + return $modifier; + } + + public function query($sql) + { + try { + $command=$this->_db->createCommand($sql); + return $command->query(); + } + catch(TDbException $e) + { + throw new BlogException(500,'blogdatamodule_query_failed',$e->getErrorMessage(),$sql); + } + } + + protected function populateUserRecord($row) + { + $userRecord=new UserRecord; + $userRecord->ID=(integer)$row['id']; + $userRecord->Name=$row['name']; + $userRecord->FullName=$row['full_name']; + $userRecord->Role=(integer)$row['role']; + $userRecord->Password=$row['passwd']; + $userRecord->VerifyCode=$row['vcode']; + $userRecord->Email=$row['email']; + $userRecord->CreateTime=(integer)$row['reg_time']; + $userRecord->Status=(integer)$row['status']; + $userRecord->Website=$row['website']; + return $userRecord; + } + + public function queryUsers($filter='',$orderBy='',$limit='') + { + if($filter!=='') + $filter='WHERE '.$filter; + $sql="SELECT * FROM tblUsers $filter $orderBy $limit"; + $rows=$this->query($sql); + $users=array(); + foreach($rows as $row) + $users[]=$this->populateUserRecord($row); + return $users; + } + + public function queryUserCount($filter) + { + if($filter!=='') + $filter='WHERE '.$filter; + $sql="SELECT COUNT(id) AS user_count FROM tblUsers $filter"; + $result=$this->query($sql); + if(($row=$result->read())!==false) + return $row['user_count']; + else + return 0; + } + + public function queryUserByID($id) + { + $sql="SELECT * FROM tblUsers WHERE id=$id"; + $result=$this->query($sql); + if(($row=$result->read())!==false) + return $this->populateUserRecord($row); + else + return null; + } + + public function queryUserByName($name) + { + $command=$this->_db->createCommand("SELECT * FROM tblUsers WHERE name=?"); + $command->bindValue(1, $name); + + $result=$command->query(); + + if(($row=$result->read())!==false) + return $this->populateUserRecord($row); + else + return null; + } + + public function insertUser($user) + { + $command=$this->_db->createCommand("INSERT INTO tblUsers ". + "(name,full_name,role,passwd,email,reg_time,status,website) ". + "VALUES (?,?,?,?,?,?,?,?)"); + $command->bindValue(1, $user->Name); + $command->bindValue(2, $user->FullName); + $command->bindValue(3, $user->Role); + $command->bindValue(4, $user->Password); + $command->bindValue(5, $user->Email); + $command->bindValue(6, time()); + $command->bindValue(7, $user->Status); + $command->bindValue(8, $user->Website); + $command->execute(); + + $user->ID=$this->_db->getLastInsertID(); + } + + public function updateUser($user) + { + $command=$this->_db->createCommand("UPDATE tblUsers SET + name=?, + full_name=?, + role=?, + passwd=?, + vcode=?, + email=?, + status=?, + website=? + WHERE id=?"); + $command->bindValue(1, $user->Name); + $command->bindValue(2, $user->FullName); + $command->bindValue(3, $user->Role); + $command->bindValue(4, $user->Password); + $command->bindValue(5, $user->VerifyCode); + $command->bindValue(6, $user->Email); + $command->bindValue(7, $user->Status); + $command->bindValue(8, $user->Website); + $command->bindValue(9, $user->ID); + $command->execute(); + } + + public function deleteUser($id) + { + $command=$this->_db->createCommand("DELETE FROM tblUsers WHERE id=?"); + $command->bindValue(1, $id); + $command->execute(); + } + + protected function populatePostRecord($row) + { + $postRecord=new PostRecord; + $postRecord->ID=(integer)$row['id']; + $postRecord->AuthorID=(integer)$row['author_id']; + if($row['author_full_name']!=='') + $postRecord->AuthorName=$row['author_full_name']; + else + $postRecord->AuthorName=$row['author_name']; + $postRecord->CreateTime=(integer)$row['create_time']; + $postRecord->ModifyTime=(integer)$row['modify_time']; + $postRecord->Title=$row['title']; + $postRecord->Content=$row['content']; + $postRecord->Status=(integer)$row['status']; + $postRecord->CommentCount=(integer)$row['comment_count']; + return $postRecord; + } + + public function queryPosts($postFilter,$categoryFilter,$orderBy,$limit) + { + //FIXME this is insecure by design since it misses proper escaping + $filter=''; + if($postFilter!=='') + $filter.=" AND $postFilter"; + if($categoryFilter!=='') + $filter.=" AND a.id IN (SELECT post_id AS id FROM tblPost2Category WHERE $categoryFilter)"; + $sql="SELECT a.id AS id, + a.author_id AS author_id, + b.name AS author_name, + b.full_name AS author_full_name, + a.create_time AS create_time, + a.modify_time AS modify_time, + a.title AS title, + a.content AS content, + a.status AS status, + a.comment_count AS comment_count + FROM tblPosts a, tblUsers b + WHERE a.author_id=b.id $filter $orderBy $limit"; + $rows=$this->query($sql); + $posts=array(); + foreach($rows as $row) + $posts[]=$this->populatePostRecord($row); + return $posts; + } + + public function queryPostsSearch($keywords,$orderBy,$limit) + { + $sql="SELECT a.id AS id, + a.author_id AS author_id, + b.name AS author_name, + b.full_name AS author_full_name, + a.create_time AS create_time, + a.modify_time AS modify_time, + a.title AS title, + a.content AS content, + a.status AS status, + a.comment_count AS comment_count + FROM tblPosts a, tblUsers b + WHERE a.author_id=b.id AND a.status=0"; + + foreach($keywords as $keyword) + $sql.=" AND (content LIKE ? OR title LIKE ?)"; + + $sql.=" $orderBy $limit"; + + $command=$this->_db->createCommand($sql); + + $i=1; + foreach($keywords as $keyword) + { + $command->bindValue($i, "%".$keyword."%"); + $i++; + } + + $rows=$command->query(); + + $posts=array(); + foreach($rows as $row) + $posts[]=$this->populatePostRecord($row); + return $posts; + + } + + public function queryPostCount($postFilter,$categoryFilter) + { + //FIXME this is insecure by design since it misses proper escaping + $filter=''; + if($postFilter!=='') + $filter.=" AND $postFilter"; + if($categoryFilter!=='') + $filter.=" AND a.id IN (SELECT post_id AS id FROM tblPost2Category WHERE $categoryFilter)"; + $sql="SELECT COUNT(a.id) AS post_count + FROM tblPosts a, tblUsers b + WHERE a.author_id=b.id $filter"; + $result=$this->query($sql); + if(($row=$result->read())!==false) + return $row['post_count']; + else + return 0; + } + + public function queryPostByID($id) + { + $sql="SELECT a.id AS id, + a.author_id AS author_id, + b.name AS author_name, + b.full_name AS author_full_name, + a.create_time AS create_time, + a.modify_time AS modify_time, + a.title AS title, + a.content AS content, + a.status AS status, + a.comment_count AS comment_count + FROM tblPosts a, tblUsers b + WHERE a.id=? AND a.author_id=b.id"; + + $command=$this->_db->createCommand($sql); + $command->bindValue(1, $id); + + $result=$command->query(); + + if(($row=$result->read())!==false) + return $this->populatePostRecord($row); + else + return null; + } + + public function insertPost($post,$catIDs) + { + $command=$this->_db->createCommand("INSERT INTO tblPosts + (author_id,create_time,modify_time,title,content,status) + VALUES (?,?,?,?,?,?)"); + $command->bindValue(1, $post->AuthorID); + $command->bindValue(2, $post->CreateTime); + $command->bindValue(3, $post->ModifyTime); + $command->bindValue(4, $post->Title); + $command->bindValue(5, $post->Content); + $command->bindValue(6, $post->Status); + + $command->execute(); + $post->ID=$this->_db->getLastInsertID(); + foreach($catIDs as $catID) + $this->insertPostCategory($post->ID,$catID); + } + + public function updatePost($post,$newCatIDs=null) + { + if($newCatIDs!==null) + { + $cats=$this->queryCategoriesByPostID($post->ID); + $catIDs=array(); + foreach($cats as $cat) + $catIDs[]=$cat->ID; + $deleteIDs=array_diff($catIDs,$newCatIDs); + foreach($deleteIDs as $id) + $this->deletePostCategory($post->ID,$id); + $insertIDs=array_diff($newCatIDs,$catIDs); + foreach($insertIDs as $id) + $this->insertPostCategory($post->ID,$id); + } + + $command=$this->_db->createCommand("UPDATE tblPosts SET + modify_time=?, + title=?, + content=?, + status=? + WHERE id=?"); + $command->bindValue(1, $post->ModifyTime); + $command->bindValue(2, $post->Title); + $command->bindValue(3, $post->Content); + $command->bindValue(4, $post->Status); + $command->bindValue(5, $post->ID); + + $command->execute(); + } + + public function deletePost($id) + { + $cats=$this->queryCategoriesByPostID($id); + foreach($cats as $cat) + $this->deletePostCategory($id,$cat->ID); + + $command=$this->_db->createCommand("DELETE FROM tblComments WHERE post_id=?"); + $command->bindValue(1, $id); + $command->execute(); + + $command=$this->_db->createCommand("DELETE FROM tblPosts WHERE id=?"); + $command->bindValue(1, $id); + $command->execute(); + } + + protected function populateCommentRecord($row) + { + $commentRecord=new CommentRecord; + $commentRecord->ID=(integer)$row['id']; + $commentRecord->PostID=(integer)$row['post_id']; + $commentRecord->AuthorName=$row['author_name']; + $commentRecord->AuthorEmail=$row['author_email']; + $commentRecord->AuthorWebsite=$row['author_website']; + $commentRecord->AuthorIP=$row['author_ip']; + $commentRecord->CreateTime=(integer)$row['create_time']; + $commentRecord->Content=$row['content']; + $commentRecord->Status=(integer)$row['status']; + return $commentRecord; + } + + public function queryComments($filter,$orderBy,$limit) + { + //FIXME this is insecure by design since it misses proper escaping + if($filter!=='') + $filter='WHERE '.$filter; + $sql="SELECT * FROM tblComments $filter $orderBy $limit"; + $rows=$this->query($sql); + $comments=array(); + foreach($rows as $row) + $comments[]=$this->populateCommentRecord($row); + return $comments; + } + + public function queryCommentsByPostID($id) + { + $sql="SELECT * FROM tblComments WHERE post_id=? ORDER BY create_time DESC"; + $command=$this->_db->createCommand($sql); + $command->bindValue(1, $id); + + $rows=$command->query(); + + $comments=array(); + foreach($rows as $row) + $comments[]=$this->populateCommentRecord($row); + return $comments; + } + + public function insertComment($comment) + { + $sql="INSERT INTO tblComments + (post_id,author_name,author_email,author_website,author_ip,create_time,status,content) + VALUES (?,?,?,?,?,?,?,?)"; + $command=$this->_db->createCommand($sql); + $command->bindValue(1, $comment->PostID); + $command->bindValue(2, $comment->AuthorName); + $command->bindValue(3, $comment->AuthorEmail); + $command->bindValue(4, $comment->AuthorWebsite); + $command->bindValue(5, $comment->AuthorIP); + $command->bindValue(6, $comment->CreateTime); + $command->bindValue(7, $comment->Status); + $command->bindValue(8, $comment->Content); + + $command->execute(); + $comment->ID=$this->_db->getLastInsertID(); + $this->query("UPDATE tblPosts SET comment_count=comment_count+1 WHERE id={$comment->PostID}"); + } + + public function updateComment($comment) + { + $sql="UPDATE tblComments SET status=? WHERE id=?"; + $command=$this->_db->createCommand($sql); + $command->bindValue(1, $comment->Status); + $command->bindValue(2, $comment->ID); + + $command->execute(); + } + + public function deleteComment($id) + { + $sql="SELECT post_id FROM tblComments WHERE id=?"; + $command=$this->_db->createCommand($sql); + $command->bindValue(1, $id); + $result=$command->query(); + + if(($row=$result->read())!==false) + { + $command=$this->_db->createCommand("DELETE FROM tblComments WHERE id=?"); + $command->bindValue(1, $id); + $command->execute(); + + $command=$this->_db->createCommand("UPDATE tblPosts SET comment_count=comment_count-1 WHERE id=?"); + $command->bindValue(1, $row['post_id']); + $command->execute(); + } + } + + protected function populateCategoryRecord($row) + { + $catRecord=new CategoryRecord; + $catRecord->ID=(integer)$row['id']; + $catRecord->Name=$row['name']; + $catRecord->Description=$row['description']; + $catRecord->PostCount=$row['post_count']; + return $catRecord; + } + + public function queryCategories() + { + $sql="SELECT * FROM tblCategories ORDER BY name ASC"; + $rows=$this->query($sql); + $cats=array(); + foreach($rows as $row) + $cats[]=$this->populateCategoryRecord($row); + return $cats; + } + + public function queryCategoriesByPostID($postID) + { + $sql="SELECT a.id AS id, + a.name AS name, + a.description AS description, + a.post_count AS post_count + FROM tblCategories a, tblPost2Category b + WHERE a.id=b.category_id AND b.post_id=? ORDER BY a.name"; + + $command=$this->_db->createCommand($sql); + $command->bindValue(1, $postID); + $rows=$command->query(); + + $cats=array(); + foreach($rows as $row) + $cats[]=$this->populateCategoryRecord($row); + return $cats; + } + + public function queryCategoryByID($id) + { + $sql="SELECT * FROM tblCategories WHERE id=?"; + + $command=$this->_db->createCommand($sql); + $command->bindValue(1, $id); + $result=$command->query(); + + if(($row=$result->read())!==false) + return $this->populateCategoryRecord($row); + else + return null; + } + + public function queryCategoryByName($name) + { + $sql="SELECT * FROM tblCategories WHERE name=?"; + + $command=$this->_db->createCommand($sql); + $command->bindValue(1, $name); + $result=$command->query(); + + if(($row=$result->read())!==false) + return $this->populateCategoryRecord($row); + else + return null; + } + + public function insertCategory($category) + { + $sql="INSERT INTO tblCategories + (name,description) + VALUES (?,?)"; + + $command=$this->_db->createCommand($sql); + $command->bindValue(1, $category->Name); + $command->bindValue(2, $category->Description); + $command->execute(); + + $category->ID=$this->_db->getLastInsertID(); + } + + public function updateCategory($category) + { + $sql="UPDATE tblCategories SET name=?, description=?, post_count=? WHERE id=?"; + + $command=$this->_db->createCommand($sql); + $command->bindValue(1, $category->Name); + $command->bindValue(2, $category->Description); + $command->bindValue(3, $category->PostCount); + $command->bindValue(4, $category->ID); + + $command->execute(); + } + + public function deleteCategory($id) + { + $sql="DELETE FROM tblPost2Category WHERE category_id=?"; + $command=$this->_db->createCommand($sql); + $command->bindValue(1, $id); + $command->execute(); + + $sql="DELETE FROM tblCategories WHERE id=?"; + $command=$this->_db->createCommand($sql); + $command->bindValue(1, $id); + $command->execute(); + } + + public function insertPostCategory($postID,$categoryID) + { + $sql="INSERT INTO tblPost2Category (post_id, category_id) VALUES (?, ?)"; + $command=$this->_db->createCommand($sql); + $command->bindValue(1, $postID); + $command->bindValue(2, $categoryID); + $command->execute(); + + $sql="UPDATE tblCategories SET post_count=post_count+1 WHERE id=?"; + $command=$this->_db->createCommand($sql); + $command->bindValue(1, $categoryID); + $command->execute(); + + } + + public function deletePostCategory($postID,$categoryID) + { + $sql="DELETE FROM tblPost2Category WHERE post_id=? AND category_id=?"; + $command=$this->_db->createCommand($sql); + $command->bindValue(1, $postID); + $command->bindValue(2, $categoryID); + $result=$command->query(); + + if($result->getRowCount()>0) + { + $sql="UPDATE tblCategories SET post_count=post_count-1 WHERE id=?"; + $command=$this->_db->createCommand($sql); + $command->bindValue(1, $categoryID); + $command->execute(); + } + } + + public function queryEarliestPostTime() + { + $sql="SELECT MIN(create_time) AS create_time FROM tblPosts"; + $result=$this->query($sql); + if(($row=$result->read())!==false) + return $row['create_time']; + else + return time(); + } +} + +class UserRecord +{ + const ROLE_USER=0; + const ROLE_ADMIN=1; + const STATUS_NORMAL=0; + const STATUS_DISABLED=1; + const STATUS_PENDING=2; + public $ID; + public $Name; + public $FullName; + public $Role; + public $Password; + public $VerifyCode; + public $Email; + public $CreateTime; + public $Status; + public $Website; +} + +class PostRecord +{ + const STATUS_PUBLISHED=0; + const STATUS_DRAFT=1; + const STATUS_PENDING=2; + const STATUS_STICKY=3; + public $ID; + public $AuthorID; + public $AuthorName; + public $CreateTime; + public $ModifyTime; + public $Title; + public $Content; + public $Status; + public $CommentCount; +} + +class CommentRecord +{ + public $ID; + public $PostID; + public $AuthorName; + public $AuthorEmail; + public $AuthorWebsite; + public $AuthorIP; + public $CreateTime; + public $Status; + public $Content; +} + +class CategoryRecord +{ + public $ID; + public $Name; + public $Description; + public $PostCount; +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Common/BlogErrorHandler.php b/demos/blog/protected/Common/BlogErrorHandler.php index 06042be1..f5144fff 100644 --- a/demos/blog/protected/Common/BlogErrorHandler.php +++ b/demos/blog/protected/Common/BlogErrorHandler.php @@ -1,46 +1,46 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -Prado::using('System.Exceptions.TErrorHandler'); -Prado::using('Application.Common.BlogException'); - -/** - * BlogErrorHandler class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class BlogErrorHandler extends TErrorHandler -{ - /** - * Displays error to the client user. - * THttpException and errors happened when the application is in Debug - * 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 BlogException) - { - $message=$exception->getMessage(); - Prado::log($message,TLogger::ERROR,'BlogApplication'); - $message=urldecode($this->getApplication()->getSecurityManager()->hashData($message)); - $this->Response->redirect($this->Service->constructUrl('ErrorReport',array('msg'=>$message),false)); - } - else - parent::handleExternalError($statusCode,$exception); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('System.Exceptions.TErrorHandler'); +Prado::using('Application.Common.BlogException'); + +/** + * BlogErrorHandler class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class BlogErrorHandler extends TErrorHandler +{ + /** + * Displays error to the client user. + * THttpException and errors happened when the application is in Debug + * 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 BlogException) + { + $message=$exception->getMessage(); + Prado::log($message,TLogger::ERROR,'BlogApplication'); + $message=urldecode($this->getApplication()->getSecurityManager()->hashData($message)); + $this->Response->redirect($this->Service->constructUrl('ErrorReport',array('msg'=>$message),false)); + } + else + parent::handleExternalError($statusCode,$exception); + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Common/BlogException.php b/demos/blog/protected/Common/BlogException.php index 17ae526f..e5ade8a3 100644 --- a/demos/blog/protected/Common/BlogException.php +++ b/demos/blog/protected/Common/BlogException.php @@ -1,31 +1,31 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * BlogException class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class BlogException extends THttpException -{ - /** - * @return string path to the error message file - */ - protected function getErrorMessageFile() - { - return dirname(__FILE__).'/messages.txt'; - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * BlogException class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class BlogException extends THttpException +{ + /** + * @return string path to the error message file + */ + protected function getErrorMessageFile() + { + return dirname(__FILE__).'/messages.txt'; + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Common/BlogPage.php b/demos/blog/protected/Common/BlogPage.php index aaf0c7e1..a5ac514e 100644 --- a/demos/blog/protected/Common/BlogPage.php +++ b/demos/blog/protected/Common/BlogPage.php @@ -1,49 +1,49 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * BlogPage class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class BlogPage extends TPage -{ - public function onPreInit($param) - { - parent::onPreInit($param); - $this->Theme=$this->Application->Parameters['ThemeName']; - } - - public function getDataAccess() - { - return $this->getApplication()->getModule('data'); - } - - public function gotoDefaultPage() - { - $this->gotoPage($this->Service->DefaultPage); - } - - public function gotoPage($pagePath,$getParameters=null) - { - $this->Response->redirect($this->Service->constructUrl($pagePath,$getParameters,false)); - } - - public function reportError($errorCode) - { - $this->gotoPage('ErrorReport',array('id'=>$errorCode)); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * BlogPage class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class BlogPage extends TPage +{ + public function onPreInit($param) + { + parent::onPreInit($param); + $this->Theme=$this->Application->Parameters['ThemeName']; + } + + public function getDataAccess() + { + return $this->getApplication()->getModule('data'); + } + + public function gotoDefaultPage() + { + $this->gotoPage($this->Service->DefaultPage); + } + + public function gotoPage($pagePath,$getParameters=null) + { + $this->Response->redirect($this->Service->constructUrl($pagePath,$getParameters,false)); + } + + public function reportError($errorCode) + { + $this->gotoPage('ErrorReport',array('id'=>$errorCode)); + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Common/BlogUser.php b/demos/blog/protected/Common/BlogUser.php index 865d7659..08418965 100644 --- a/demos/blog/protected/Common/BlogUser.php +++ b/demos/blog/protected/Common/BlogUser.php @@ -1,60 +1,60 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -Prado::using('System.Security.TUser'); - -/** - * BlogUser class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class BlogUser extends TUser -{ - private $_id; - - public function getID() - { - return $this->_id; - } - - public function setID($value) - { - $this->_id=$value; - } - - public function getIsAdmin() - { - return $this->isInRole('admin'); - } - - public function saveToString() - { - $a=array($this->_id,parent::saveToString()); - return serialize($a); - } - - public function loadFromString($data) - { - if(!empty($data)) - { - list($id,$str)=unserialize($data); - $this->_id=$id; - return parent::loadFromString($str); - } - else - return $this; - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('System.Security.TUser'); + +/** + * BlogUser class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class BlogUser extends TUser +{ + private $_id; + + public function getID() + { + return $this->_id; + } + + public function setID($value) + { + $this->_id=$value; + } + + public function getIsAdmin() + { + return $this->isInRole('admin'); + } + + public function saveToString() + { + $a=array($this->_id,parent::saveToString()); + return serialize($a); + } + + public function loadFromString($data) + { + if(!empty($data)) + { + list($id,$str)=unserialize($data); + $this->_id=$id; + return parent::loadFromString($str); + } + else + return $this; + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Common/BlogUserManager.php b/demos/blog/protected/Common/BlogUserManager.php index efaa7f1f..26a4427a 100644 --- a/demos/blog/protected/Common/BlogUserManager.php +++ b/demos/blog/protected/Common/BlogUserManager.php @@ -1,95 +1,95 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -Prado::using('System.Security.IUserManager'); -Prado::using('Application.Common.BlogUser'); - -/** - * BlogUserManager class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class BlogUserManager extends TModule implements IUserManager -{ - public function getGuestName() - { - return 'Guest'; - } - - /** - * 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) - return new BlogUser($this); - else - { - $username=strtolower($username); - $db=$this->Application->getModule('data'); - if(($userRecord=$db->queryUserByName($username))!==null) - { - $user=new BlogUser($this); - $user->setID($userRecord->ID); - $user->setName($username); - $user->setIsGuest(false); - $user->setRoles($userRecord->Role===UserRecord::ROLE_USER?'user':'admin'); - return $user; - } - else - return null; - } - } - - /** - * 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) - { - $db=$this->Application->getModule('data'); - if(($userRecord=$db->queryUserByName($username))!==null) - return $userRecord->Password===md5($password) && $userRecord->Status===UserRecord::STATUS_NORMAL; - else - return false; - } - - /** - * 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) - { - // do nothing since we don't support cookie-based auth in this example - } - - /** - * 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) - { - // do nothing since we don't support cookie-based auth in this example - return null; - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('System.Security.IUserManager'); +Prado::using('Application.Common.BlogUser'); + +/** + * BlogUserManager class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class BlogUserManager extends TModule implements IUserManager +{ + public function getGuestName() + { + return 'Guest'; + } + + /** + * 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) + return new BlogUser($this); + else + { + $username=strtolower($username); + $db=$this->Application->getModule('data'); + if(($userRecord=$db->queryUserByName($username))!==null) + { + $user=new BlogUser($this); + $user->setID($userRecord->ID); + $user->setName($username); + $user->setIsGuest(false); + $user->setRoles($userRecord->Role===UserRecord::ROLE_USER?'user':'admin'); + return $user; + } + else + return null; + } + } + + /** + * 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) + { + $db=$this->Application->getModule('data'); + if(($userRecord=$db->queryUserByName($username))!==null) + return $userRecord->Password===md5($password) && $userRecord->Status===UserRecord::STATUS_NORMAL; + else + return false; + } + + /** + * 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) + { + // do nothing since we don't support cookie-based auth in this example + } + + /** + * 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) + { + // do nothing since we don't support cookie-based auth in this example + return null; + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Common/XListMenu.php b/demos/blog/protected/Common/XListMenu.php index 7dadfbe4..92ab2984 100644 --- a/demos/blog/protected/Common/XListMenu.php +++ b/demos/blog/protected/Common/XListMenu.php @@ -1,127 +1,127 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -Prado::using('System.Web.UI.WebControls.TListControl'); - -/** - * XListMenu class - * - * XListMenu displays a list of hyperlinks that can be used for page menus. - * Menu items adjust their css class automatically according to the current - * page displayed. In particular, a menu item is considered as active if - * the URL it represents is for the page currently displayed. - * - * Usage of XListMenu is similar to PRADO list controls. Each list item has - * two extra properties: {@link XListMenuItem::setPagePath PagePath} and - * {@link XListMenuItem::setNavigateUrl NavigateUrl}. The former is used to - * determine if the item is active or not, while the latter specifies the - * URL for the item. If the latter is not specified, a URL to the page is - * generated automatically. - * - * In template, you may use the following tags to specify a menu: - * - * - * - * - * - * - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class XListMenu extends TListControl -{ - public function addParsedObject($object) - { - if($object instanceof XListMenuItem) - parent::addParsedObject($object); - } - - public function getActiveCssClass() - { - return $this->getViewState('ActiveCssClass',''); - } - - public function setActiveCssClass($value) - { - $this->setViewState('ActiveCssClass',$value,''); - } - - public function getInactiveCssClass() - { - return $this->getViewState('InactiveCssClass',''); - } - - public function setInactiveCssClass($value) - { - $this->setViewState('InactiveCssClass',$value,''); - } - - public function render($writer) - { - if(($activeClass=$this->getActiveCssClass())!=='') - $activeClass=' class="'.$activeClass.'"'; - if(($inactiveClass=$this->getInactiveCssClass())!=='') - $inactiveClass=' class="'.$inactiveClass.'"'; - $currentPagePath=$this->getPage()->getPagePath(); - $writer->write("
    \n"); - foreach($this->getItems() as $item) - { - $pagePath=$item->getPagePath(); - //if(strpos($currentPagePath.'.',$pagePath.'.')===0) - if($pagePath[strlen($pagePath)-1]==='*') - { - if(strpos($currentPagePath.'.',rtrim($pagePath,'*'))===0) - $cssClass=$activeClass; - else - $cssClass=$inactiveClass; - } - else - { - if($pagePath===$currentPagePath) - $cssClass=$activeClass; - else - $cssClass=$inactiveClass; - } - if(($url=$item->getNavigateUrl())==='') - $url=$this->getService()->constructUrl($pagePath); - $writer->write("
  • ".$item->getText()."
  • \n"); - } - $writer->write("
"); - } -} - -class XListMenuItem extends TListItem -{ - public function getPagePath() - { - return $this->getValue(); - } - - public function setPagePath($value) - { - $this->setValue($value); - } - - public function getNavigateUrl() - { - return $this->hasAttribute('NavigateUrl')?$this->getAttribute('NavigateUrl'):''; - } - - public function setNavigateUrl($value) - { - $this->setAttribute('NavigateUrl',$value); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('System.Web.UI.WebControls.TListControl'); + +/** + * XListMenu class + * + * XListMenu displays a list of hyperlinks that can be used for page menus. + * Menu items adjust their css class automatically according to the current + * page displayed. In particular, a menu item is considered as active if + * the URL it represents is for the page currently displayed. + * + * Usage of XListMenu is similar to PRADO list controls. Each list item has + * two extra properties: {@link XListMenuItem::setPagePath PagePath} and + * {@link XListMenuItem::setNavigateUrl NavigateUrl}. The former is used to + * determine if the item is active or not, while the latter specifies the + * URL for the item. If the latter is not specified, a URL to the page is + * generated automatically. + * + * In template, you may use the following tags to specify a menu: + * + * + * + * + * + * + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class XListMenu extends TListControl +{ + public function addParsedObject($object) + { + if($object instanceof XListMenuItem) + parent::addParsedObject($object); + } + + public function getActiveCssClass() + { + return $this->getViewState('ActiveCssClass',''); + } + + public function setActiveCssClass($value) + { + $this->setViewState('ActiveCssClass',$value,''); + } + + public function getInactiveCssClass() + { + return $this->getViewState('InactiveCssClass',''); + } + + public function setInactiveCssClass($value) + { + $this->setViewState('InactiveCssClass',$value,''); + } + + public function render($writer) + { + if(($activeClass=$this->getActiveCssClass())!=='') + $activeClass=' class="'.$activeClass.'"'; + if(($inactiveClass=$this->getInactiveCssClass())!=='') + $inactiveClass=' class="'.$inactiveClass.'"'; + $currentPagePath=$this->getPage()->getPagePath(); + $writer->write("
    \n"); + foreach($this->getItems() as $item) + { + $pagePath=$item->getPagePath(); + //if(strpos($currentPagePath.'.',$pagePath.'.')===0) + if($pagePath[strlen($pagePath)-1]==='*') + { + if(strpos($currentPagePath.'.',rtrim($pagePath,'*'))===0) + $cssClass=$activeClass; + else + $cssClass=$inactiveClass; + } + else + { + if($pagePath===$currentPagePath) + $cssClass=$activeClass; + else + $cssClass=$inactiveClass; + } + if(($url=$item->getNavigateUrl())==='') + $url=$this->getService()->constructUrl($pagePath); + $writer->write("
  • ".$item->getText()."
  • \n"); + } + $writer->write("
"); + } +} + +class XListMenuItem extends TListItem +{ + public function getPagePath() + { + return $this->getValue(); + } + + public function setPagePath($value) + { + $this->setValue($value); + } + + public function getNavigateUrl() + { + return $this->hasAttribute('NavigateUrl')?$this->getAttribute('NavigateUrl'):''; + } + + public function setNavigateUrl($value) + { + $this->setAttribute('NavigateUrl',$value); + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Layouts/MainLayout.php b/demos/blog/protected/Layouts/MainLayout.php index cfc42d50..b7956d75 100644 --- a/demos/blog/protected/Layouts/MainLayout.php +++ b/demos/blog/protected/Layouts/MainLayout.php @@ -1,24 +1,24 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * MainLayout class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class MainLayout extends TTemplateControl -{ -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * MainLayout class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class MainLayout extends TTemplateControl +{ +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Admin/AdminMenu.php b/demos/blog/protected/Pages/Admin/AdminMenu.php index a631d5b5..4687a5ce 100644 --- a/demos/blog/protected/Pages/Admin/AdminMenu.php +++ b/demos/blog/protected/Pages/Admin/AdminMenu.php @@ -1,24 +1,24 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * AdminMenu class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class AdminMenu extends TTemplateControl -{ -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * AdminMenu class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class AdminMenu extends TTemplateControl +{ +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Admin/ConfigMan.php b/demos/blog/protected/Pages/Admin/ConfigMan.php index 61516c27..c60a04e8 100644 --- a/demos/blog/protected/Pages/Admin/ConfigMan.php +++ b/demos/blog/protected/Pages/Admin/ConfigMan.php @@ -1,77 +1,77 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * ConfigMan class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class ConfigMan extends BlogPage -{ - const CONFIG_FILE='Application.Data.Settings'; - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $parameters=$this->Application->Parameters; - $this->SiteTitle->Text=$parameters['SiteTitle']; - $this->SiteSubtitle->Text=$parameters['SiteSubtitle']; - $this->SiteOwner->Text=$parameters['SiteOwner']; - $this->AdminEmail->Text=$parameters['AdminEmail']; - $this->MultipleUser->Checked=TPropertyValue::ensureBoolean($parameters['MultipleUser']); - $this->AccountApproval->Checked=TPropertyValue::ensureBoolean($parameters['AccountApproval']); - $this->PostPerPage->Text=$parameters['PostPerPage']; - $this->RecentComments->Text=$parameters['RecentComments']; - $this->PostApproval->Checked=TPropertyValue::ensureBoolean($parameters['PostApproval']); - $themes=$this->Service->ThemeManager->AvailableThemes; - $this->ThemeName->DataSource=$themes; - $this->ThemeName->dataBind(); - $this->ThemeName->SelectedValue=array_search($parameters['ThemeName'],$themes); - } - } - - public function saveButtonClicked($sender,$param) - { - $dom=new TXmlDocument; - $dom->Encoding='utf-8'; - $dom->TagName='parameters'; - $elements=$dom->Elements; - $elements[]=$this->createParameter('SiteTitle',$this->SiteTitle->Text); - $elements[]=$this->createParameter('SiteSubtitle',$this->SiteSubtitle->Text); - $elements[]=$this->createParameter('SiteOwner',$this->SiteOwner->Text); - $elements[]=$this->createParameter('AdminEmail',$this->AdminEmail->Text); - $elements[]=$this->createParameter('MultipleUser',$this->MultipleUser->Checked); - $elements[]=$this->createParameter('AccountApproval',$this->AccountApproval->Checked); - $elements[]=$this->createParameter('PostPerPage',$this->PostPerPage->Text); - $elements[]=$this->createParameter('RecentComments',$this->RecentComments->Text); - $elements[]=$this->createParameter('PostApproval',$this->PostApproval->Checked); - $themeName=$this->ThemeName->SelectedItem->Text; - $elements[]=$this->createParameter('ThemeName',$themeName); - $dom->saveToFile(Prado::getPathOfNamespace(self::CONFIG_FILE,'.xml')); - if($themeName!==$this->Theme->Name) - $this->Response->reload(); - } - - private function createParameter($id,$value) - { - $element=new TXmlElement('parameter'); - $element->Attributes['id']=$id; - $element->Attributes['value']=TPropertyValue::ensureString($value); - return $element; - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * ConfigMan class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class ConfigMan extends BlogPage +{ + const CONFIG_FILE='Application.Data.Settings'; + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $parameters=$this->Application->Parameters; + $this->SiteTitle->Text=$parameters['SiteTitle']; + $this->SiteSubtitle->Text=$parameters['SiteSubtitle']; + $this->SiteOwner->Text=$parameters['SiteOwner']; + $this->AdminEmail->Text=$parameters['AdminEmail']; + $this->MultipleUser->Checked=TPropertyValue::ensureBoolean($parameters['MultipleUser']); + $this->AccountApproval->Checked=TPropertyValue::ensureBoolean($parameters['AccountApproval']); + $this->PostPerPage->Text=$parameters['PostPerPage']; + $this->RecentComments->Text=$parameters['RecentComments']; + $this->PostApproval->Checked=TPropertyValue::ensureBoolean($parameters['PostApproval']); + $themes=$this->Service->ThemeManager->AvailableThemes; + $this->ThemeName->DataSource=$themes; + $this->ThemeName->dataBind(); + $this->ThemeName->SelectedValue=array_search($parameters['ThemeName'],$themes); + } + } + + public function saveButtonClicked($sender,$param) + { + $dom=new TXmlDocument; + $dom->Encoding='utf-8'; + $dom->TagName='parameters'; + $elements=$dom->Elements; + $elements[]=$this->createParameter('SiteTitle',$this->SiteTitle->Text); + $elements[]=$this->createParameter('SiteSubtitle',$this->SiteSubtitle->Text); + $elements[]=$this->createParameter('SiteOwner',$this->SiteOwner->Text); + $elements[]=$this->createParameter('AdminEmail',$this->AdminEmail->Text); + $elements[]=$this->createParameter('MultipleUser',$this->MultipleUser->Checked); + $elements[]=$this->createParameter('AccountApproval',$this->AccountApproval->Checked); + $elements[]=$this->createParameter('PostPerPage',$this->PostPerPage->Text); + $elements[]=$this->createParameter('RecentComments',$this->RecentComments->Text); + $elements[]=$this->createParameter('PostApproval',$this->PostApproval->Checked); + $themeName=$this->ThemeName->SelectedItem->Text; + $elements[]=$this->createParameter('ThemeName',$themeName); + $dom->saveToFile(Prado::getPathOfNamespace(self::CONFIG_FILE,'.xml')); + if($themeName!==$this->Theme->Name) + $this->Response->reload(); + } + + private function createParameter($id,$value) + { + $element=new TXmlElement('parameter'); + $element->Attributes['id']=$id; + $element->Attributes['value']=TPropertyValue::ensureString($value); + return $element; + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Admin/PostMan.php b/demos/blog/protected/Pages/Admin/PostMan.php index bf6597b1..c2ceb73f 100644 --- a/demos/blog/protected/Pages/Admin/PostMan.php +++ b/demos/blog/protected/Pages/Admin/PostMan.php @@ -1,73 +1,73 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * PostMan class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class PostMan extends BlogPage -{ - protected function bindData() - { - $offset=$this->PostGrid->CurrentPageIndex*$this->PostGrid->PageSize; - $limit=$this->PostGrid->PageSize; - $this->PostGrid->DataSource=$this->DataAccess->queryPosts('','','ORDER BY a.status DESC, modify_time DESC',"LIMIT $offset,$limit"); - $this->PostGrid->VirtualItemCount=$this->DataAccess->queryPostCount('',''); - $this->PostGrid->dataBind(); - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - $this->bindData(); - } - - public function changePage($sender,$param) - { - $this->PostGrid->CurrentPageIndex=$param->NewPageIndex; - $this->bindData(); - } - - public function pagerCreated($sender,$param) - { - $param->Pager->Controls->insertAt(0,'Page: '); - } - - public function editItem($sender,$param) - { - $this->PostGrid->EditItemIndex=$param->Item->ItemIndex; - $this->bindData(); - } - - public function saveItem($sender,$param) - { - $item=$param->Item; - $postID=$this->PostGrid->DataKeys[$item->ItemIndex]; - $postRecord=$this->DataAccess->queryPostByID($postID); - $postRecord->Status=TPropertyValue::ensureInteger($item->Cells[2]->PostStatus->SelectedValue); - $this->DataAccess->updatePost($postRecord); - $this->PostGrid->EditItemIndex=-1; - $this->bindData(); - } - - public function cancelItem($sender,$param) - { - $this->PostGrid->EditItemIndex=-1; - $this->bindData(); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * PostMan class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class PostMan extends BlogPage +{ + protected function bindData() + { + $offset=$this->PostGrid->CurrentPageIndex*$this->PostGrid->PageSize; + $limit=$this->PostGrid->PageSize; + $this->PostGrid->DataSource=$this->DataAccess->queryPosts('','','ORDER BY a.status DESC, modify_time DESC',"LIMIT $offset,$limit"); + $this->PostGrid->VirtualItemCount=$this->DataAccess->queryPostCount('',''); + $this->PostGrid->dataBind(); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + $this->bindData(); + } + + public function changePage($sender,$param) + { + $this->PostGrid->CurrentPageIndex=$param->NewPageIndex; + $this->bindData(); + } + + public function pagerCreated($sender,$param) + { + $param->Pager->Controls->insertAt(0,'Page: '); + } + + public function editItem($sender,$param) + { + $this->PostGrid->EditItemIndex=$param->Item->ItemIndex; + $this->bindData(); + } + + public function saveItem($sender,$param) + { + $item=$param->Item; + $postID=$this->PostGrid->DataKeys[$item->ItemIndex]; + $postRecord=$this->DataAccess->queryPostByID($postID); + $postRecord->Status=TPropertyValue::ensureInteger($item->Cells[2]->PostStatus->SelectedValue); + $this->DataAccess->updatePost($postRecord); + $this->PostGrid->EditItemIndex=-1; + $this->bindData(); + } + + public function cancelItem($sender,$param) + { + $this->PostGrid->EditItemIndex=-1; + $this->bindData(); + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Admin/UserMan.php b/demos/blog/protected/Pages/Admin/UserMan.php index 5901c334..231f6c84 100644 --- a/demos/blog/protected/Pages/Admin/UserMan.php +++ b/demos/blog/protected/Pages/Admin/UserMan.php @@ -1,75 +1,75 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * UserMan class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class UserMan extends BlogPage -{ - protected function bindData() - { - $author=$this->User->ID; - $offset=$this->UserGrid->CurrentPageIndex*$this->UserGrid->PageSize; - $limit=$this->UserGrid->PageSize; - $this->UserGrid->DataSource=$this->DataAccess->queryUsers('','ORDER BY status DESC, name ASC',"LIMIT $offset,$limit"); - $this->UserGrid->VirtualItemCount=$this->DataAccess->queryUserCount(''); - $this->UserGrid->dataBind(); - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - $this->bindData(); - } - - public function changePage($sender,$param) - { - $this->UserGrid->CurrentPageIndex=$param->NewPageIndex; - $this->bindData(); - } - - public function pagerCreated($sender,$param) - { - $param->Pager->Controls->insertAt(0,'Page: '); - } - - public function editItem($sender,$param) - { - $this->UserGrid->EditItemIndex=$param->Item->ItemIndex; - $this->bindData(); - } - - public function saveItem($sender,$param) - { - $item=$param->Item; - $userID=$this->UserGrid->DataKeys[$item->ItemIndex]; - $userRecord=$this->DataAccess->queryUserByID($userID); - $userRecord->Role=TPropertyValue::ensureInteger($item->Cells[1]->UserRole->SelectedValue); - $userRecord->Status=TPropertyValue::ensureInteger($item->Cells[2]->UserStatus->SelectedValue); - $this->DataAccess->updateUser($userRecord); - $this->UserGrid->EditItemIndex=-1; - $this->bindData(); - } - - public function cancelItem($sender,$param) - { - $this->UserGrid->EditItemIndex=-1; - $this->bindData(); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * UserMan class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class UserMan extends BlogPage +{ + protected function bindData() + { + $author=$this->User->ID; + $offset=$this->UserGrid->CurrentPageIndex*$this->UserGrid->PageSize; + $limit=$this->UserGrid->PageSize; + $this->UserGrid->DataSource=$this->DataAccess->queryUsers('','ORDER BY status DESC, name ASC',"LIMIT $offset,$limit"); + $this->UserGrid->VirtualItemCount=$this->DataAccess->queryUserCount(''); + $this->UserGrid->dataBind(); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + $this->bindData(); + } + + public function changePage($sender,$param) + { + $this->UserGrid->CurrentPageIndex=$param->NewPageIndex; + $this->bindData(); + } + + public function pagerCreated($sender,$param) + { + $param->Pager->Controls->insertAt(0,'Page: '); + } + + public function editItem($sender,$param) + { + $this->UserGrid->EditItemIndex=$param->Item->ItemIndex; + $this->bindData(); + } + + public function saveItem($sender,$param) + { + $item=$param->Item; + $userID=$this->UserGrid->DataKeys[$item->ItemIndex]; + $userRecord=$this->DataAccess->queryUserByID($userID); + $userRecord->Role=TPropertyValue::ensureInteger($item->Cells[1]->UserRole->SelectedValue); + $userRecord->Status=TPropertyValue::ensureInteger($item->Cells[2]->UserStatus->SelectedValue); + $this->DataAccess->updateUser($userRecord); + $this->UserGrid->EditItemIndex=-1; + $this->bindData(); + } + + public function cancelItem($sender,$param) + { + $this->UserGrid->EditItemIndex=-1; + $this->bindData(); + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/ErrorReport.php b/demos/blog/protected/Pages/ErrorReport.php index 50d4a047..2b086f5f 100644 --- a/demos/blog/protected/Pages/ErrorReport.php +++ b/demos/blog/protected/Pages/ErrorReport.php @@ -1,29 +1,29 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * ErrorReport class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class ErrorReport extends BlogPage -{ - public function onLoad($param) - { - parent::onLoad($param); - $this->ErrorMessage->Text=$this->Application->SecurityManager->validateData(urldecode($this->Request['msg'])); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * ErrorReport class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class ErrorReport extends BlogPage +{ + public function onLoad($param) + { + parent::onLoad($param); + $this->ErrorMessage->Text=$this->Application->SecurityManager->validateData(urldecode($this->Request['msg'])); + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/EditCategory.php b/demos/blog/protected/Pages/Posts/EditCategory.php index 76013264..d60418be 100644 --- a/demos/blog/protected/Pages/Posts/EditCategory.php +++ b/demos/blog/protected/Pages/Posts/EditCategory.php @@ -1,61 +1,61 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * EditCategory class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class EditCategory extends BlogPage -{ - private $_category; - - public function onInit($param) - { - parent::onInit($param); - $id=TPropertyValue::ensureInteger($this->Request['id']); - $this->_category=$this->DataAccess->queryCategoryByID($id); - if($this->_category===null) - throw new BlogException(500,'category_id_invalid',$id); - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $this->CategoryName->Text=$this->_category->Name; - $this->CategoryDescription->Text=$this->_category->Description; - } - } - - public function saveButtonClicked($sender,$param) - { - if($this->IsValid) - { - $this->_category->Name=$this->CategoryName->Text; - $this->_category->Description=$this->CategoryDescription->Text; - $this->DataAccess->updateCategory($this->_category); - $this->gotoPage('Posts.ListPost',array('cat'=>$this->_category->ID)); - } - } - - public function checkCategoryName($sender,$param) - { - $name=$this->CategoryName->Text; - $param->IsValid=$this->DataAccess->queryCategoryByName($name)===null; - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * EditCategory class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class EditCategory extends BlogPage +{ + private $_category; + + public function onInit($param) + { + parent::onInit($param); + $id=TPropertyValue::ensureInteger($this->Request['id']); + $this->_category=$this->DataAccess->queryCategoryByID($id); + if($this->_category===null) + throw new BlogException(500,'category_id_invalid',$id); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $this->CategoryName->Text=$this->_category->Name; + $this->CategoryDescription->Text=$this->_category->Description; + } + } + + public function saveButtonClicked($sender,$param) + { + if($this->IsValid) + { + $this->_category->Name=$this->CategoryName->Text; + $this->_category->Description=$this->CategoryDescription->Text; + $this->DataAccess->updateCategory($this->_category); + $this->gotoPage('Posts.ListPost',array('cat'=>$this->_category->ID)); + } + } + + public function checkCategoryName($sender,$param) + { + $name=$this->CategoryName->Text; + $param->IsValid=$this->DataAccess->queryCategoryByName($name)===null; + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/EditPost.php b/demos/blog/protected/Pages/Posts/EditPost.php index 8d754b30..3ba6f069 100644 --- a/demos/blog/protected/Pages/Posts/EditPost.php +++ b/demos/blog/protected/Pages/Posts/EditPost.php @@ -1,78 +1,78 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * EditPost class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class EditPost extends BlogPage -{ - private $_postRecord=null; - - public function onInit($param) - { - parent::onInit($param); - $id=TPropertyValue::ensureInteger($this->Request['id']); - $this->_postRecord=$this->DataAccess->queryPostByID($id); - if($this->_postRecord===null) - throw new BlogException(500,'post_id_invalid',$id); - // only the author and admin can edit the post - if(!$this->User->IsAdmin && $this->User->ID!==$this->_postRecord->AuthorID) - throw new BlogException(500,'post_edit_disallowed',$id); - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $postRecord=$this->_postRecord; - $this->Title->Text=$postRecord->Title; - $this->Content->Text=$postRecord->Content; - $this->DraftMode->Checked=$postRecord->Status===PostRecord::STATUS_DRAFT; - $this->Categories->DataSource=$this->DataAccess->queryCategories(); - $this->Categories->dataBind(); - $cats=$this->DataAccess->queryCategoriesByPostID($postRecord->ID); - $catIDs=array(); - foreach($cats as $cat) - $catIDs[]=$cat->ID; - $this->Categories->SelectedValues=$catIDs; - } - } - - public function saveButtonClicked($sender,$param) - { - if($this->IsValid) - { - $postRecord=$this->_postRecord; - $postRecord->Title=$this->Title->SafeText; - $postRecord->Content=$this->Content->SafeText; - if($this->DraftMode->Checked) - $postRecord->Status=PostRecord::STATUS_DRAFT; - else if(!$this->User->IsAdmin && TPropertyValue::ensureBoolean($this->Application->Parameters['PostApproval'])) - $postRecord->Status=PostRecord::STATUS_PENDING; - else - $postRecord->Status=PostRecord::STATUS_PUBLISHED; - $postRecord->ModifyTime=time(); - $cats=array(); - foreach($this->Categories->SelectedValues as $value) - $cats[]=TPropertyValue::ensureInteger($value); - $this->DataAccess->updatePost($postRecord,$cats); - $this->gotoPage('Posts.ViewPost',array('id'=>$postRecord->ID)); - } - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * EditPost class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class EditPost extends BlogPage +{ + private $_postRecord=null; + + public function onInit($param) + { + parent::onInit($param); + $id=TPropertyValue::ensureInteger($this->Request['id']); + $this->_postRecord=$this->DataAccess->queryPostByID($id); + if($this->_postRecord===null) + throw new BlogException(500,'post_id_invalid',$id); + // only the author and admin can edit the post + if(!$this->User->IsAdmin && $this->User->ID!==$this->_postRecord->AuthorID) + throw new BlogException(500,'post_edit_disallowed',$id); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $postRecord=$this->_postRecord; + $this->Title->Text=$postRecord->Title; + $this->Content->Text=$postRecord->Content; + $this->DraftMode->Checked=$postRecord->Status===PostRecord::STATUS_DRAFT; + $this->Categories->DataSource=$this->DataAccess->queryCategories(); + $this->Categories->dataBind(); + $cats=$this->DataAccess->queryCategoriesByPostID($postRecord->ID); + $catIDs=array(); + foreach($cats as $cat) + $catIDs[]=$cat->ID; + $this->Categories->SelectedValues=$catIDs; + } + } + + public function saveButtonClicked($sender,$param) + { + if($this->IsValid) + { + $postRecord=$this->_postRecord; + $postRecord->Title=$this->Title->SafeText; + $postRecord->Content=$this->Content->SafeText; + if($this->DraftMode->Checked) + $postRecord->Status=PostRecord::STATUS_DRAFT; + else if(!$this->User->IsAdmin && TPropertyValue::ensureBoolean($this->Application->Parameters['PostApproval'])) + $postRecord->Status=PostRecord::STATUS_PENDING; + else + $postRecord->Status=PostRecord::STATUS_PUBLISHED; + $postRecord->ModifyTime=time(); + $cats=array(); + foreach($this->Categories->SelectedValues as $value) + $cats[]=TPropertyValue::ensureInteger($value); + $this->DataAccess->updatePost($postRecord,$cats); + $this->gotoPage('Posts.ViewPost',array('id'=>$postRecord->ID)); + } + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/ListPost.php b/demos/blog/protected/Pages/Posts/ListPost.php index 0e0a044c..7ff9dac9 100644 --- a/demos/blog/protected/Pages/Posts/ListPost.php +++ b/demos/blog/protected/Pages/Posts/ListPost.php @@ -1,142 +1,142 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * ListPost class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class ListPost extends BlogPage -{ - private $_posts; - private $_category; - - public function onInit($param) - { - parent::onInit($param); - $this->_posts=$this->DataAccess->queryPosts( - $this->getPostFilter(), - $this->getCategoryFilter(), - 'ORDER BY a.status DESC, create_time DESC', - 'LIMIT '.$this->getPageOffset().','.$this->getPageSize()); - if($this->Request['cat']!==null) - { - $catID=TPropertyValue::ensureInteger($this->Request['cat']); - $this->_category=$this->DataAccess->queryCategoryByID($catID); - $this->CategoryPanel->Visible=true; - } - $this->Title=$this->Application->Parameters['SiteTitle']; - } - - private function getPageOffset() - { - if(($offset=TPropertyValue::ensureInteger($this->Request['offset']))<=0) - $offset=0; - return $offset; - } - - private function getPageSize() - { - if(($limit=TPropertyValue::ensureInteger($this->Request['limit']))<=0) - $limit=TPropertyValue::ensureInteger($this->Application->Parameters['PostPerPage']); - return $limit; - } - - private function getTimeFilter() - { - if(($time=TPropertyValue::ensureInteger($this->Request['time']))>0) - { - $year=(integer)($time/100); - $month=$time%100; - $startTime=mktime(0,0,0,$month,1,$year); - if(++$month>12) - { - $month=1; - $year++; - } - $endTime=mktime(0,0,0,$month,1,$year); - return "create_time>=$startTime AND create_time<$endTime"; - } - else - return ''; - } - - private function getPostFilter() - { - $filter='(a.status=0 OR a.status=3)'; - if(($timeFilter=$this->getTimeFilter())!=='') - return "$filter AND $timeFilter"; - else - return $filter; - } - - private function getCategoryFilter() - { - if(($catID=$this->Request['cat'])!==null) - { - $catID=TPropertyValue::ensureInteger($catID); - return "category_id=$catID"; - } - else - return ''; - } - - private function formUrl($newOffset) - { - $gets=array(); - $gets['offset']=$newOffset; - if($this->Request['limit']!==null) - $gets['limit']=$this->Request['limit']; - if($this->Request['time']!==null) - $gets['time']=$this->Request['time']; - if($this->Request['cat']!==null) - $gets['cat']=$this->Request['cat']; - return $this->Service->constructUrl('Posts.ListPost',$gets); - } - - public function getCategory() - { - return $this->_category; - } - - public function onLoad($param) - { - parent::onLoad($param); - $this->PostList->DataSource=$this->_posts; - $this->PostList->dataBind(); - if($this->getPageOffset()>0) - { - if(($offset=$this->getPageOffset()-$this->getPageSize())<0) - $offset=0; - $this->PrevPage->NavigateUrl=$this->formUrl($offset); - $this->PrevPage->Visible=true; - } - if(count($this->_posts)===$this->getPageSize()) - { - $this->NextPage->NavigateUrl=$this->formUrl($this->getPageOffset()+$this->getPageSize()); - $this->NextPage->Visible=true; - } - } - - public function deleteButtonClicked($sender,$param) - { - if($this->User->IsAdmin) - { - $this->DataAccess->deleteCategory($this->Category->ID); - $this->gotoDefaultPage(); - } - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * ListPost class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class ListPost extends BlogPage +{ + private $_posts; + private $_category; + + public function onInit($param) + { + parent::onInit($param); + $this->_posts=$this->DataAccess->queryPosts( + $this->getPostFilter(), + $this->getCategoryFilter(), + 'ORDER BY a.status DESC, create_time DESC', + 'LIMIT '.$this->getPageOffset().','.$this->getPageSize()); + if($this->Request['cat']!==null) + { + $catID=TPropertyValue::ensureInteger($this->Request['cat']); + $this->_category=$this->DataAccess->queryCategoryByID($catID); + $this->CategoryPanel->Visible=true; + } + $this->Title=$this->Application->Parameters['SiteTitle']; + } + + private function getPageOffset() + { + if(($offset=TPropertyValue::ensureInteger($this->Request['offset']))<=0) + $offset=0; + return $offset; + } + + private function getPageSize() + { + if(($limit=TPropertyValue::ensureInteger($this->Request['limit']))<=0) + $limit=TPropertyValue::ensureInteger($this->Application->Parameters['PostPerPage']); + return $limit; + } + + private function getTimeFilter() + { + if(($time=TPropertyValue::ensureInteger($this->Request['time']))>0) + { + $year=(integer)($time/100); + $month=$time%100; + $startTime=mktime(0,0,0,$month,1,$year); + if(++$month>12) + { + $month=1; + $year++; + } + $endTime=mktime(0,0,0,$month,1,$year); + return "create_time>=$startTime AND create_time<$endTime"; + } + else + return ''; + } + + private function getPostFilter() + { + $filter='(a.status=0 OR a.status=3)'; + if(($timeFilter=$this->getTimeFilter())!=='') + return "$filter AND $timeFilter"; + else + return $filter; + } + + private function getCategoryFilter() + { + if(($catID=$this->Request['cat'])!==null) + { + $catID=TPropertyValue::ensureInteger($catID); + return "category_id=$catID"; + } + else + return ''; + } + + private function formUrl($newOffset) + { + $gets=array(); + $gets['offset']=$newOffset; + if($this->Request['limit']!==null) + $gets['limit']=$this->Request['limit']; + if($this->Request['time']!==null) + $gets['time']=$this->Request['time']; + if($this->Request['cat']!==null) + $gets['cat']=$this->Request['cat']; + return $this->Service->constructUrl('Posts.ListPost',$gets); + } + + public function getCategory() + { + return $this->_category; + } + + public function onLoad($param) + { + parent::onLoad($param); + $this->PostList->DataSource=$this->_posts; + $this->PostList->dataBind(); + if($this->getPageOffset()>0) + { + if(($offset=$this->getPageOffset()-$this->getPageSize())<0) + $offset=0; + $this->PrevPage->NavigateUrl=$this->formUrl($offset); + $this->PrevPage->Visible=true; + } + if(count($this->_posts)===$this->getPageSize()) + { + $this->NextPage->NavigateUrl=$this->formUrl($this->getPageOffset()+$this->getPageSize()); + $this->NextPage->Visible=true; + } + } + + public function deleteButtonClicked($sender,$param) + { + if($this->User->IsAdmin) + { + $this->DataAccess->deleteCategory($this->Category->ID); + $this->gotoDefaultPage(); + } + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/MyPost.php b/demos/blog/protected/Pages/Posts/MyPost.php index fd65cc57..7d0be020 100644 --- a/demos/blog/protected/Pages/Posts/MyPost.php +++ b/demos/blog/protected/Pages/Posts/MyPost.php @@ -1,51 +1,51 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * MyPost class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class MyPost extends BlogPage -{ - protected function bindData() - { - $author=$this->User->ID; - $offset=$this->PostGrid->CurrentPageIndex*$this->PostGrid->PageSize; - $limit=$this->PostGrid->PageSize; - $this->PostGrid->DataSource=$this->DataAccess->queryPosts("author_id=$author",'','ORDER BY a.status DESC, create_time DESC',"LIMIT $offset,$limit"); - $this->PostGrid->VirtualItemCount=$this->DataAccess->queryPostCount("author_id=$author",''); - $this->PostGrid->dataBind(); - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - $this->bindData(); - } - - public function changePage($sender,$param) - { - $this->PostGrid->CurrentPageIndex=$param->NewPageIndex; - $this->bindData(); - } - - public function pagerCreated($sender,$param) - { - $param->Pager->Controls->insertAt(0,'Page: '); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * MyPost class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class MyPost extends BlogPage +{ + protected function bindData() + { + $author=$this->User->ID; + $offset=$this->PostGrid->CurrentPageIndex*$this->PostGrid->PageSize; + $limit=$this->PostGrid->PageSize; + $this->PostGrid->DataSource=$this->DataAccess->queryPosts("author_id=$author",'','ORDER BY a.status DESC, create_time DESC',"LIMIT $offset,$limit"); + $this->PostGrid->VirtualItemCount=$this->DataAccess->queryPostCount("author_id=$author",''); + $this->PostGrid->dataBind(); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + $this->bindData(); + } + + public function changePage($sender,$param) + { + $this->PostGrid->CurrentPageIndex=$param->NewPageIndex; + $this->bindData(); + } + + public function pagerCreated($sender,$param) + { + $param->Pager->Controls->insertAt(0,'Page: '); + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/NewCategory.php b/demos/blog/protected/Pages/Posts/NewCategory.php index 5df0c85b..b5bf26e9 100644 --- a/demos/blog/protected/Pages/Posts/NewCategory.php +++ b/demos/blog/protected/Pages/Posts/NewCategory.php @@ -1,41 +1,41 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * NewCategory class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class NewCategory extends BlogPage -{ - public function saveButtonClicked($sender,$param) - { - if($this->IsValid) - { - $categoryRecord=new CategoryRecord; - $categoryRecord->Name=$this->CategoryName->Text; - $categoryRecord->Description=$this->CategoryDescription->Text; - $this->DataAccess->insertCategory($categoryRecord); - $this->gotoPage('Posts.ListPost',array('cat'=>$categoryRecord->ID)); - } - } - - public function checkCategoryName($sender,$param) - { - $name=$this->CategoryName->Text; - $param->IsValid=$this->DataAccess->queryCategoryByName($name)===null; - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * NewCategory class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class NewCategory extends BlogPage +{ + public function saveButtonClicked($sender,$param) + { + if($this->IsValid) + { + $categoryRecord=new CategoryRecord; + $categoryRecord->Name=$this->CategoryName->Text; + $categoryRecord->Description=$this->CategoryDescription->Text; + $this->DataAccess->insertCategory($categoryRecord); + $this->gotoPage('Posts.ListPost',array('cat'=>$categoryRecord->ID)); + } + } + + public function checkCategoryName($sender,$param) + { + $name=$this->CategoryName->Text; + $param->IsValid=$this->DataAccess->queryCategoryByName($name)===null; + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/NewPost.php b/demos/blog/protected/Pages/Posts/NewPost.php index 2f894cd5..45b1a794 100644 --- a/demos/blog/protected/Pages/Posts/NewPost.php +++ b/demos/blog/protected/Pages/Posts/NewPost.php @@ -1,57 +1,57 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * NewPost class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class NewPost extends BlogPage -{ - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $this->Categories->DataSource=$this->DataAccess->queryCategories(); - $this->Categories->dataBind(); - } - } - - public function saveButtonClicked($sender,$param) - { - if($this->IsValid) - { - $postRecord=new PostRecord; - $postRecord->Title=$this->Title->SafeText; - $postRecord->Content=$this->Content->SafeText; - if($this->DraftMode->Checked) - $postRecord->Status=PostRecord::STATUS_DRAFT; - else if(!$this->User->IsAdmin && TPropertyValue::ensureBoolean($this->Application->Parameters['PostApproval'])) - $postRecord->Status=PostRecord::STATUS_PENDING; - else - $postRecord->Status=PostRecord::STATUS_PUBLISHED; - $postRecord->CreateTime=time(); - $postRecord->ModifyTime=$postRecord->CreateTime; - $postRecord->AuthorID=$this->User->ID; - $cats=array(); - foreach($this->Categories->SelectedValues as $value) - $cats[]=TPropertyValue::ensureInteger($value); - $this->DataAccess->insertPost($postRecord,$cats); - $this->gotoPage('Posts.ViewPost',array('id'=>$postRecord->ID)); - } - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * NewPost class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class NewPost extends BlogPage +{ + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $this->Categories->DataSource=$this->DataAccess->queryCategories(); + $this->Categories->dataBind(); + } + } + + public function saveButtonClicked($sender,$param) + { + if($this->IsValid) + { + $postRecord=new PostRecord; + $postRecord->Title=$this->Title->SafeText; + $postRecord->Content=$this->Content->SafeText; + if($this->DraftMode->Checked) + $postRecord->Status=PostRecord::STATUS_DRAFT; + else if(!$this->User->IsAdmin && TPropertyValue::ensureBoolean($this->Application->Parameters['PostApproval'])) + $postRecord->Status=PostRecord::STATUS_PENDING; + else + $postRecord->Status=PostRecord::STATUS_PUBLISHED; + $postRecord->CreateTime=time(); + $postRecord->ModifyTime=$postRecord->CreateTime; + $postRecord->AuthorID=$this->User->ID; + $cats=array(); + foreach($this->Categories->SelectedValues as $value) + $cats[]=TPropertyValue::ensureInteger($value); + $this->DataAccess->insertPost($postRecord,$cats); + $this->gotoPage('Posts.ViewPost',array('id'=>$postRecord->ID)); + } + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Posts/ViewPost.php b/demos/blog/protected/Pages/Posts/ViewPost.php index 662dc659..5831ba93 100644 --- a/demos/blog/protected/Pages/Posts/ViewPost.php +++ b/demos/blog/protected/Pages/Posts/ViewPost.php @@ -1,90 +1,90 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * ViewPost class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class ViewPost extends BlogPage -{ - private $_post=null; - - public function onInit($param) - { - parent::onInit($param); - $id=TPropertyValue::ensureInteger($this->Request['id']); - $this->_post=$this->DataAccess->queryPostByID($id); - if($this->_post===null) - throw new BlogException(500,'post_id_invalid',$id); - // if post is not published, only the author and admin can view it - if($this->_post->Status!==PostRecord::STATUS_PUBLISHED && $this->_post->Status!==PostRecord::STATUS_STICKY && !$this->User->IsAdmin && $this->User->ID!==$this->_post->AuthorID) - throw new BlogException(500,'post_view_disallowed',$id); - $this->Title=htmlentities($this->_post->Title,ENT_QUOTES,'UTF-8'); - } - - public function getCanEditPost() - { - $user=$this->getUser(); - return $user->getIsAdmin() || $user->getID()===$this->_post->AuthorID; - } - - public function getCurrentPost() - { - return $this->_post; - } - - public function onLoad($param) - { - parent::onLoad($param); - $this->Status->Visible=$this->_post->Status!==PostRecord::STATUS_PUBLISHED && $this->_post->Status!==PostRecord::STATUS_STICKY; - $this->CategoryList->DataSource=$this->DataAccess->queryCategoriesByPostID($this->_post->ID); - $this->CategoryList->dataBind(); - $this->CommentList->DataSource=$this->DataAccess->queryCommentsByPostID($this->_post->ID); - $this->CommentList->dataBind(); - } - - public function submitCommentButtonClicked($sender,$param) - { - if($this->IsValid) - { - $commentRecord=new CommentRecord; - $commentRecord->PostID=$this->CurrentPost->ID; - $commentRecord->AuthorName=$this->CommentAuthor->SafeText; - $commentRecord->AuthorEmail=$this->CommentEmail->Text; - $commentRecord->AuthorWebsite=$this->CommentWebsite->SafeText; - $commentRecord->AuthorIP=$this->Request->UserHostAddress; - $commentRecord->Content=$this->CommentContent->SafeText; - $commentRecord->CreateTime=time(); - $commentRecord->Status=0; - $this->DataAccess->insertComment($commentRecord); - $this->Response->reload(); - } - } - - public function deleteButtonClicked($sender,$param) - { - $this->DataAccess->deletePost($this->CurrentPost->ID); - $this->gotoDefaultPage(); - } - - public function repeaterItemCommand($sender,$param) - { - $id=TPropertyValue::ensureInteger($param->CommandParameter); - $this->DataAccess->deleteComment($id); - $this->Response->reload(); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * ViewPost class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class ViewPost extends BlogPage +{ + private $_post=null; + + public function onInit($param) + { + parent::onInit($param); + $id=TPropertyValue::ensureInteger($this->Request['id']); + $this->_post=$this->DataAccess->queryPostByID($id); + if($this->_post===null) + throw new BlogException(500,'post_id_invalid',$id); + // if post is not published, only the author and admin can view it + if($this->_post->Status!==PostRecord::STATUS_PUBLISHED && $this->_post->Status!==PostRecord::STATUS_STICKY && !$this->User->IsAdmin && $this->User->ID!==$this->_post->AuthorID) + throw new BlogException(500,'post_view_disallowed',$id); + $this->Title=htmlentities($this->_post->Title,ENT_QUOTES,'UTF-8'); + } + + public function getCanEditPost() + { + $user=$this->getUser(); + return $user->getIsAdmin() || $user->getID()===$this->_post->AuthorID; + } + + public function getCurrentPost() + { + return $this->_post; + } + + public function onLoad($param) + { + parent::onLoad($param); + $this->Status->Visible=$this->_post->Status!==PostRecord::STATUS_PUBLISHED && $this->_post->Status!==PostRecord::STATUS_STICKY; + $this->CategoryList->DataSource=$this->DataAccess->queryCategoriesByPostID($this->_post->ID); + $this->CategoryList->dataBind(); + $this->CommentList->DataSource=$this->DataAccess->queryCommentsByPostID($this->_post->ID); + $this->CommentList->dataBind(); + } + + public function submitCommentButtonClicked($sender,$param) + { + if($this->IsValid) + { + $commentRecord=new CommentRecord; + $commentRecord->PostID=$this->CurrentPost->ID; + $commentRecord->AuthorName=$this->CommentAuthor->SafeText; + $commentRecord->AuthorEmail=$this->CommentEmail->Text; + $commentRecord->AuthorWebsite=$this->CommentWebsite->SafeText; + $commentRecord->AuthorIP=$this->Request->UserHostAddress; + $commentRecord->Content=$this->CommentContent->SafeText; + $commentRecord->CreateTime=time(); + $commentRecord->Status=0; + $this->DataAccess->insertComment($commentRecord); + $this->Response->reload(); + } + } + + public function deleteButtonClicked($sender,$param) + { + $this->DataAccess->deletePost($this->CurrentPost->ID); + $this->gotoDefaultPage(); + } + + public function repeaterItemCommand($sender,$param) + { + $id=TPropertyValue::ensureInteger($param->CommandParameter); + $this->DataAccess->deleteComment($id); + $this->Response->reload(); + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/SearchPost.php b/demos/blog/protected/Pages/SearchPost.php index dc483f9a..437435f9 100644 --- a/demos/blog/protected/Pages/SearchPost.php +++ b/demos/blog/protected/Pages/SearchPost.php @@ -1,68 +1,68 @@ -_posts=$this->DataAccess->queryPostsSearch( - $this->getPostKeywords(), - 'ORDER BY create_time DESC', - 'LIMIT '.$this->getPageOffset().','.$this->getPageSize()); - } - - private function getPostKeywords() - { - return explode(' ',$this->Request['keyword']); - } - - private function getPageOffset() - { - if(($offset=TPropertyValue::ensureInteger($this->Request['offset']))<=0) - $offset=0; - return $offset; - } - - private function getPageSize() - { - if(($limit=TPropertyValue::ensureInteger($this->Request['limit']))<=0) - $limit=TPropertyValue::ensureInteger($this->Application->Parameters['PostPerPage']); - return $limit; - } - - private function formUrl($newOffset) - { - $gets=array(); - $gets['offset']=$newOffset; - if($this->Request['limit']!==null) - $gets['limit']=$this->Request['limit']; - if($this->Request['time']!==null) - $gets['time']=$this->Request['time']; - if($this->Request['cat']!==null) - $gets['cat']=$this->Request['cat']; - return $this->Service->constructUrl('Posts.ListPost',$gets); - } - - public function onLoad($param) - { - parent::onLoad($param); - $this->PostList->DataSource=$this->_posts; - $this->PostList->dataBind(); - if($this->getPageOffset()>0) - { - if(($offset=$this->getPageOffset()-$this->getPageSize())<0) - $offset=0; - $this->PrevPage->NavigateUrl=$this->formUrl($offset); - $this->PrevPage->Visible=true; - } - if(count($this->_posts)===$this->getPageSize()) - { - $this->NextPage->NavigateUrl=$this->formUrl($this->getPageOffset()+$this->getPageSize()); - $this->NextPage->Visible=true; - } - } -} - +_posts=$this->DataAccess->queryPostsSearch( + $this->getPostKeywords(), + 'ORDER BY create_time DESC', + 'LIMIT '.$this->getPageOffset().','.$this->getPageSize()); + } + + private function getPostKeywords() + { + return explode(' ',$this->Request['keyword']); + } + + private function getPageOffset() + { + if(($offset=TPropertyValue::ensureInteger($this->Request['offset']))<=0) + $offset=0; + return $offset; + } + + private function getPageSize() + { + if(($limit=TPropertyValue::ensureInteger($this->Request['limit']))<=0) + $limit=TPropertyValue::ensureInteger($this->Application->Parameters['PostPerPage']); + return $limit; + } + + private function formUrl($newOffset) + { + $gets=array(); + $gets['offset']=$newOffset; + if($this->Request['limit']!==null) + $gets['limit']=$this->Request['limit']; + if($this->Request['time']!==null) + $gets['time']=$this->Request['time']; + if($this->Request['cat']!==null) + $gets['cat']=$this->Request['cat']; + return $this->Service->constructUrl('Posts.ListPost',$gets); + } + + public function onLoad($param) + { + parent::onLoad($param); + $this->PostList->DataSource=$this->_posts; + $this->PostList->dataBind(); + if($this->getPageOffset()>0) + { + if(($offset=$this->getPageOffset()-$this->getPageSize())<0) + $offset=0; + $this->PrevPage->NavigateUrl=$this->formUrl($offset); + $this->PrevPage->Visible=true; + } + if(count($this->_posts)===$this->getPageSize()) + { + $this->NextPage->NavigateUrl=$this->formUrl($this->getPageOffset()+$this->getPageSize()); + $this->NextPage->Visible=true; + } + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Users/EditUser.php b/demos/blog/protected/Pages/Users/EditUser.php index c574ca6b..8d5cb090 100644 --- a/demos/blog/protected/Pages/Users/EditUser.php +++ b/demos/blog/protected/Pages/Users/EditUser.php @@ -1,69 +1,69 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * EditUser class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class EditUser extends BlogPage -{ - private $_userRecord=null; - - public function onInit($param) - { - parent::onInit($param); - if(($id=$this->Request['id'])!==null) - { - $id=TPropertyValue::ensureInteger($id); - if(!$this->User->IsAdmin && $this->User->ID!==$id) - throw new BlogException(500,'profile_edit_disallowed',$id); - } - else - $id=$this->User->ID; - if(($this->_userRecord=$this->DataAccess->queryUserByID($id))===null) - throw new BlogException(500,'profile_id_invalid',$id); - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $userRecord=$this->_userRecord; - $this->Username->Text=$userRecord->Name; - $this->FullName->Text=$userRecord->FullName; - $this->Email->Text=$userRecord->Email; - $this->Website->Text=$userRecord->Website; - } - } - - public function saveButtonClicked($sender,$param) - { - if($this->IsValid) - { - $userRecord=$this->_userRecord; - if($this->Password->Text!=='') - $userRecord->Password=md5($this->Password->Text); - $userRecord->FullName=$this->FullName->Text; - $userRecord->Email=$this->Email->Text; - $userRecord->Website=$this->Website->Text; - $this->DataAccess->updateUser($userRecord); - $authManager=$this->Application->getModule('auth'); - $this->gotoPage('Users.ViewUser',array('id'=>$userRecord->ID)); - } - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * EditUser class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class EditUser extends BlogPage +{ + private $_userRecord=null; + + public function onInit($param) + { + parent::onInit($param); + if(($id=$this->Request['id'])!==null) + { + $id=TPropertyValue::ensureInteger($id); + if(!$this->User->IsAdmin && $this->User->ID!==$id) + throw new BlogException(500,'profile_edit_disallowed',$id); + } + else + $id=$this->User->ID; + if(($this->_userRecord=$this->DataAccess->queryUserByID($id))===null) + throw new BlogException(500,'profile_id_invalid',$id); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $userRecord=$this->_userRecord; + $this->Username->Text=$userRecord->Name; + $this->FullName->Text=$userRecord->FullName; + $this->Email->Text=$userRecord->Email; + $this->Website->Text=$userRecord->Website; + } + } + + public function saveButtonClicked($sender,$param) + { + if($this->IsValid) + { + $userRecord=$this->_userRecord; + if($this->Password->Text!=='') + $userRecord->Password=md5($this->Password->Text); + $userRecord->FullName=$this->FullName->Text; + $userRecord->Email=$this->Email->Text; + $userRecord->Website=$this->Website->Text; + $this->DataAccess->updateUser($userRecord); + $authManager=$this->Application->getModule('auth'); + $this->gotoPage('Users.ViewUser',array('id'=>$userRecord->ID)); + } + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Users/NewUser.php b/demos/blog/protected/Pages/Users/NewUser.php index 40e79910..50f9f123 100644 --- a/demos/blog/protected/Pages/Users/NewUser.php +++ b/demos/blog/protected/Pages/Users/NewUser.php @@ -1,58 +1,58 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * NewUser class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class NewUser extends BlogPage -{ - public function onInit($param) - { - if(!$this->User->IsAdmin && !TPropertyValue::ensureBoolean($this->Application->Parameters['MultipleUser'])) - throw new BlogException(500,'newuser_registration_disallowed'); - } - - public function checkUsername($sender,$param) - { - $username=strtolower($this->Username->Text); - $param->IsValid=$this->DataAccess->queryUserByName($username)===null; - } - - public function createUser($sender,$param) - { - if($this->IsValid) - { - $userRecord=new UserRecord; - $userRecord->Name=strtolower($this->Username->Text); - $userRecord->FullName=$this->FullName->Text; - $userRecord->Role=0; - $userRecord->Password=md5($this->Password->Text); - $userRecord->Email=$this->Email->Text; - $userRecord->CreateTime=time(); - $userRecord->Website=$this->Website->Text; - if(TPropertyValue::ensureBoolean($this->Application->Parameters['AccountApproval'])) - $userRecord->Status=UserRecord::STATUS_PENDING; - else - $userRecord->Status=UserRecord::STATUS_NORMAL; - $this->DataAccess->insertUser($userRecord); - $authManager=$this->Application->getModule('auth'); - $authManager->login($this->Username->Text,$this->Password->Text); - $this->gotoDefaultPage(); - } - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * NewUser class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class NewUser extends BlogPage +{ + public function onInit($param) + { + if(!$this->User->IsAdmin && !TPropertyValue::ensureBoolean($this->Application->Parameters['MultipleUser'])) + throw new BlogException(500,'newuser_registration_disallowed'); + } + + public function checkUsername($sender,$param) + { + $username=strtolower($this->Username->Text); + $param->IsValid=$this->DataAccess->queryUserByName($username)===null; + } + + public function createUser($sender,$param) + { + if($this->IsValid) + { + $userRecord=new UserRecord; + $userRecord->Name=strtolower($this->Username->Text); + $userRecord->FullName=$this->FullName->Text; + $userRecord->Role=0; + $userRecord->Password=md5($this->Password->Text); + $userRecord->Email=$this->Email->Text; + $userRecord->CreateTime=time(); + $userRecord->Website=$this->Website->Text; + if(TPropertyValue::ensureBoolean($this->Application->Parameters['AccountApproval'])) + $userRecord->Status=UserRecord::STATUS_PENDING; + else + $userRecord->Status=UserRecord::STATUS_NORMAL; + $this->DataAccess->insertUser($userRecord); + $authManager=$this->Application->getModule('auth'); + $authManager->login($this->Username->Text,$this->Password->Text); + $this->gotoDefaultPage(); + } + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Pages/Users/ViewUser.php b/demos/blog/protected/Pages/Users/ViewUser.php index 75bd711a..86c27592 100644 --- a/demos/blog/protected/Pages/Users/ViewUser.php +++ b/demos/blog/protected/Pages/Users/ViewUser.php @@ -1,42 +1,42 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * ViewUser class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class ViewUser extends BlogPage -{ - private $_userRecord=null; - - public function onInit($param) - { - parent::onInit($param); - if(($id=$this->Request['id'])!==null) - $id=TPropertyValue::ensureInteger($id); - else - $id=$this->User->ID; - if(($this->_userRecord=$this->DataAccess->queryUserByID($id))===null) - throw new BlogException(500,'profile_id_invalid',$id); - $this->_userRecord->Email=strtr(strtoupper($this->_userRecord->Email),array('@'=>' at ','.'=>' dot ')); - } - - public function getProfile() - { - return $this->_userRecord; - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * ViewUser class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class ViewUser extends BlogPage +{ + private $_userRecord=null; + + public function onInit($param) + { + parent::onInit($param); + if(($id=$this->Request['id'])!==null) + $id=TPropertyValue::ensureInteger($id); + else + $id=$this->User->ID; + if(($this->_userRecord=$this->DataAccess->queryUserByID($id))===null) + throw new BlogException(500,'profile_id_invalid',$id); + $this->_userRecord->Email=strtr(strtoupper($this->_userRecord->Email),array('@'=>' at ','.'=>' dot ')); + } + + public function getProfile() + { + return $this->_userRecord; + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Portlets/AccountPortlet.php b/demos/blog/protected/Portlets/AccountPortlet.php index 2bbe55d3..40be36ae 100644 --- a/demos/blog/protected/Portlets/AccountPortlet.php +++ b/demos/blog/protected/Portlets/AccountPortlet.php @@ -1,31 +1,31 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -Prado::using('Application.Portlets.Portlet'); - -/** - * AccountPortlet class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class AccountPortlet extends Portlet -{ - public function logout($sender,$param) - { - $this->Application->getModule('auth')->logout(); - $this->Response->reload(); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('Application.Portlets.Portlet'); + +/** + * AccountPortlet class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class AccountPortlet extends Portlet +{ + public function logout($sender,$param) + { + $this->Application->getModule('auth')->logout(); + $this->Response->reload(); + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Portlets/ArchivePortlet.php b/demos/blog/protected/Portlets/ArchivePortlet.php index 003eb0cc..f8bd488e 100644 --- a/demos/blog/protected/Portlets/ArchivePortlet.php +++ b/demos/blog/protected/Portlets/ArchivePortlet.php @@ -1,62 +1,62 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -Prado::using('Application.Portlets.Portlet'); - -/** - * ArchivePortlet class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class ArchivePortlet extends Portlet -{ - private function makeMonthTime($timestamp) - { - $date=getdate($timestamp); - return mktime(0,0,0,$date['mon'],1,$date['year']); - } - - public function onLoad($param) - { - $currentTime=time(); - $startTime=$this->Application->getModule('data')->queryEarliestPostTime(); - if(empty($startTime)) // if no posts - $startTime=$currentTime; - - // obtain the timestamp for the initial month - $date=getdate($startTime); - $startTime=mktime(0,0,0,$date['mon'],1,$date['year']); - - $date=getdate($currentTime); - $month=$date['mon']; - $year=$date['year']; - - $timestamps=array(); - while(true) - { - if(($timestamp=mktime(0,0,0,$month,1,$year))<$startTime) - break; - $timestamps[]=$timestamp; - if(--$month===0) - { - $month=12; - $year--; - } - } - $this->MonthList->DataSource=$timestamps; - $this->MonthList->dataBind(); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('Application.Portlets.Portlet'); + +/** + * ArchivePortlet class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class ArchivePortlet extends Portlet +{ + private function makeMonthTime($timestamp) + { + $date=getdate($timestamp); + return mktime(0,0,0,$date['mon'],1,$date['year']); + } + + public function onLoad($param) + { + $currentTime=time(); + $startTime=$this->Application->getModule('data')->queryEarliestPostTime(); + if(empty($startTime)) // if no posts + $startTime=$currentTime; + + // obtain the timestamp for the initial month + $date=getdate($startTime); + $startTime=mktime(0,0,0,$date['mon'],1,$date['year']); + + $date=getdate($currentTime); + $month=$date['mon']; + $year=$date['year']; + + $timestamps=array(); + while(true) + { + if(($timestamp=mktime(0,0,0,$month,1,$year))<$startTime) + break; + $timestamps[]=$timestamp; + if(--$month===0) + { + $month=12; + $year--; + } + } + $this->MonthList->DataSource=$timestamps; + $this->MonthList->dataBind(); + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Portlets/CategoryPortlet.php b/demos/blog/protected/Portlets/CategoryPortlet.php index d95b0661..0b451db8 100644 --- a/demos/blog/protected/Portlets/CategoryPortlet.php +++ b/demos/blog/protected/Portlets/CategoryPortlet.php @@ -1,38 +1,38 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -Prado::using('Application.Portlets.Portlet'); - -/** - * CategoryPortlet class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class CategoryPortlet extends Portlet -{ - public function onLoad($param) - { - parent::onLoad($param); - $cats=$this->Application->getModule('data')->queryCategories(); - foreach($cats as $cat) - { - $cat->ID=$this->Service->constructUrl('Posts.ListPost',array('cat'=>$cat->ID)); - $cat->Name.=' (' . $cat->PostCount .')'; - } - $this->CategoryList->DataSource=$cats; - $this->CategoryList->dataBind(); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('Application.Portlets.Portlet'); + +/** + * CategoryPortlet class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class CategoryPortlet extends Portlet +{ + public function onLoad($param) + { + parent::onLoad($param); + $cats=$this->Application->getModule('data')->queryCategories(); + foreach($cats as $cat) + { + $cat->ID=$this->Service->constructUrl('Posts.ListPost',array('cat'=>$cat->ID)); + $cat->Name.=' (' . $cat->PostCount .')'; + } + $this->CategoryList->DataSource=$cats; + $this->CategoryList->dataBind(); + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Portlets/CommentPortlet.php b/demos/blog/protected/Portlets/CommentPortlet.php index c3549928..ff8d075a 100644 --- a/demos/blog/protected/Portlets/CommentPortlet.php +++ b/demos/blog/protected/Portlets/CommentPortlet.php @@ -1,40 +1,40 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -Prado::using('Application.Portlets.Portlet'); - -/** - * CommentPortlet class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class CommentPortlet extends Portlet -{ - public function onLoad($param) - { - parent::onLoad($param); - $commentLimit=TPropertyValue::ensureInteger($this->Application->Parameters['RecentComments']); - $comments=$this->Application->getModule('data')->queryComments('','ORDER BY create_time DESC',"LIMIT $commentLimit"); - foreach($comments as $comment) - { - $comment->ID=$this->Service->constructUrl('Posts.ViewPost',array('id'=>$comment->PostID)).'#c'.$comment->ID; - if(strlen($comment->Content)>40) - $comment->Content=substr($comment->Content,0,40).' ...'; - } - $this->CommentList->DataSource=$comments; - $this->CommentList->dataBind(); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('Application.Portlets.Portlet'); + +/** + * CommentPortlet class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class CommentPortlet extends Portlet +{ + public function onLoad($param) + { + parent::onLoad($param); + $commentLimit=TPropertyValue::ensureInteger($this->Application->Parameters['RecentComments']); + $comments=$this->Application->getModule('data')->queryComments('','ORDER BY create_time DESC',"LIMIT $commentLimit"); + foreach($comments as $comment) + { + $comment->ID=$this->Service->constructUrl('Posts.ViewPost',array('id'=>$comment->PostID)).'#c'.$comment->ID; + if(strlen($comment->Content)>40) + $comment->Content=substr($comment->Content,0,40).' ...'; + } + $this->CommentList->DataSource=$comments; + $this->CommentList->dataBind(); + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Portlets/LoginPortlet.php b/demos/blog/protected/Portlets/LoginPortlet.php index 6f400f0a..58c056b3 100644 --- a/demos/blog/protected/Portlets/LoginPortlet.php +++ b/demos/blog/protected/Portlets/LoginPortlet.php @@ -1,39 +1,39 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -Prado::using('Application.Portlets.Portlet'); - -/** - * LoginPortlet class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class LoginPortlet extends Portlet -{ - public function validateUser($sender,$param) - { - $authManager=$this->Application->getModule('auth'); - if(!$authManager->login(strtolower($this->Username->Text),$this->Password->Text)) - $param->IsValid=false; - } - - public function loginButtonClicked($sender,$param) - { - if($this->Page->IsValid) - $this->Response->reload(); - //$this->Response->redirect($this->Application->getModule('auth')->getReturnUrl()); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('Application.Portlets.Portlet'); + +/** + * LoginPortlet class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class LoginPortlet extends Portlet +{ + public function validateUser($sender,$param) + { + $authManager=$this->Application->getModule('auth'); + if(!$authManager->login(strtolower($this->Username->Text),$this->Password->Text)) + $param->IsValid=false; + } + + public function loginButtonClicked($sender,$param) + { + if($this->Page->IsValid) + $this->Response->reload(); + //$this->Response->redirect($this->Application->getModule('auth')->getReturnUrl()); + } +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Portlets/Portlet.php b/demos/blog/protected/Portlets/Portlet.php index 50cb634d..6a7cee70 100644 --- a/demos/blog/protected/Portlets/Portlet.php +++ b/demos/blog/protected/Portlets/Portlet.php @@ -1,24 +1,24 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -/** - * Portlet class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class Portlet extends TTemplateControl -{ -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +/** + * Portlet class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class Portlet extends TTemplateControl +{ +} + ?> \ No newline at end of file diff --git a/demos/blog/protected/Portlets/SearchPortlet.php b/demos/blog/protected/Portlets/SearchPortlet.php index 10ef0499..4f7d6ebf 100644 --- a/demos/blog/protected/Portlets/SearchPortlet.php +++ b/demos/blog/protected/Portlets/SearchPortlet.php @@ -1,39 +1,39 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - */ - -Prado::using('Application.Portlets.Portlet'); - -/** - * SearchPortlet class - * - * @author Qiang Xue - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2006 PradoSoft - * @license http://www.pradosoft.com/license/ - */ -class SearchPortlet extends Portlet -{ - public function onInit($param) - { - parent::onInit($param); - if(!$this->Page->IsPostBack && ($keyword=$this->Request['keyword'])!==null) - $this->Keyword->Text=$keyword; - } - - public function search($sender,$param) - { - $keyword=$this->Keyword->Text; - $url=$this->Service->constructUrl('SearchPost',array('keyword'=>$keyword),false); - $this->Response->redirect($url); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + */ + +Prado::using('Application.Portlets.Portlet'); + +/** + * SearchPortlet class + * + * @author Qiang Xue + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + */ +class SearchPortlet extends Portlet +{ + public function onInit($param) + { + parent::onInit($param); + if(!$this->Page->IsPostBack && ($keyword=$this->Request['keyword'])!==null) + $this->Keyword->Text=$keyword; + } + + public function search($sender,$param) + { + $keyword=$this->Keyword->Text; + $url=$this->Service->constructUrl('SearchPost',array('keyword'=>$keyword),false); + $this->Response->redirect($url); + } +} + ?> \ No newline at end of file diff --git a/demos/chat/index.php b/demos/chat/index.php index 17ed21d0..7a9eaf42 100644 --- a/demos/chat/index.php +++ b/demos/chat/index.php @@ -1,29 +1,29 @@ -run(); - +run(); + ?> \ No newline at end of file diff --git a/demos/chat/protected/App_Code/ChatBufferRecord.php b/demos/chat/protected/App_Code/ChatBufferRecord.php index f4d53db0..5a714de2 100644 --- a/demos/chat/protected/App_Code/ChatBufferRecord.php +++ b/demos/chat/protected/App_Code/ChatBufferRecord.php @@ -1,64 +1,64 @@ -_created_on === null) - $this->_created_on = time(); - return $this->_created_on; - } - - public function setCreated_On($value) - { - $this->_created_on = $value; - } - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } - - public function saveMessage() - { - foreach(ChatUserRecord::finder()->findAll() as $user) - { - $message = new self; - $message->for_user = $user->username; - $message->from_user = $this->from_user; - $message->message = $this->message; - $message->save(); - if($user->username == $this->from_user) - { - $user->last_activity = time(); //update the last activity; - $user->save(); - } - } - } - - public function getUserMessages($user) - { - $content = ''; - foreach($this->findAll('for_user = ?', $user) as $message) - $content .= $this->formatMessage($message); - $this->deleteAll('for_user = ? OR created_on < ?', $user, time() - 300); //5 min inactivity - return $content; - } - - protected function formatMessage($message) - { - $user = htmlspecialchars($message->from_user); - $content = htmlspecialchars($message->message); - return "
{$user}: {$content}
"; - } -} - +_created_on === null) + $this->_created_on = time(); + return $this->_created_on; + } + + public function setCreated_On($value) + { + $this->_created_on = $value; + } + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } + + public function saveMessage() + { + foreach(ChatUserRecord::finder()->findAll() as $user) + { + $message = new self; + $message->for_user = $user->username; + $message->from_user = $this->from_user; + $message->message = $this->message; + $message->save(); + if($user->username == $this->from_user) + { + $user->last_activity = time(); //update the last activity; + $user->save(); + } + } + } + + public function getUserMessages($user) + { + $content = ''; + foreach($this->findAll('for_user = ?', $user) as $message) + $content .= $this->formatMessage($message); + $this->deleteAll('for_user = ? OR created_on < ?', $user, time() - 300); //5 min inactivity + return $content; + } + + protected function formatMessage($message) + { + $user = htmlspecialchars($message->from_user); + $content = htmlspecialchars($message->message); + return "
{$user}: {$content}
"; + } +} + ?> \ No newline at end of file diff --git a/demos/chat/protected/App_Code/ChatUserManager.php b/demos/chat/protected/App_Code/ChatUserManager.php index f28ee362..d0f242fd 100644 --- a/demos/chat/protected/App_Code/ChatUserManager.php +++ b/demos/chat/protected/App_Code/ChatUserManager.php @@ -1,85 +1,85 @@ -setIsGuest(true); - if($username !== null) - { - $user->setIsGuest(false); - $user->setName($username); - $user->setRoles(array('normal')); - } - return $user; - } - - /** - * Add a new user to the database. - * @param string username. - */ - public function addNewUser($username) - { - $user = new ChatUserRecord(); - $user->username = $username; - $user->save(); - } - - /** - * @return boolean true if username already exists, false otherwise. - */ - public function usernameExists($username) - { - return ChatUserRecord::finder()->findByUsername($username) instanceof ChatUserRecord; - } - - /** - * Validates if the username exists. - * @param string user name - * @param string password - * @return boolean true if validation is successful, false otherwise. - */ - public function validateUser($username,$password) - { - return $this->usernameExists($username); - } - - /** - * 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) - { - // do nothing since we don't support cookie-based auth in this example - } - - /** - * 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) - { - // do nothing since we don't support cookie-based auth in this example - return null; - } -} - - +setIsGuest(true); + if($username !== null) + { + $user->setIsGuest(false); + $user->setName($username); + $user->setRoles(array('normal')); + } + return $user; + } + + /** + * Add a new user to the database. + * @param string username. + */ + public function addNewUser($username) + { + $user = new ChatUserRecord(); + $user->username = $username; + $user->save(); + } + + /** + * @return boolean true if username already exists, false otherwise. + */ + public function usernameExists($username) + { + return ChatUserRecord::finder()->findByUsername($username) instanceof ChatUserRecord; + } + + /** + * Validates if the username exists. + * @param string user name + * @param string password + * @return boolean true if validation is successful, false otherwise. + */ + public function validateUser($username,$password) + { + return $this->usernameExists($username); + } + + /** + * 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) + { + // do nothing since we don't support cookie-based auth in this example + } + + /** + * 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) + { + // do nothing since we don't support cookie-based auth in this example + return null; + } +} + + ?> \ No newline at end of file diff --git a/demos/chat/protected/App_Code/ChatUserRecord.php b/demos/chat/protected/App_Code/ChatUserRecord.php index b68fbd4d..ee45cf84 100644 --- a/demos/chat/protected/App_Code/ChatUserRecord.php +++ b/demos/chat/protected/App_Code/ChatUserRecord.php @@ -1,41 +1,41 @@ -_last_activity === null) - $this->_last_activity = time(); - return $this->_last_activity; - } - - public function setLast_Activity($value) - { - $this->_last_activity = $value; - } - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } - - public function getUserList() - { - $this->deleteAll('last_activity < ?', time()-300); //5 min inactivity - $content = '
    '; - foreach($this->findAll() as $user) - { - $content .= '
  • '.htmlspecialchars($user->username).'
  • '; - } - $content .= '
'; - - return $content; - } -} - +_last_activity === null) + $this->_last_activity = time(); + return $this->_last_activity; + } + + public function setLast_Activity($value) + { + $this->_last_activity = $value; + } + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } + + public function getUserList() + { + $this->deleteAll('last_activity < ?', time()-300); //5 min inactivity + $content = '
    '; + foreach($this->findAll() as $user) + { + $content .= '
  • '.htmlspecialchars($user->username).'
  • '; + } + $content .= '
'; + + return $content; + } +} + ?> \ No newline at end of file diff --git a/demos/chat/protected/pages/Home.php b/demos/chat/protected/pages/Home.php index 65cb22dc..bdcb2d3b 100644 --- a/demos/chat/protected/pages/Home.php +++ b/demos/chat/protected/pages/Home.php @@ -1,56 +1,56 @@ -Application->User->Name; - if(!$this->Application->Modules['users']->usernameExists($username)) - { - $auth = $this->Application->Modules['auth']; - $auth->logout(); - - //redirect to login page. - $this->Response->Redirect($this->Service->ConstructUrl($auth->LoginPage)); - } - } - - function processMessage($sender, $param) - { - if(strlen($this->userinput->Text) > 0) - { - $record = new ChatBufferRecord(); - $record->message = $this->userinput->Text; - $record->from_user = $this->Application->User->Name; - $record->saveMessage(); - $this->userinput->Text = ''; - $this->refresh($sender, $param); - $this->CallbackClient->focus($this->userinput); - } - } - - function refresh($sender, $param) - { - //refresh the message list - $content = ChatBufferRecord::finder()->getUserMessages($this->Application->User->Name); - if(strlen($content) > 0) - { - $client = $this->Page->CallbackClient; - $anchor = (string)time(); - $content .= " "; - $client->appendContent("messages", $content); - $client->focus($anchor); - } - - //refresh the user list - $lastUpdate = $this->getViewState('userList',''); - $users = ChatUserRecord::finder()->getUserList(); - if($lastUpdate != $users) - { - $this->Page->CallbackClient->update('users', $users); - $this->setViewstate('userList', $users); - } - } -} - +Application->User->Name; + if(!$this->Application->Modules['users']->usernameExists($username)) + { + $auth = $this->Application->Modules['auth']; + $auth->logout(); + + //redirect to login page. + $this->Response->Redirect($this->Service->ConstructUrl($auth->LoginPage)); + } + } + + function processMessage($sender, $param) + { + if(strlen($this->userinput->Text) > 0) + { + $record = new ChatBufferRecord(); + $record->message = $this->userinput->Text; + $record->from_user = $this->Application->User->Name; + $record->saveMessage(); + $this->userinput->Text = ''; + $this->refresh($sender, $param); + $this->CallbackClient->focus($this->userinput); + } + } + + function refresh($sender, $param) + { + //refresh the message list + $content = ChatBufferRecord::finder()->getUserMessages($this->Application->User->Name); + if(strlen($content) > 0) + { + $client = $this->Page->CallbackClient; + $anchor = (string)time(); + $content .= " "; + $client->appendContent("messages", $content); + $client->focus($anchor); + } + + //refresh the user list + $lastUpdate = $this->getViewState('userList',''); + $users = ChatUserRecord::finder()->getUserList(); + if($lastUpdate != $users) + { + $this->Page->CallbackClient->update('users', $users); + $this->setViewstate('userList', $users); + } + } +} + ?> \ No newline at end of file diff --git a/demos/chat/protected/pages/Login.php b/demos/chat/protected/pages/Login.php index 831ab925..ec39f1f0 100644 --- a/demos/chat/protected/pages/Login.php +++ b/demos/chat/protected/pages/Login.php @@ -1,40 +1,40 @@ -Application->Modules['users']; - if($manager->usernameExists($this->username->Text)) - $param->IsValid = false; - } - - /** - * Create and login a new user, then redirect to the requested page. - * @param TControl button control that created the event. - * @param TEventParameter event parameters. - */ - function createNewUser($sender, $param) - { - if($this->Page->IsValid) - { - $manager = $this->Application->Modules['users']; - $manager->addNewUser($this->username->Text); - - //do manual login - $user = $manager->getUser($this->username->Text); - $auth = $this->Application->Modules['auth']; - $auth->updateSessionUser($user); - $this->Application->User = $user; - - $this->Response->redirect($auth->ReturnUrl); - } - } -} - +Application->Modules['users']; + if($manager->usernameExists($this->username->Text)) + $param->IsValid = false; + } + + /** + * Create and login a new user, then redirect to the requested page. + * @param TControl button control that created the event. + * @param TEventParameter event parameters. + */ + function createNewUser($sender, $param) + { + if($this->Page->IsValid) + { + $manager = $this->Application->Modules['users']; + $manager->addNewUser($this->username->Text); + + //do manual login + $user = $manager->getUser($this->username->Text); + $auth = $this->Application->Modules['auth']; + $auth->updateSessionUser($user); + $this->Application->User = $user; + + $this->Response->redirect($auth->ReturnUrl); + } + } +} + ?> \ No newline at end of file diff --git a/demos/composer/index.php b/demos/composer/index.php index 43c0b436..6efff1af 100644 --- a/demos/composer/index.php +++ b/demos/composer/index.php @@ -1,18 +1,18 @@ -run(); - +run(); + ?> \ No newline at end of file diff --git a/demos/composer/index2.php b/demos/composer/index2.php index f3d8dd90..30df9480 100644 --- a/demos/composer/index2.php +++ b/demos/composer/index2.php @@ -1,18 +1,18 @@ -run(); - +run(); + ?> \ No newline at end of file diff --git a/demos/composer/protected/pages/ClassDefinition.php b/demos/composer/protected/pages/ClassDefinition.php index cb657e85..aee5fe6f 100644 --- a/demos/composer/protected/pages/ClassDefinition.php +++ b/demos/composer/protected/pages/ClassDefinition.php @@ -1,371 +1,371 @@ -_className='ClassName'; - $this->_parentClass='TWebControl'; - $this->_interfaces=''; - $this->_properties=new TList; - $this->_events=new TList; - $this->_email=''; - $this->_author=''; - $this->_comments=''; - } - - public function render($writer) - { - $this->renderComments($writer); - $this->renderClass($writer); - } - - protected function renderComments($writer) - { - $str ="/**\n"; - $str.=" * Class {$this->ClassName}.\n"; - if($this->Comments!=='') - { - $str.=" *\n"; - $str.=" * ".implode("\n * ",explode("\n",wordwrap($this->Comments))); - $str.="\n *\n"; - } - if($this->Author!=='') - { - $str.=" * @author {$this->Author}"; - if($this->Email!=='') - $str.=" <{$this->Email}>"; - $str.="\n"; - } - $str.=" * @version \$Revision: \$ \$Date: \$\n"; - $str.=" */\n"; - $writer->write($str); - } - - protected function renderClass($writer) - { - $writer->write("class {$this->ClassName}"); - if($this->ParentClass!=='') - $writer->write(" extends {$this->ParentClass}"); - if($this->Interfaces!=='') - $writer->write(" implements {$this->Interfaces}"); - $writer->write("\n{\n"); - $this->renderVariables($writer); - $this->renderProperties($writer); - $this->renderEvents($writer); - $writer->write("}\n"); - } - - private function getVariableName($propertyName) - { - return '_'.strtolower($propertyName[0]).substr($propertyName,1); - } - - protected function renderVariables($writer) - { - foreach($this->Properties as $property) - { - if($property->Storage==='Memory') - { - $name=$this->getVariableName($property->Name); - $value=$this->getValueAsString($property->DefaultValue,$property->Type); - $writer->write("\t/**\n\t * @var {$property->Type} {$property->Comments}\n\t */\n"); - $writer->write("\tprivate \$$name=$value;\n"); - } - } - } - - private function getValueAsString($value,$type) - { - switch($type) - { - case 'integer': - $value=TPropertyValue::ensureInteger($value); - break; - case 'float': - $value=TPropertyValue::ensureFloat($value); - break; - case 'boolean': - if(TPropertyValue::ensureBoolean($value)) - $value='true'; - else - $value='false'; - break; - case 'enumerable': - $value="'$value'"; - break; - case 'mixed': - $value='null'; - break; - case 'string': - $value="'$value'"; - break; - } - return "$value"; - } - - private function getValueConversionString($type) - { - switch($type) - { - case 'integer': return 'TPropertyValue::ensureInteger($value)'; - case 'float': return 'TPropertyValue::ensureFloat($value)'; - case 'boolean': return 'TPropertyValue::ensureBoolean($value)'; - case 'enumerable': return 'TPropertyValue::ensureEnum($value)'; - case 'mixed': return '$value'; - case 'string': return 'TPropertyValue::ensureString($value)'; - } - } - - protected function renderProperties($writer) - { - foreach($this->Properties as $property) - { - $name=$property->Name; - if($name==='') - continue; - $comments=implode("\n\t * ",explode("\n",wordwrap($property->Comments))); - $access=$property->IsProtected?'protected':'public'; - $setter='set'.$property->Name.'($value)'; - $getter='get'.$property->Name.'()'; - $value=$this->getValueAsString($property->DefaultValue,$property->Type); - if($property->Storage==='ViewState') - { - $readStatement="return \$this->getViewState('$name',$value);"; - $writeStatement="\$this->setViewState('$name',".$this->getValueConversionString($property->Type).",$value);"; - } - else if($property->Storage==='ControlState') - { - $readStatement="return \$this->getControlState('$name',$value);"; - $writeStatement="\$this->setControlState('$name',".$this->getValueConversionString($property->Type).",$value);"; - } - else - { - $varname=$this->getVariableName($property->Name); - $readStatement="return \$this->$varname;"; - $writeStatement="\$this->$varname=".$this->getValueConversionString($property->Type).";"; - } - $writer->write("\n\t/**\n\t * @return {$property->Type} $comments Defaults to $value.\n\t */\n"); - $writer->write("\t$access function $getter\n\t{\n\t\t$readStatement\n\t}\n"); - if(!$property->ReadOnly) - { - $writer->write("\n\t/**\n\t * @param {$property->Type} $comments\n\t */\n"); - $writer->write("\t$access function $setter\n\t{\n\t\t$writeStatement\n\t}\n"); - } - } - } - - protected function renderEvents($writer) - { - foreach($this->Events as $event) - { - $name=$event->Name; - if($name==='') - continue; - if(strncasecmp($name,'on',2)!==0) - $name='On'.$name; - else - { - $name[0]='O'; - $name[1]='n'; - } - $methodName=$name; - $methodName[0]='o'; - $comments=implode("\n\t * ",explode("\n",wordwrap($event->Comments))); - $writer->write("\n\t/**\n\t * Raises $name event.\n\t * $comments\n\t * @param TEventParameter event parameter\n\t */\n"); - $writer->write("\tpublic function $methodName(\$param)\n\t{\n\t\t\$this->raiseEvent('$name',\$this,\$param);\n\t}\n"); - } - } - - public function getClassName() - { - return $this->_className; - } - - public function setClassName($value) - { - $this->_className=trim($value); - } - - public function getParentClass() - { - return $this->_parentClass; - } - - public function setParentClass($value) - { - $this->_parentClass=trim($value); - } - - public function getInterfaces() - { - return $this->_interfaces; - } - - public function setInterfaces($value) - { - $this->_interfaces=$value; - } - - public function getProperties() - { - if(!$this->_properties) - $this->_properties=new TList; - return $this->_properties; - } - - public function getEvents() - { - if(!$this->_events) - $this->_events=new TList; - return $this->_events; - } - - public function getComments() - { - return $this->_comments; - } - - public function setComments($value) - { - $this->_comments=$value; - } - - public function getAuthor() - { - return $this->_author; - } - - public function setAuthor($value) - { - $this->_author=trim($value); - } - - public function getEmail() - { - return $this->_email; - } - - public function setEmail($value) - { - $this->_email=trim($value); - } -} - -class EventDefinition extends TComponent -{ - private $_name=''; - private $_comments=''; - - public function getName() - { - return $this->_name; - } - - public function setName($value) - { - $this->_name=ucfirst(trim($value)); - } - - public function getComments() - { - return $this->_comments; - } - - public function setComments($value) - { - $this->_comments=$value; - } -} - -class PropertyDefinition extends TComponent -{ - private $_name=''; - private $_type='string'; - private $_default=''; - private $_readOnly=false; - private $_protected=false; - private $_storage='ViewState'; - private $_comments=''; - - public function getName() - { - return $this->_name; - } - - public function setName($value) - { - $this->_name=ucfirst(trim($value)); - } - - public function getType() - { - return $this->_type; - } - - public function setType($value) - { - $this->_type=trim($value); - } - - public function getDefaultValue() - { - return $this->_default; - } - - public function setDefaultValue($value) - { - $this->_default=trim($value); - } - - public function getReadOnly() - { - return $this->_readOnly; - } - - public function setReadOnly($value) - { - $this->_readOnly=TPropertyValue::ensureBoolean($value); - } - - public function getIsProtected() - { - return $this->_protected; - } - - public function setIsProtected($value) - { - $this->_protected=TPropertyValue::ensureBoolean($value); - } - - public function getStorage() - { - return $this->_storage; - } - - public function setStorage($value) - { - $this->_storage=trim($value); - } - - public function getComments() - { - return $this->_comments; - } - - public function setComments($value) - { - $this->_comments=$value; - } -} - +_className='ClassName'; + $this->_parentClass='TWebControl'; + $this->_interfaces=''; + $this->_properties=new TList; + $this->_events=new TList; + $this->_email=''; + $this->_author=''; + $this->_comments=''; + } + + public function render($writer) + { + $this->renderComments($writer); + $this->renderClass($writer); + } + + protected function renderComments($writer) + { + $str ="/**\n"; + $str.=" * Class {$this->ClassName}.\n"; + if($this->Comments!=='') + { + $str.=" *\n"; + $str.=" * ".implode("\n * ",explode("\n",wordwrap($this->Comments))); + $str.="\n *\n"; + } + if($this->Author!=='') + { + $str.=" * @author {$this->Author}"; + if($this->Email!=='') + $str.=" <{$this->Email}>"; + $str.="\n"; + } + $str.=" * @version \$Revision: \$ \$Date: \$\n"; + $str.=" */\n"; + $writer->write($str); + } + + protected function renderClass($writer) + { + $writer->write("class {$this->ClassName}"); + if($this->ParentClass!=='') + $writer->write(" extends {$this->ParentClass}"); + if($this->Interfaces!=='') + $writer->write(" implements {$this->Interfaces}"); + $writer->write("\n{\n"); + $this->renderVariables($writer); + $this->renderProperties($writer); + $this->renderEvents($writer); + $writer->write("}\n"); + } + + private function getVariableName($propertyName) + { + return '_'.strtolower($propertyName[0]).substr($propertyName,1); + } + + protected function renderVariables($writer) + { + foreach($this->Properties as $property) + { + if($property->Storage==='Memory') + { + $name=$this->getVariableName($property->Name); + $value=$this->getValueAsString($property->DefaultValue,$property->Type); + $writer->write("\t/**\n\t * @var {$property->Type} {$property->Comments}\n\t */\n"); + $writer->write("\tprivate \$$name=$value;\n"); + } + } + } + + private function getValueAsString($value,$type) + { + switch($type) + { + case 'integer': + $value=TPropertyValue::ensureInteger($value); + break; + case 'float': + $value=TPropertyValue::ensureFloat($value); + break; + case 'boolean': + if(TPropertyValue::ensureBoolean($value)) + $value='true'; + else + $value='false'; + break; + case 'enumerable': + $value="'$value'"; + break; + case 'mixed': + $value='null'; + break; + case 'string': + $value="'$value'"; + break; + } + return "$value"; + } + + private function getValueConversionString($type) + { + switch($type) + { + case 'integer': return 'TPropertyValue::ensureInteger($value)'; + case 'float': return 'TPropertyValue::ensureFloat($value)'; + case 'boolean': return 'TPropertyValue::ensureBoolean($value)'; + case 'enumerable': return 'TPropertyValue::ensureEnum($value)'; + case 'mixed': return '$value'; + case 'string': return 'TPropertyValue::ensureString($value)'; + } + } + + protected function renderProperties($writer) + { + foreach($this->Properties as $property) + { + $name=$property->Name; + if($name==='') + continue; + $comments=implode("\n\t * ",explode("\n",wordwrap($property->Comments))); + $access=$property->IsProtected?'protected':'public'; + $setter='set'.$property->Name.'($value)'; + $getter='get'.$property->Name.'()'; + $value=$this->getValueAsString($property->DefaultValue,$property->Type); + if($property->Storage==='ViewState') + { + $readStatement="return \$this->getViewState('$name',$value);"; + $writeStatement="\$this->setViewState('$name',".$this->getValueConversionString($property->Type).",$value);"; + } + else if($property->Storage==='ControlState') + { + $readStatement="return \$this->getControlState('$name',$value);"; + $writeStatement="\$this->setControlState('$name',".$this->getValueConversionString($property->Type).",$value);"; + } + else + { + $varname=$this->getVariableName($property->Name); + $readStatement="return \$this->$varname;"; + $writeStatement="\$this->$varname=".$this->getValueConversionString($property->Type).";"; + } + $writer->write("\n\t/**\n\t * @return {$property->Type} $comments Defaults to $value.\n\t */\n"); + $writer->write("\t$access function $getter\n\t{\n\t\t$readStatement\n\t}\n"); + if(!$property->ReadOnly) + { + $writer->write("\n\t/**\n\t * @param {$property->Type} $comments\n\t */\n"); + $writer->write("\t$access function $setter\n\t{\n\t\t$writeStatement\n\t}\n"); + } + } + } + + protected function renderEvents($writer) + { + foreach($this->Events as $event) + { + $name=$event->Name; + if($name==='') + continue; + if(strncasecmp($name,'on',2)!==0) + $name='On'.$name; + else + { + $name[0]='O'; + $name[1]='n'; + } + $methodName=$name; + $methodName[0]='o'; + $comments=implode("\n\t * ",explode("\n",wordwrap($event->Comments))); + $writer->write("\n\t/**\n\t * Raises $name event.\n\t * $comments\n\t * @param TEventParameter event parameter\n\t */\n"); + $writer->write("\tpublic function $methodName(\$param)\n\t{\n\t\t\$this->raiseEvent('$name',\$this,\$param);\n\t}\n"); + } + } + + public function getClassName() + { + return $this->_className; + } + + public function setClassName($value) + { + $this->_className=trim($value); + } + + public function getParentClass() + { + return $this->_parentClass; + } + + public function setParentClass($value) + { + $this->_parentClass=trim($value); + } + + public function getInterfaces() + { + return $this->_interfaces; + } + + public function setInterfaces($value) + { + $this->_interfaces=$value; + } + + public function getProperties() + { + if(!$this->_properties) + $this->_properties=new TList; + return $this->_properties; + } + + public function getEvents() + { + if(!$this->_events) + $this->_events=new TList; + return $this->_events; + } + + public function getComments() + { + return $this->_comments; + } + + public function setComments($value) + { + $this->_comments=$value; + } + + public function getAuthor() + { + return $this->_author; + } + + public function setAuthor($value) + { + $this->_author=trim($value); + } + + public function getEmail() + { + return $this->_email; + } + + public function setEmail($value) + { + $this->_email=trim($value); + } +} + +class EventDefinition extends TComponent +{ + private $_name=''; + private $_comments=''; + + public function getName() + { + return $this->_name; + } + + public function setName($value) + { + $this->_name=ucfirst(trim($value)); + } + + public function getComments() + { + return $this->_comments; + } + + public function setComments($value) + { + $this->_comments=$value; + } +} + +class PropertyDefinition extends TComponent +{ + private $_name=''; + private $_type='string'; + private $_default=''; + private $_readOnly=false; + private $_protected=false; + private $_storage='ViewState'; + private $_comments=''; + + public function getName() + { + return $this->_name; + } + + public function setName($value) + { + $this->_name=ucfirst(trim($value)); + } + + public function getType() + { + return $this->_type; + } + + public function setType($value) + { + $this->_type=trim($value); + } + + public function getDefaultValue() + { + return $this->_default; + } + + public function setDefaultValue($value) + { + $this->_default=trim($value); + } + + public function getReadOnly() + { + return $this->_readOnly; + } + + public function setReadOnly($value) + { + $this->_readOnly=TPropertyValue::ensureBoolean($value); + } + + public function getIsProtected() + { + return $this->_protected; + } + + public function setIsProtected($value) + { + $this->_protected=TPropertyValue::ensureBoolean($value); + } + + public function getStorage() + { + return $this->_storage; + } + + public function setStorage($value) + { + $this->_storage=trim($value); + } + + public function getComments() + { + return $this->_comments; + } + + public function setComments($value) + { + $this->_comments=$value; + } +} + ?> \ No newline at end of file diff --git a/demos/composer/protected/pages/Home.php b/demos/composer/protected/pages/Home.php index d3d02b66..07f02e7e 100644 --- a/demos/composer/protected/pages/Home.php +++ b/demos/composer/protected/pages/Home.php @@ -1,118 +1,118 @@ -_classDefinition) - $this->_classDefinition=new ClassDefinition; - return $this->_classDefinition; - } - - public function onInit($param) - { - parent::onInit($param); - if(!$this->IsPostBack) - { - $properties=$this->ClassDefinition->Properties; - $properties[]=new PropertyDefinition; - $properties[]=new PropertyDefinition; - $properties[]=new PropertyDefinition; - $this->PropertyList->DataSource=$properties; - $this->dataBind(); - } - } - - public function propertyAction($sender,$param) - { - if($param->CommandName==='add') - $this->ClassDefinition->Properties->add(new PropertyDefinition); - if($param->CommandName==='remove') - $this->ClassDefinition->Properties->removeAt($param->CommandParameter); - else if($param->CommandName==='up') - { - $property=$this->ClassDefinition->Properties->itemAt($param->CommandParameter); - $this->ClassDefinition->Properties->removeAt($param->CommandParameter); - $this->ClassDefinition->Properties->insertAt($param->CommandParameter-1,$property); - } - else if($param->CommandName==='down') - { - $property=$this->ClassDefinition->Properties->itemAt($param->CommandParameter); - $this->ClassDefinition->Properties->removeAt($param->CommandParameter); - $this->ClassDefinition->Properties->insertAt($param->CommandParameter+1,$property); - } - $this->PropertyList->DataSource=$this->ClassDefinition->Properties; - $this->PropertyList->dataBind(); - } - - public function eventAction($sender,$param) - { - if($param->CommandName==='add') - $this->ClassDefinition->Events->add(new EventDefinition); - else if($param->CommandName==='remove') - $this->ClassDefinition->Events->removeAt($param->CommandParameter); - else if($param->CommandName==='up') - { - $property=$this->ClassDefinition->Events->itemAt($param->CommandParameter); - $this->ClassDefinition->Events->removeAt($param->CommandParameter); - $this->ClassDefinition->Events->insertAt($param->CommandParameter-1,$property); - } - else if($param->CommandName==='down') - { - $property=$this->ClassDefinition->Events->itemAt($param->CommandParameter); - $this->ClassDefinition->Events->removeAt($param->CommandParameter); - $this->ClassDefinition->Events->insertAt($param->CommandParameter+1,$property); - } - $this->EventList->DataSource=$this->ClassDefinition->Events; - $this->EventList->dataBind(); - } - - public function onLoad($param) - { - parent::onLoad($param); - //if($this->IsPostBack && $this->IsValid) - if($this->IsPostBack) - { - $def=$this->ClassDefinition; - $def->reset(); - $def->ClassName=$this->ClassName->Text; - $def->ParentClass=$this->ParentClass->Text; - $def->Interfaces=$this->Interfaces->Text; - $def->Comments=$this->Comments->Text; - $def->Author=$this->AuthorName->Text; - $def->Email=$this->AuthorEmail->Text; - foreach($this->PropertyList->Items as $item) - { - $property=new PropertyDefinition; - $property->Name=$item->PropertyName->Text; - $property->Type=$item->PropertyType->Text; - $property->DefaultValue=$item->DefaultValue->Text; - $property->ReadOnly=$item->ReadOnly->Checked; - $property->IsProtected=$item->IsProtected->Checked; - $property->Comments=$item->Comments->Text; - $property->Storage=$item->Storage->Text; - $def->Properties[]=$property; - } - foreach($this->EventList->Items as $item) - { - $event=new EventDefinition; - $event->Name=$item->EventName->Text; - $event->Comments=$item->Comments->Text; - $def->Events[]=$event; - } - } - } - - public function generateCode($sender,$param) - { - $writer=Prado::createComponent('TTextWriter'); - $this->ClassDefinition->render($writer); - $this->SourceCode->Text=$writer->flush(); - } -} - +_classDefinition) + $this->_classDefinition=new ClassDefinition; + return $this->_classDefinition; + } + + public function onInit($param) + { + parent::onInit($param); + if(!$this->IsPostBack) + { + $properties=$this->ClassDefinition->Properties; + $properties[]=new PropertyDefinition; + $properties[]=new PropertyDefinition; + $properties[]=new PropertyDefinition; + $this->PropertyList->DataSource=$properties; + $this->dataBind(); + } + } + + public function propertyAction($sender,$param) + { + if($param->CommandName==='add') + $this->ClassDefinition->Properties->add(new PropertyDefinition); + if($param->CommandName==='remove') + $this->ClassDefinition->Properties->removeAt($param->CommandParameter); + else if($param->CommandName==='up') + { + $property=$this->ClassDefinition->Properties->itemAt($param->CommandParameter); + $this->ClassDefinition->Properties->removeAt($param->CommandParameter); + $this->ClassDefinition->Properties->insertAt($param->CommandParameter-1,$property); + } + else if($param->CommandName==='down') + { + $property=$this->ClassDefinition->Properties->itemAt($param->CommandParameter); + $this->ClassDefinition->Properties->removeAt($param->CommandParameter); + $this->ClassDefinition->Properties->insertAt($param->CommandParameter+1,$property); + } + $this->PropertyList->DataSource=$this->ClassDefinition->Properties; + $this->PropertyList->dataBind(); + } + + public function eventAction($sender,$param) + { + if($param->CommandName==='add') + $this->ClassDefinition->Events->add(new EventDefinition); + else if($param->CommandName==='remove') + $this->ClassDefinition->Events->removeAt($param->CommandParameter); + else if($param->CommandName==='up') + { + $property=$this->ClassDefinition->Events->itemAt($param->CommandParameter); + $this->ClassDefinition->Events->removeAt($param->CommandParameter); + $this->ClassDefinition->Events->insertAt($param->CommandParameter-1,$property); + } + else if($param->CommandName==='down') + { + $property=$this->ClassDefinition->Events->itemAt($param->CommandParameter); + $this->ClassDefinition->Events->removeAt($param->CommandParameter); + $this->ClassDefinition->Events->insertAt($param->CommandParameter+1,$property); + } + $this->EventList->DataSource=$this->ClassDefinition->Events; + $this->EventList->dataBind(); + } + + public function onLoad($param) + { + parent::onLoad($param); + //if($this->IsPostBack && $this->IsValid) + if($this->IsPostBack) + { + $def=$this->ClassDefinition; + $def->reset(); + $def->ClassName=$this->ClassName->Text; + $def->ParentClass=$this->ParentClass->Text; + $def->Interfaces=$this->Interfaces->Text; + $def->Comments=$this->Comments->Text; + $def->Author=$this->AuthorName->Text; + $def->Email=$this->AuthorEmail->Text; + foreach($this->PropertyList->Items as $item) + { + $property=new PropertyDefinition; + $property->Name=$item->PropertyName->Text; + $property->Type=$item->PropertyType->Text; + $property->DefaultValue=$item->DefaultValue->Text; + $property->ReadOnly=$item->ReadOnly->Checked; + $property->IsProtected=$item->IsProtected->Checked; + $property->Comments=$item->Comments->Text; + $property->Storage=$item->Storage->Text; + $def->Properties[]=$property; + } + foreach($this->EventList->Items as $item) + { + $event=new EventDefinition; + $event->Name=$item->EventName->Text; + $event->Comments=$item->Comments->Text; + $def->Events[]=$event; + } + } + } + + public function generateCode($sender,$param) + { + $writer=Prado::createComponent('TTextWriter'); + $this->ClassDefinition->render($writer); + $this->SourceCode->Text=$writer->flush(); + } +} + ?> \ No newline at end of file diff --git a/demos/composer/protected/pages/Layout.php b/demos/composer/protected/pages/Layout.php index a82d2fff..3d9b5714 100644 --- a/demos/composer/protected/pages/Layout.php +++ b/demos/composer/protected/pages/Layout.php @@ -1,15 +1,15 @@ -TopicPanel->Visible=!$this->TopicPanel->Visible; - if($this->TopicPanel->Visible) - $sender->Text="Hide TOC"; - else - $sender->Text="Show TOC"; - } -} - +TopicPanel->Visible=!$this->TopicPanel->Visible; + if($this->TopicPanel->Visible) + $sender->Text="Hide TOC"; + else + $sender->Text="Show TOC"; + } +} + ?> \ No newline at end of file diff --git a/demos/helloworld/index.php b/demos/helloworld/index.php index 43c0b436..6efff1af 100644 --- a/demos/helloworld/index.php +++ b/demos/helloworld/index.php @@ -1,18 +1,18 @@ -run(); - +run(); + ?> \ No newline at end of file diff --git a/demos/helloworld/protected/pages/Home.php b/demos/helloworld/protected/pages/Home.php index 16174b2e..36eb2032 100644 --- a/demos/helloworld/protected/pages/Home.php +++ b/demos/helloworld/protected/pages/Home.php @@ -1,11 +1,11 @@ -Text='Hello world!'; - } -} - +Text='Hello world!'; + } +} + ?> \ No newline at end of file diff --git a/demos/northwind-db/index.php b/demos/northwind-db/index.php index 94e60d49..ef243159 100644 --- a/demos/northwind-db/index.php +++ b/demos/northwind-db/index.php @@ -1,28 +1,28 @@ -run(); - +run(); + ?> \ No newline at end of file diff --git a/demos/northwind-db/protected/database/Category.php b/demos/northwind-db/protected/database/Category.php index 06fc979f..d708ee96 100644 --- a/demos/northwind-db/protected/database/Category.php +++ b/demos/northwind-db/protected/database/Category.php @@ -1,26 +1,26 @@ - array(self::HAS_MANY, 'Product'), - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} + array(self::HAS_MANY, 'Product'), + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} ?> \ No newline at end of file diff --git a/demos/northwind-db/protected/database/Customer.php b/demos/northwind-db/protected/database/Customer.php index 810f2a6a..464b384d 100644 --- a/demos/northwind-db/protected/database/Customer.php +++ b/demos/northwind-db/protected/database/Customer.php @@ -1,33 +1,33 @@ - array(self::HAS_MANY, 'Order'), - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} + array(self::HAS_MANY, 'Order'), + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} ?> \ No newline at end of file diff --git a/demos/northwind-db/protected/database/Employee.php b/demos/northwind-db/protected/database/Employee.php index 1e0f090e..573b887d 100644 --- a/demos/northwind-db/protected/database/Employee.php +++ b/demos/northwind-db/protected/database/Employee.php @@ -1,48 +1,48 @@ - array(self::MANY_TO_MANY, 'Territory', 'EmployeeTerritories'), - 'Orders' => array(self::HAS_MANY, 'Order'), - - //parent children relationship - 'Subordinates' => array(self::HAS_MANY, 'Employee'), - 'Superior' => array(self::BELONGS_TO, 'Employee') - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} + array(self::MANY_TO_MANY, 'Territory', 'EmployeeTerritories'), + 'Orders' => array(self::HAS_MANY, 'Order'), + + //parent children relationship + 'Subordinates' => array(self::HAS_MANY, 'Employee'), + 'Superior' => array(self::BELONGS_TO, 'Employee') + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} ?> \ No newline at end of file diff --git a/demos/northwind-db/protected/database/Order.php b/demos/northwind-db/protected/database/Order.php index 228fb2b5..2a425102 100644 --- a/demos/northwind-db/protected/database/Order.php +++ b/demos/northwind-db/protected/database/Order.php @@ -1,42 +1,42 @@ - array(self::HAS_MANY, 'OrderDetail'), - 'Customer' => array(self::BELONGS_TO, 'Customer'), - 'Shipper' => array(self::BELONGS_TO, 'Shipper'), - 'Employee' => array(self::BELONGS_TO, 'Employee'), - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} + array(self::HAS_MANY, 'OrderDetail'), + 'Customer' => array(self::BELONGS_TO, 'Customer'), + 'Shipper' => array(self::BELONGS_TO, 'Shipper'), + 'Employee' => array(self::BELONGS_TO, 'Employee'), + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} ?> \ No newline at end of file diff --git a/demos/northwind-db/protected/database/OrderDetail.php b/demos/northwind-db/protected/database/OrderDetail.php index 1732b0d9..47f77351 100644 --- a/demos/northwind-db/protected/database/OrderDetail.php +++ b/demos/northwind-db/protected/database/OrderDetail.php @@ -1,27 +1,27 @@ - array(self::BELONGS_TO, 'Product'), - 'Order' => array(self::BELONGS_TO, 'Order'), - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} + array(self::BELONGS_TO, 'Product'), + 'Order' => array(self::BELONGS_TO, 'Order'), + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} ?> \ No newline at end of file diff --git a/demos/northwind-db/protected/database/Product.php b/demos/northwind-db/protected/database/Product.php index 93736ab8..088fbbd2 100644 --- a/demos/northwind-db/protected/database/Product.php +++ b/demos/northwind-db/protected/database/Product.php @@ -1,36 +1,36 @@ - array(self::BELONGS_TO, 'Supplier'), - 'Category' => array(self::BELONGS_TO, 'Category'), - 'OrderDetails' => array(self::HAS_MANY, 'OrderDetail'), - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} + array(self::BELONGS_TO, 'Supplier'), + 'Category' => array(self::BELONGS_TO, 'Category'), + 'OrderDetails' => array(self::HAS_MANY, 'OrderDetail'), + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} ?> \ No newline at end of file diff --git a/demos/northwind-db/protected/database/Region.php b/demos/northwind-db/protected/database/Region.php index 3d1c2a84..6473e682 100644 --- a/demos/northwind-db/protected/database/Region.php +++ b/demos/northwind-db/protected/database/Region.php @@ -1,25 +1,25 @@ - array(self::HAS_MANY, 'Territory') - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} + array(self::HAS_MANY, 'Territory') + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} ?> \ No newline at end of file diff --git a/demos/northwind-db/protected/database/Shipper.php b/demos/northwind-db/protected/database/Shipper.php index a3f0aeb3..f90548ea 100644 --- a/demos/northwind-db/protected/database/Shipper.php +++ b/demos/northwind-db/protected/database/Shipper.php @@ -1,25 +1,25 @@ - array(self::HAS_MANY, 'Order'), - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} + array(self::HAS_MANY, 'Order'), + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} ?> \ No newline at end of file diff --git a/demos/northwind-db/protected/database/Supplier.php b/demos/northwind-db/protected/database/Supplier.php index 7cabdde5..bc3b44e0 100644 --- a/demos/northwind-db/protected/database/Supplier.php +++ b/demos/northwind-db/protected/database/Supplier.php @@ -1,34 +1,34 @@ - array(self::HAS_MANY, 'Product') - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} + array(self::HAS_MANY, 'Product') + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} ?> \ No newline at end of file diff --git a/demos/northwind-db/protected/database/Territory.php b/demos/northwind-db/protected/database/Territory.php index 16f33dea..96006bb1 100644 --- a/demos/northwind-db/protected/database/Territory.php +++ b/demos/northwind-db/protected/database/Territory.php @@ -1,60 +1,60 @@ - array(self::BELONGS_TO, 'Region'), - 'Employees' => array(self::HAS_MANY, 'Employee', 'EmployeeTerritories') - ); - - /** - * @return Region - */ - public function getRegion() - { - //lazy load the region - if($this->_region===null) - $this->_region = Region::finder()->findByPk($this->RegionID); - return $this->_region; - } - - public function setRegion($value) - { - $this->_region=$value; - } - - /** - * @return Employee[] - */ - public function getEmployees() - { - //lazy load - if($this->_employees==null) - $this->setEmployees($this->withEmployees()->findByPk($this->TerritoryID)->getEmployees()); - return $this->_employees; - } - - public function setEmployees($value) - { - //ensure TList - $this->_employees = $value instanceof TList ? $value : new TList($value); - } - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} + array(self::BELONGS_TO, 'Region'), + 'Employees' => array(self::HAS_MANY, 'Employee', 'EmployeeTerritories') + ); + + /** + * @return Region + */ + public function getRegion() + { + //lazy load the region + if($this->_region===null) + $this->_region = Region::finder()->findByPk($this->RegionID); + return $this->_region; + } + + public function setRegion($value) + { + $this->_region=$value; + } + + /** + * @return Employee[] + */ + public function getEmployees() + { + //lazy load + if($this->_employees==null) + $this->setEmployees($this->withEmployees()->findByPk($this->TerritoryID)->getEmployees()); + return $this->_employees; + } + + public function setEmployees($value) + { + //ensure TList + $this->_employees = $value instanceof TList ? $value : new TList($value); + } + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} ?> \ No newline at end of file diff --git a/demos/northwind-db/protected/pages/NorthwindCrud.php b/demos/northwind-db/protected/pages/NorthwindCrud.php index 57694caa..72297ac8 100644 --- a/demos/northwind-db/protected/pages/NorthwindCrud.php +++ b/demos/northwind-db/protected/pages/NorthwindCrud.php @@ -1,28 +1,28 @@ -getRecordClassList(Prado::getPathOfNamespace('Application.database.*')); - $this->class_list->dataSource = $classes; - $this->class_list->dataBind(); - } - - protected function getRecordClassList($directory) - { - $list=array(); - $folder=@opendir($directory); - while($entry=@readdir($folder)) - { - if($entry[0]==='.') - continue; - else if(is_file($directory.'/'.$entry) && strpos($entry,'.php')) - $list[] = str_replace('.php', '', $entry); - } - closedir($folder); - return $list; - } -} - +getRecordClassList(Prado::getPathOfNamespace('Application.database.*')); + $this->class_list->dataSource = $classes; + $this->class_list->dataBind(); + } + + protected function getRecordClassList($directory) + { + $list=array(); + $folder=@opendir($directory); + while($entry=@readdir($folder)) + { + if($entry[0]==='.') + continue; + else if(is_file($directory.'/'.$entry) && strpos($entry,'.php')) + $list[] = str_replace('.php', '', $entry); + } + closedir($folder); + return $list; + } +} + ?> \ No newline at end of file diff --git a/demos/personal/index.php b/demos/personal/index.php index 04695b16..1722244d 100644 --- a/demos/personal/index.php +++ b/demos/personal/index.php @@ -1,15 +1,15 @@ -run(); - +run(); + ?> \ No newline at end of file diff --git a/demos/personal/protected/Common/LoginPortlet.php b/demos/personal/protected/Common/LoginPortlet.php index 1f5cd4f5..1b93912b 100644 --- a/demos/personal/protected/Common/LoginPortlet.php +++ b/demos/personal/protected/Common/LoginPortlet.php @@ -1,19 +1,19 @@ -Application->getModule('auth'); - if(!$authManager->login($this->Username->Text,$this->Password->Text)) - $param->IsValid=false; - } - - public function loginButtonClicked($sender,$param) - { - if($this->Page->IsValid) - $this->Response->redirect($this->Application->getModule('auth')->getReturnUrl()); - } -} - +Application->getModule('auth'); + if(!$authManager->login($this->Username->Text,$this->Password->Text)) + $param->IsValid=false; + } + + public function loginButtonClicked($sender,$param) + { + if($this->Page->IsValid) + $this->Response->redirect($this->Application->getModule('auth')->getReturnUrl()); + } +} + ?> \ No newline at end of file diff --git a/demos/personal/protected/Common/MainMenu.php b/demos/personal/protected/Common/MainMenu.php index a2334c03..5e1e95c0 100644 --- a/demos/personal/protected/Common/MainMenu.php +++ b/demos/personal/protected/Common/MainMenu.php @@ -1,12 +1,12 @@ -Application->getModule('auth')->logout(); - $this->Response->redirect($this->Service->constructUrl('Home')); - } -} - +Application->getModule('auth')->logout(); + $this->Response->redirect($this->Service->constructUrl('Home')); + } +} + ?> \ No newline at end of file diff --git a/demos/personal/protected/Pages/Layout.php b/demos/personal/protected/Pages/Layout.php index ba96038b..7f5e5802 100644 --- a/demos/personal/protected/Pages/Layout.php +++ b/demos/personal/protected/Pages/Layout.php @@ -1,7 +1,7 @@ - \ No newline at end of file diff --git a/demos/personal/protected/Pages/Register.php b/demos/personal/protected/Pages/Register.php index b699d859..26f9aa50 100644 --- a/demos/personal/protected/Pages/Register.php +++ b/demos/personal/protected/Pages/Register.php @@ -1,19 +1,19 @@ -IsValid to false if the username is already taken - } - - public function createUser($sender,$param) - { - if($this->IsValid) - { - // create new user account - } - } -} - +IsValid to false if the username is already taken + } + + public function createUser($sender,$param) + { + if($this->IsValid) + { + // create new user account + } + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/index.php b/demos/quickstart/index.php index 43c0b436..6efff1af 100644 --- a/demos/quickstart/index.php +++ b/demos/quickstart/index.php @@ -1,18 +1,18 @@ -run(); - +run(); + ?> \ No newline at end of file diff --git a/demos/quickstart/index2.php b/demos/quickstart/index2.php index f3d8dd90..30df9480 100644 --- a/demos/quickstart/index2.php +++ b/demos/quickstart/index2.php @@ -1,18 +1,18 @@ -run(); - +run(); + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/QuickStartGlobalization.php b/demos/quickstart/protected/QuickStartGlobalization.php index 6a0b0fb2..8fc42e8d 100644 --- a/demos/quickstart/protected/QuickStartGlobalization.php +++ b/demos/quickstart/protected/QuickStartGlobalization.php @@ -1,31 +1,31 @@ -Application->OnBeginRequest[] = array($this, 'beginRequest'); - } - - public function beginRequest($sender, $param) - { - if(null == ($culture=$this->Request['lang'])) - { - if(null !== ($cookie=$this->Request->Cookies['lang'])) - $culture = $cookie->getValue(); - } - - if(is_string($culture)) - { - $info = new CultureInfo(); - if($info->validCulture($culture)) - { - $this->setCulture($culture); - $this->Response->Cookies[] = new THttpCookie('lang',$culture); - } - } - } -} - +Application->OnBeginRequest[] = array($this, 'beginRequest'); + } + + public function beginRequest($sender, $param) + { + if(null == ($culture=$this->Request['lang'])) + { + if(null !== ($cookie=$this->Request->Cookies['lang'])) + $culture = $cookie->getValue(); + } + + if(is_string($culture)) + { + $info = new CultureInfo(); + if($info->validCulture($culture)) + { + $this->setCulture($culture); + $this->Response->Cookies[] = new THttpCookie('lang',$culture); + } + } + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/controls/Comments/CommentBlock.php b/demos/quickstart/protected/controls/Comments/CommentBlock.php index 9c008491..ebb82a0f 100644 --- a/demos/quickstart/protected/controls/Comments/CommentBlock.php +++ b/demos/quickstart/protected/controls/Comments/CommentBlock.php @@ -1,107 +1,107 @@ -setDbConnection($db); - -class CommentRecord extends TActiveRecord -{ - const TABLE='qs_comments'; - - public $id; - public $username; - public $date_added; - public $page; - public $block_id; - public $content; - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} - -class CommentBlock extends TTemplateControl -{ - private $_page; - - function onLoad($param) - { - if(!$this->Page->IsCallBack) - { - $count = array(); - $data = $this->getCommentData(); - foreach($data as $r) - { - if(!isset($count[$r->block_id])) - $count[$r->block_id]=0; - $count[$r->block_id]++; - } - $js = "var comment_count = ".TJavascript::encode($count).";\n"; - $this->Page->ClientScript->registerBeginScript('count',$js); - $this->comments->dataSource = $data; - $this->comments->dataBind(); - } - } - - function getCommentData() - { - return CommentRecord::finder()->findAllByPage($this->getCurrentPagePath()); - } - - function add_comment($sender, $param) - { - if(!$this->Page->IsValid) - return; - $record = new CommentRecord; - $record->username = $this->username->Text; - $record->date_added = date('Y-m-d h:i:s'); - $record->page = $this->getCurrentPagePath(); - $record->block_id = $this->block_id->Value; - $record->content = $this->content->Text; - $record->save(); - - $this->content->Text = ''; - $this->password->Text = ''; - $cc = $this->Page->CallbackClient; - $cc->appendContent('comment-list', $this->format_message($record)); - $cc->callClientFunction('hide_add_comment'); - $cc->callClientFunction('increment_count_tag', $record->block_id); - if(!$this->Page->IsCallBack) - { - $this->comments->dataSource = $this->getCommentData(); - $this->comments->dataBind(); - } - } - - protected function getCurrentPagePath() - { - if(is_null($this->_page)) - { - $page = str_replace($this->Service->BasePath, '', $this->Page->Template->TemplateFile); - $this->_page = str_replace('\\', '/', $page); - } - return $this->_page; - } - - function validate_credential($sender, $param) - { - $param->IsValid = $this->password->Text == 'Prado'; - } - - protected function format_message($record) - { - $username=htmlspecialchars($record->username); - $content=nl2br(htmlspecialchars($record->content)); - return << - {$username} on {$record->date_added}. -
{$content}
- -EOD; - } +setDbConnection($db); + +class CommentRecord extends TActiveRecord +{ + const TABLE='qs_comments'; + + public $id; + public $username; + public $date_added; + public $page; + public $block_id; + public $content; + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} + +class CommentBlock extends TTemplateControl +{ + private $_page; + + function onLoad($param) + { + if(!$this->Page->IsCallBack) + { + $count = array(); + $data = $this->getCommentData(); + foreach($data as $r) + { + if(!isset($count[$r->block_id])) + $count[$r->block_id]=0; + $count[$r->block_id]++; + } + $js = "var comment_count = ".TJavascript::encode($count).";\n"; + $this->Page->ClientScript->registerBeginScript('count',$js); + $this->comments->dataSource = $data; + $this->comments->dataBind(); + } + } + + function getCommentData() + { + return CommentRecord::finder()->findAllByPage($this->getCurrentPagePath()); + } + + function add_comment($sender, $param) + { + if(!$this->Page->IsValid) + return; + $record = new CommentRecord; + $record->username = $this->username->Text; + $record->date_added = date('Y-m-d h:i:s'); + $record->page = $this->getCurrentPagePath(); + $record->block_id = $this->block_id->Value; + $record->content = $this->content->Text; + $record->save(); + + $this->content->Text = ''; + $this->password->Text = ''; + $cc = $this->Page->CallbackClient; + $cc->appendContent('comment-list', $this->format_message($record)); + $cc->callClientFunction('hide_add_comment'); + $cc->callClientFunction('increment_count_tag', $record->block_id); + if(!$this->Page->IsCallBack) + { + $this->comments->dataSource = $this->getCommentData(); + $this->comments->dataBind(); + } + } + + protected function getCurrentPagePath() + { + if(is_null($this->_page)) + { + $page = str_replace($this->Service->BasePath, '', $this->Page->Template->TemplateFile); + $this->_page = str_replace('\\', '/', $page); + } + return $this->_page; + } + + function validate_credential($sender, $param) + { + $param->IsValid = $this->password->Text == 'Prado'; + } + + protected function format_message($record) + { + $username=htmlspecialchars($record->username); + $content=nl2br(htmlspecialchars($record->content)); + return << + {$username} on {$record->date_added}. +
{$content}
+ +EOD; + } } \ No newline at end of file diff --git a/demos/quickstart/protected/controls/Comments/comments.js b/demos/quickstart/protected/controls/Comments/comments.js index ca3f54fb..44464689 100644 --- a/demos/quickstart/protected/controls/Comments/comments.js +++ b/demos/quickstart/protected/controls/Comments/comments.js @@ -1,207 +1,207 @@ -var currentCommentID; - -function show_comment_list() -{ - $('comment-list').show(); - $('add-comment').hide(); - $('show-comment-link').addClassName("active"); - $('add-comment-link').removeClassName("active"); - $('all-comments-link').removeClassName("active"); - show_comments_in_list(currentCommentID); -} - -function show_all_comments() -{ - $('comment-list').show(); - $('add-comment').hide(); - $('show-comment-link').removeClassName("active"); - $('add-comment-link').removeClassName("active"); - $('all-comments-link').addClassName("active"); - show_comments_in_list(); -} - - -function show_add_comment() -{ - $('comment-list').hide(); - $('add-comment').show(); - $('show-comment-link').removeClassName("active"); - $('add-comment-link').addClassName("active"); - $('all-comments-link').removeClassName("active"); -} - -function hide_add_comment() -{ - $('user-comments').hide(); - $('modal-background').hide(); - $(content_textare_id).value = ''; - $(currentCommentID).style.zIndex = 0; -} - -function show_comments_in_list(id) -{ - var list = $('comment-list'); - var count=0; - for(var i=0, k=list.childNodes.length; i < k; i++) - { - var node = list.childNodes[i]; - if(node.nodeType == 1) //an element node - { - if(typeof(id) == "undefined" || node.className.indexOf(id) >= 0) - { - node.style.display="block" - count++; - } - else - node.style.display="none"; - } - } - return count; -} - -function show_comments(block) -{ - var id = block.id - currentCommentID = id; - $(hidden_block_id).value = id; - var commentBlock = $('user-comments'); - var pos = Position.cumulativeOffset(block); - var top = pos[1] + block.offsetHeight; - commentBlock.style.top = top+"px"; - commentBlock.style.width = (block.offsetWidth-22)+"px"; - - commentBlock.show(); - - var count = show_comments_in_list(id); - - $('comment-list').show(); - if(count > 0) - show_comment_list(); - else - show_add_comment(); - - var background = $('modal-background'); - background.style.top="0px"; - background.style.left="0px"; - background.style.opacity="0.5"; - background.style.width = document.body.offsetWidth+"px"; - background.style.height = document.body.offsetHeight+"px"; - background.show(); - block.style.zIndex = 100; - block.style.paddingRight="9px"; - block.style.marginRight="-9px"; - -} - -function show_block(block) -{ - while(block && (!block.className || block.className.indexOf("block-content") < 0)) - block = block.parentNode; - if(block && block.className.indexOf("block-content") >= 0) - { - block.addClassName('block-hover'); - var tag = $('tag-'+block.id); -// if(tag.className.indexOf("tag-shown")<=0) - tag.firstChild.style.visibility="visible" - } -} - -function hide_block(block) -{ - while(block && (!block.className || block.className.indexOf("block-content") < 0)) - block = block.parentNode; - if(block && block.className.indexOf("block-hover") >= 0) - { - block.removeClassName('block-hover'); - var tag = $('tag-'+block.id); - if(tag.className.indexOf("tag-shown")<=0) - tag.firstChild.style.visibility="hidden" - } -} - -function add_comment_tag(el) -{ - var dim = Element.getDimensions(el); - var comments = get_comment_count(el.id); - var style = "height:"+(dim.height > 35 ? dim.height : 35)+"px;"; - var cssClass = dim.height ? "block-comment-tag" : "block-comment-tag-ie"; - var title = "View "+comments+" comments" - var innerStyle=""; - if(comments <= 0) - { - innerStyle = " visibility:hidden;"; - comments = "add"; - title = "Add new comment"; - } - else - cssClass += " tag-shown"; - var id = "tag-"+el.id; - var tag = "
"+comments+"
 
"; - new Insertion.Before(el, tag); - var tag_div = $(id); - Event.observe(tag_div, "mouseover", function(e){ if(typeof(show_block)!="undefined") show_block(el); }); - Event.observe(tag_div, "mouseout", function(e){ if(typeof(hide_block) !="undefined") hide_block(el); }); - Event.observe(tag_div, "click", function(e) { if(typeof(show_comments) !="undefined") show_comments(el); Event.stop(e); }); -} - -function increment_count_tag(id) -{ - var tag = $('tag-'+id); - if(tag && tag.firstChild) - { - if(tag.className.indexOf("tag-shown") >= 0) - { - var count = Number(tag.firstChild.innerHTML); - tag.firstChild.innerHTML = (++count)+""; - tag.firstChild.style.visibility="visible"; - } - else - { - tag.firstChild.innerHTML = "1"; - tag.addClassName("tag-shown"); - tag.firstChild.style.visibility="visible"; - } - } -} - -function get_comment_count(id) -{ - return comment_count[id] ? comment_count[id] : 0; -} - -//initialize the comment js - -if(!Prado.Browser.ie) //not IE 4,5,6 -{ - (function() - { - var userComments = $('user-comments'); - userComments.style.position="absolute"; - userComments.style.marginRight="80px"; - var commentList = $('comment-list'); - commentList.style.height="320px"; - $('add-comment').style.height="320px"; - commentList.style.overflow="auto"; - $('show-comment-link').style.display=""; - $('to-top').hide(); - $('close-comments').show(); - $('all-comments-link').show(); - userComments.hide(); - $('comments-header').hide(); - - $$('#comment-list .source-link').each(function(el){ el.hide(); }); - - $$('#content .block-content').each(function(el) - { - Event.observe(el, 'mouseover', function(e){ if(typeof(show_block)!="undefined") show_block(Event.element(e)); }); - Event.observe(el, 'mouseout', function(e){ if(typeof(hide_block)!="undefined") hide_block(Event.element(e)); }); - add_comment_tag(el); - }); - - Event.observe($('show-comment-link'), "click", function(e) { show_comment_list(); Event.stop(e); }); - Event.observe($('add-comment-link'), "click", function(e) { show_add_comment(); Event.stop(e); }); - Event.observe($('all-comments-link'), "click", function(e) { show_all_comments(); Event.stop(e); }); - Event.observe($('close-comments'), "click", function(e) { hide_add_comment(); Event.stop(e); }); - - })(); +var currentCommentID; + +function show_comment_list() +{ + $('comment-list').show(); + $('add-comment').hide(); + $('show-comment-link').addClassName("active"); + $('add-comment-link').removeClassName("active"); + $('all-comments-link').removeClassName("active"); + show_comments_in_list(currentCommentID); +} + +function show_all_comments() +{ + $('comment-list').show(); + $('add-comment').hide(); + $('show-comment-link').removeClassName("active"); + $('add-comment-link').removeClassName("active"); + $('all-comments-link').addClassName("active"); + show_comments_in_list(); +} + + +function show_add_comment() +{ + $('comment-list').hide(); + $('add-comment').show(); + $('show-comment-link').removeClassName("active"); + $('add-comment-link').addClassName("active"); + $('all-comments-link').removeClassName("active"); +} + +function hide_add_comment() +{ + $('user-comments').hide(); + $('modal-background').hide(); + $(content_textare_id).value = ''; + $(currentCommentID).style.zIndex = 0; +} + +function show_comments_in_list(id) +{ + var list = $('comment-list'); + var count=0; + for(var i=0, k=list.childNodes.length; i < k; i++) + { + var node = list.childNodes[i]; + if(node.nodeType == 1) //an element node + { + if(typeof(id) == "undefined" || node.className.indexOf(id) >= 0) + { + node.style.display="block" + count++; + } + else + node.style.display="none"; + } + } + return count; +} + +function show_comments(block) +{ + var id = block.id + currentCommentID = id; + $(hidden_block_id).value = id; + var commentBlock = $('user-comments'); + var pos = Position.cumulativeOffset(block); + var top = pos[1] + block.offsetHeight; + commentBlock.style.top = top+"px"; + commentBlock.style.width = (block.offsetWidth-22)+"px"; + + commentBlock.show(); + + var count = show_comments_in_list(id); + + $('comment-list').show(); + if(count > 0) + show_comment_list(); + else + show_add_comment(); + + var background = $('modal-background'); + background.style.top="0px"; + background.style.left="0px"; + background.style.opacity="0.5"; + background.style.width = document.body.offsetWidth+"px"; + background.style.height = document.body.offsetHeight+"px"; + background.show(); + block.style.zIndex = 100; + block.style.paddingRight="9px"; + block.style.marginRight="-9px"; + +} + +function show_block(block) +{ + while(block && (!block.className || block.className.indexOf("block-content") < 0)) + block = block.parentNode; + if(block && block.className.indexOf("block-content") >= 0) + { + block.addClassName('block-hover'); + var tag = $('tag-'+block.id); +// if(tag.className.indexOf("tag-shown")<=0) + tag.firstChild.style.visibility="visible" + } +} + +function hide_block(block) +{ + while(block && (!block.className || block.className.indexOf("block-content") < 0)) + block = block.parentNode; + if(block && block.className.indexOf("block-hover") >= 0) + { + block.removeClassName('block-hover'); + var tag = $('tag-'+block.id); + if(tag.className.indexOf("tag-shown")<=0) + tag.firstChild.style.visibility="hidden" + } +} + +function add_comment_tag(el) +{ + var dim = Element.getDimensions(el); + var comments = get_comment_count(el.id); + var style = "height:"+(dim.height > 35 ? dim.height : 35)+"px;"; + var cssClass = dim.height ? "block-comment-tag" : "block-comment-tag-ie"; + var title = "View "+comments+" comments" + var innerStyle=""; + if(comments <= 0) + { + innerStyle = " visibility:hidden;"; + comments = "add"; + title = "Add new comment"; + } + else + cssClass += " tag-shown"; + var id = "tag-"+el.id; + var tag = "
"+comments+"
 
"; + new Insertion.Before(el, tag); + var tag_div = $(id); + Event.observe(tag_div, "mouseover", function(e){ if(typeof(show_block)!="undefined") show_block(el); }); + Event.observe(tag_div, "mouseout", function(e){ if(typeof(hide_block) !="undefined") hide_block(el); }); + Event.observe(tag_div, "click", function(e) { if(typeof(show_comments) !="undefined") show_comments(el); Event.stop(e); }); +} + +function increment_count_tag(id) +{ + var tag = $('tag-'+id); + if(tag && tag.firstChild) + { + if(tag.className.indexOf("tag-shown") >= 0) + { + var count = Number(tag.firstChild.innerHTML); + tag.firstChild.innerHTML = (++count)+""; + tag.firstChild.style.visibility="visible"; + } + else + { + tag.firstChild.innerHTML = "1"; + tag.addClassName("tag-shown"); + tag.firstChild.style.visibility="visible"; + } + } +} + +function get_comment_count(id) +{ + return comment_count[id] ? comment_count[id] : 0; +} + +//initialize the comment js + +if(!Prado.Browser.ie) //not IE 4,5,6 +{ + (function() + { + var userComments = $('user-comments'); + userComments.style.position="absolute"; + userComments.style.marginRight="80px"; + var commentList = $('comment-list'); + commentList.style.height="320px"; + $('add-comment').style.height="320px"; + commentList.style.overflow="auto"; + $('show-comment-link').style.display=""; + $('to-top').hide(); + $('close-comments').show(); + $('all-comments-link').show(); + userComments.hide(); + $('comments-header').hide(); + + $$('#comment-list .source-link').each(function(el){ el.hide(); }); + + $$('#content .block-content').each(function(el) + { + Event.observe(el, 'mouseover', function(e){ if(typeof(show_block)!="undefined") show_block(Event.element(e)); }); + Event.observe(el, 'mouseout', function(e){ if(typeof(hide_block)!="undefined") hide_block(Event.element(e)); }); + add_comment_tag(el); + }); + + Event.observe($('show-comment-link'), "click", function(e) { show_comment_list(); Event.stop(e); }); + Event.observe($('add-comment-link'), "click", function(e) { show_add_comment(); Event.stop(e); }); + Event.observe($('all-comments-link'), "click", function(e) { show_all_comments(); Event.stop(e); }); + Event.observe($('close-comments'), "click", function(e) { hide_add_comment(); Event.stop(e); }); + + })(); } \ No newline at end of file diff --git a/demos/quickstart/protected/controls/DocLink.php b/demos/quickstart/protected/controls/DocLink.php index e8ca7dfa..12b8e898 100644 --- a/demos/quickstart/protected/controls/DocLink.php +++ b/demos/quickstart/protected/controls/DocLink.php @@ -1,31 +1,31 @@ -getViewState('ClassPath',''); - } - - public function setClassPath($value) - { - $this->setViewState('ClassPath',$value,''); - } - - public function onPreRender($param) - { - parent::onPreRender($param); - $paths=explode('.',$this->getClassPath()); - if(count($paths)>1) - { - $classFile=array_pop($paths).'.html'; - $this->setNavigateUrl(self::BASE_URL . '/' . implode('.',$paths) . '/' . $classFile); - if($this->getText() === '') - $this->setText('API Manual'); - } - } -} - +getViewState('ClassPath',''); + } + + public function setClassPath($value) + { + $this->setViewState('ClassPath',$value,''); + } + + public function onPreRender($param) + { + parent::onPreRender($param); + $paths=explode('.',$this->getClassPath()); + if(count($paths)>1) + { + $classFile=array_pop($paths).'.html'; + $this->setNavigateUrl(self::BASE_URL . '/' . implode('.',$paths) . '/' . $classFile); + if($this->getText() === '') + $this->setText('API Manual'); + } + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/controls/Layout.php b/demos/quickstart/protected/controls/Layout.php index 3973db8f..5106a72b 100644 --- a/demos/quickstart/protected/controls/Layout.php +++ b/demos/quickstart/protected/controls/Layout.php @@ -1,48 +1,48 @@ -Request['notheme'])) - $this->Service->RequestedPage->EnableTheming=false; - parent::__construct(); - } - - public function onLoad($param) - { - parent::onLoad($param); - $url=$this->Request->RequestUri; - if(strpos($url,'?')===false) - $url.='?notheme=true'; - else - $url.='&notheme=true'; - $this->PrinterLink->NavigateUrl=$url; - - if(isset($this->Request['notheme'])) - { - $this->MainMenu->Visible=false; - $this->TopicPanel->Visible=false; - } - - $this->languages->DataSource = TPropertyValue::ensureArray($this->Application->Parameters['languages']); - $this->languages->dataBind(); - } - - public function languageLinkCreated($sender, $param) - { - $item = $param->Item; - if($item->ItemType == TListItemType::Item || $item->ItemType == TListItemType::AlternatingItem) - { - $params = $this->Request->toArray(); - $params['lang'] = $sender->DataKeys[$item->ItemIndex]; - unset($params[$this->Request->ServiceID]); - $url = $this->Service->ConstructUrl($this->Service->RequestedPagePath, $params); - $item->link->NavigateUrl = $url; - if($this->Application->Globalization->Culture == $params['lang']) - $item->link->CssClass="active"; - } - } -} - +Request['notheme'])) + $this->Service->RequestedPage->EnableTheming=false; + parent::__construct(); + } + + public function onLoad($param) + { + parent::onLoad($param); + $url=$this->Request->RequestUri; + if(strpos($url,'?')===false) + $url.='?notheme=true'; + else + $url.='&notheme=true'; + $this->PrinterLink->NavigateUrl=$url; + + if(isset($this->Request['notheme'])) + { + $this->MainMenu->Visible=false; + $this->TopicPanel->Visible=false; + } + + $this->languages->DataSource = TPropertyValue::ensureArray($this->Application->Parameters['languages']); + $this->languages->dataBind(); + } + + public function languageLinkCreated($sender, $param) + { + $item = $param->Item; + if($item->ItemType == TListItemType::Item || $item->ItemType == TListItemType::AlternatingItem) + { + $params = $this->Request->toArray(); + $params['lang'] = $sender->DataKeys[$item->ItemIndex]; + unset($params[$this->Request->ServiceID]); + $url = $this->Service->ConstructUrl($this->Service->RequestedPagePath, $params); + $item->link->NavigateUrl = $url; + if($this->Application->Globalization->Culture == $params['lang']) + $item->link->CssClass="active"; + } + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/controls/RequiresVersion.php b/demos/quickstart/protected/controls/RequiresVersion.php index 9e598d3a..c5dc37ec 100644 --- a/demos/quickstart/protected/controls/RequiresVersion.php +++ b/demos/quickstart/protected/controls/RequiresVersion.php @@ -1,16 +1,16 @@ -setViewState('Version',$value); - } - - public function getVersion() - { - return $this->getViewState('Version'); - } -} - +setViewState('Version',$value); + } + + public function getVersion() + { + return $this->getViewState('Version'); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/controls/RunBar.php b/demos/quickstart/protected/controls/RunBar.php index 8990c4c3..4db016be 100644 --- a/demos/quickstart/protected/controls/RunBar.php +++ b/demos/quickstart/protected/controls/RunBar.php @@ -1,23 +1,23 @@ -getViewState('PagePath',''); - } - - public function setPagePath($value) - { - $this->setViewState('PagePath',$value,''); - } - - public function onPreRender($param) - { - $pagePath=$this->getPagePath(); - $this->RunButton->NavigateUrl="?page=$pagePath"; - $this->ViewSourceButton->NavigateUrl="?page=ViewSource&path=/".strtr($pagePath,'.','/').'.page'; - } -} - +getViewState('PagePath',''); + } + + public function setPagePath($value) + { + $this->setViewState('PagePath',$value,''); + } + + public function onPreRender($param) + { + $pagePath=$this->getPagePath(); + $this->RunButton->NavigateUrl="?page=$pagePath"; + $this->ViewSourceButton->NavigateUrl="?page=ViewSource&path=/".strtr($pagePath,'.','/').'.page'; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/controls/SampleLayout.php b/demos/quickstart/protected/controls/SampleLayout.php index a89b905d..a2d6f658 100644 --- a/demos/quickstart/protected/controls/SampleLayout.php +++ b/demos/quickstart/protected/controls/SampleLayout.php @@ -1,13 +1,13 @@ -Request['notheme'])) - $this->Service->RequestedPage->EnableTheming=false; - parent::__construct(); - } -} - +Request['notheme'])) + $this->Service->RequestedPage->EnableTheming=false; + parent::__construct(); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/controls/SearchBox.php b/demos/quickstart/protected/controls/SearchBox.php index 2e74ae31..e13d5e46 100644 --- a/demos/quickstart/protected/controls/SearchBox.php +++ b/demos/quickstart/protected/controls/SearchBox.php @@ -1,41 +1,41 @@ -ensureChildControls(); - return $this->getRegisteredObject('search')->getText(); - } - - public function getTextBox() - { - $this->ensureChildControls(); - return $this->getRegisteredObject('search'); - } - - public function getButton() - { - $this->ensureChildControls(); - return $this->getRegisteredObject('find'); - } - - public function onInit($param) - { - parent::onInit($param); - if(strlen($q = $this->Page->Request['q']) > 0) - $this->search->setText($q); - } - - public function doSearch($sender, $param) - { - if(strlen($query = $this->search->getText()) >0) - { - $ps = $this->getApplication()->getService(); - $page = $ps->constructUrl('Search', array('q' => $query), false); - $this->getApplication()->getResponse()->redirect($page); - } - } -} - +ensureChildControls(); + return $this->getRegisteredObject('search')->getText(); + } + + public function getTextBox() + { + $this->ensureChildControls(); + return $this->getRegisteredObject('search'); + } + + public function getButton() + { + $this->ensureChildControls(); + return $this->getRegisteredObject('find'); + } + + public function onInit($param) + { + parent::onInit($param); + if(strlen($q = $this->Page->Request['q']) > 0) + $this->search->setText($q); + } + + public function doSearch($sender, $param) + { + if(strlen($query = $this->search->getText()) >0) + { + $ps = $this->getApplication()->getService(); + $page = $ps->constructUrl('Search', array('q' => $query), false); + $this->getApplication()->getResponse()->redirect($page); + } + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/controls/SinceVersion.php b/demos/quickstart/protected/controls/SinceVersion.php index cfeeffbb..db73275b 100644 --- a/demos/quickstart/protected/controls/SinceVersion.php +++ b/demos/quickstart/protected/controls/SinceVersion.php @@ -1,16 +1,16 @@ -setViewState('Version',$value); - } - - public function getVersion() - { - return $this->getViewState('Version'); - } -} - +setViewState('Version',$value); + } + + public function getVersion() + { + return $this->getViewState('Version'); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/controls/TopicList.php b/demos/quickstart/protected/controls/TopicList.php index ce827cc0..eb5976a9 100644 --- a/demos/quickstart/protected/controls/TopicList.php +++ b/demos/quickstart/protected/controls/TopicList.php @@ -1,8 +1,8 @@ - \ No newline at end of file diff --git a/demos/quickstart/protected/index/ZendSearch.php b/demos/quickstart/protected/index/ZendSearch.php index ec15729c..70aef414 100644 --- a/demos/quickstart/protected/index/ZendSearch.php +++ b/demos/quickstart/protected/index/ZendSearch.php @@ -1,55 +1,55 @@ -_data = Prado::getPathOfNamespace($path); - } - - public function getIndexDataDirectory() - { - return $this->_data; - } - - public function setZendFramework($path) - { - $this->_ZF = Prado::getPathOfNamespace($path); - } - - protected function importZendNamespace() - { - if(is_null(Prado::getPathOfAlias('Zend'))) - { - $zendBase = !is_null($this->_ZF) ? $this->_ZF.'.*' : 'Application.index.*'; - $path = !is_null($this->_ZF) ? $this->_ZF.'.Zend.*' : 'Application.index.Zend.*'; - Prado::using($zendBase); - Prado::setPathOfAlias('Zend', Prado::getPathOfNamespace($path)); - } - } - - protected function getZendSearch() - { - if(is_null($this->_search)) - { - $this->importZendNamespace(); - Prado::using('Zend.Search.Lucene'); - $this->_search = new Zend_Search_Lucene($this->_data); - } - return $this->_search; - } - - public function find($query) - { - return $this->getZendSearch()->find(strtolower($query)); - } -} - +_data = Prado::getPathOfNamespace($path); + } + + public function getIndexDataDirectory() + { + return $this->_data; + } + + public function setZendFramework($path) + { + $this->_ZF = Prado::getPathOfNamespace($path); + } + + protected function importZendNamespace() + { + if(is_null(Prado::getPathOfAlias('Zend'))) + { + $zendBase = !is_null($this->_ZF) ? $this->_ZF.'.*' : 'Application.index.*'; + $path = !is_null($this->_ZF) ? $this->_ZF.'.Zend.*' : 'Application.index.Zend.*'; + Prado::using($zendBase); + Prado::setPathOfAlias('Zend', Prado::getPathOfNamespace($path)); + } + } + + protected function getZendSearch() + { + if(is_null($this->_search)) + { + $this->importZendNamespace(); + Prado::using('Zend.Search.Lucene'); + $this->_search = new Zend_Search_Lucene($this->_data); + } + return $this->_search; + } + + public function find($query) + { + return $this->getZendSearch()->find(strtolower($query)); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveButton/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveButton/Home.php index 4a4e23ca..e3afdaae 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveButton/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveButton/Home.php @@ -1,20 +1,20 @@ -Text="Name: {$param->CommandName}, Param: {$param->CommandParameter}"; - else - $sender->Text="I'm clicked"; - } - - public function buttonCallback($sender, $param) - { - $sender->Text .= ' using callback'; - } -} - +Text="Name: {$param->CommandName}, Param: {$param->CommandParameter}"; + else + $sender->Text="I'm clicked"; + } + + public function buttonCallback($sender, $param) + { + $sender->Text .= ' using callback'; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveCheckBox/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveCheckBox/Home.php index f0543695..5a73a6f4 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveCheckBox/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveCheckBox/Home.php @@ -1,16 +1,16 @@ -Text= $sender->ClientID . " clicked"; - } - - public function checkboxCallback($sender, $param) - { - $sender->Text .= ' using callback'; - } -} - +Text= $sender->ClientID . " clicked"; + } + + public function checkboxCallback($sender, $param) + { + $sender->Text .= ' using callback'; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveCheckBoxList/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveCheckBoxList/Home.php index 3644721e..b9060163 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveCheckBoxList/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveCheckBoxList/Home.php @@ -1,26 +1,26 @@ -SelectedIndices; - $result=''; - foreach($indices as $index) - { - $item=$input->Items[$index]; - $result.="(Index: $index, Value: $item->Value, Text: $item->Text)"; - } - if($result==='') - $output->Text='Your selection is empty.'; - else - $output->Text='Your selection is: '.$result; - } - - public function selectionChanged($sender,$param) - { - $this->collectSelectionResult($this->CheckBoxList,$this->SelectionResult); - } -} - +SelectedIndices; + $result=''; + foreach($indices as $index) + { + $item=$input->Items[$index]; + $result.="(Index: $index, Value: $item->Value, Text: $item->Text)"; + } + if($result==='') + $output->Text='Your selection is empty.'; + else + $output->Text='Your selection is: '.$result; + } + + public function selectionChanged($sender,$param) + { + $this->collectSelectionResult($this->CheckBoxList,$this->SelectionResult); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveCustomValidator/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveCustomValidator/Home.php index 102afcb0..c668c86d 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveCustomValidator/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveCustomValidator/Home.php @@ -1,11 +1,11 @@ -IsValid = $this->textbox1->Text == 'Prado'; - } -} - +IsValid = $this->textbox1->Text == 'Prado'; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample1.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample1.php index ada1ee6e..43d645ab 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample1.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample1.php @@ -1,37 +1,37 @@ -'ITN001','name'=>'Motherboard','quantity'=>1,'price'=>100.00,'imported'=>true), - array('id'=>'ITN002','name'=>'CPU','quantity'=>1,'price'=>150.00,'imported'=>true), - array('id'=>'ITN003','name'=>'Harddrive','quantity'=>2,'price'=>80.00,'imported'=>true), - array('id'=>'ITN004','name'=>'Sound card','quantity'=>1,'price'=>40.00,'imported'=>false), - array('id'=>'ITN005','name'=>'Video card','quantity'=>1,'price'=>150.00,'imported'=>true), - array('id'=>'ITN006','name'=>'Keyboard','quantity'=>1,'price'=>20.00,'imported'=>false), - array('id'=>'ITN007','name'=>'Monitor','quantity'=>2,'price'=>300.00,'imported'=>true), - array('id'=>'ITN008','name'=>'CDRW drive','quantity'=>1,'price'=>40.00,'imported'=>true), - array('id'=>'ITN009','name'=>'Cooling fan','quantity'=>2,'price'=>10.00,'imported'=>false), - array('id'=>'ITN010','name'=>'Video camera','quantity'=>20,'price'=>30.00,'imported'=>true), - array('id'=>'ITN011','name'=>'Card reader','quantity'=>10,'price'=>24.00,'imported'=>true), - array('id'=>'ITN012','name'=>'Floppy drive','quantity'=>50,'price'=>12.00,'imported'=>false), - array('id'=>'ITN013','name'=>'CD drive','quantity'=>25,'price'=>20.00,'imported'=>true), - array('id'=>'ITN014','name'=>'DVD drive','quantity'=>15,'price'=>80.00,'imported'=>true), - array('id'=>'ITN015','name'=>'Mouse pad','quantity'=>50,'price'=>5.00,'imported'=>false), - array('id'=>'ITN016','name'=>'Network cable','quantity'=>40,'price'=>8.00,'imported'=>true), - array('id'=>'ITN017','name'=>'Case','quantity'=>8,'price'=>65.00,'imported'=>false), - array('id'=>'ITN018','name'=>'Surge protector','quantity'=>45,'price'=>15.00,'imported'=>false), - array('id'=>'ITN019','name'=>'Speaker','quantity'=>35,'price'=>65.00,'imported'=>false), - ); - } - - public function buttonClicked($sender, $param) - { - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } -} - +'ITN001','name'=>'Motherboard','quantity'=>1,'price'=>100.00,'imported'=>true), + array('id'=>'ITN002','name'=>'CPU','quantity'=>1,'price'=>150.00,'imported'=>true), + array('id'=>'ITN003','name'=>'Harddrive','quantity'=>2,'price'=>80.00,'imported'=>true), + array('id'=>'ITN004','name'=>'Sound card','quantity'=>1,'price'=>40.00,'imported'=>false), + array('id'=>'ITN005','name'=>'Video card','quantity'=>1,'price'=>150.00,'imported'=>true), + array('id'=>'ITN006','name'=>'Keyboard','quantity'=>1,'price'=>20.00,'imported'=>false), + array('id'=>'ITN007','name'=>'Monitor','quantity'=>2,'price'=>300.00,'imported'=>true), + array('id'=>'ITN008','name'=>'CDRW drive','quantity'=>1,'price'=>40.00,'imported'=>true), + array('id'=>'ITN009','name'=>'Cooling fan','quantity'=>2,'price'=>10.00,'imported'=>false), + array('id'=>'ITN010','name'=>'Video camera','quantity'=>20,'price'=>30.00,'imported'=>true), + array('id'=>'ITN011','name'=>'Card reader','quantity'=>10,'price'=>24.00,'imported'=>true), + array('id'=>'ITN012','name'=>'Floppy drive','quantity'=>50,'price'=>12.00,'imported'=>false), + array('id'=>'ITN013','name'=>'CD drive','quantity'=>25,'price'=>20.00,'imported'=>true), + array('id'=>'ITN014','name'=>'DVD drive','quantity'=>15,'price'=>80.00,'imported'=>true), + array('id'=>'ITN015','name'=>'Mouse pad','quantity'=>50,'price'=>5.00,'imported'=>false), + array('id'=>'ITN016','name'=>'Network cable','quantity'=>40,'price'=>8.00,'imported'=>true), + array('id'=>'ITN017','name'=>'Case','quantity'=>8,'price'=>65.00,'imported'=>false), + array('id'=>'ITN018','name'=>'Surge protector','quantity'=>45,'price'=>15.00,'imported'=>false), + array('id'=>'ITN019','name'=>'Speaker','quantity'=>35,'price'=>65.00,'imported'=>false), + ); + } + + public function buttonClicked($sender, $param) + { + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample2.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample2.php index 3831582d..10a37e0a 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample2.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample2.php @@ -1,86 +1,86 @@ -'0596007124', - 'title'=>'Head First Design Patterns', - 'publisher'=>'O\'Reilly Media, Inc.', - 'price'=>29.67, - 'instock'=>true, - 'rating'=>4, - ), - array( - 'ISBN'=>'0201633612', - 'title'=>'Design Patterns: Elements of Reusable Object-Oriented Software', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>47.04, - 'instock'=>true, - 'rating'=>5, - ), - array( - 'ISBN'=>'0321247140', - 'title'=>'Design Patterns Explained : A New Perspective on Object-Oriented Design', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>37.49, - 'instock'=>true, - 'rating'=>4, - ), - array( - 'ISBN'=>'0201485672', - 'title'=>'Refactoring: Improving the Design of Existing Code', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>47.14, - 'instock'=>true, - 'rating'=>3, - ), - array( - 'ISBN'=>'0321213351', - 'title'=>'Refactoring to Patterns', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>38.49, - 'instock'=>true, - 'rating'=>2, - ), - array( - 'ISBN'=>'0735619670', - 'title'=>'Code Complete', - 'publisher'=>'Microsoft Press', - 'price'=>32.99, - 'instock'=>false, - 'rating'=>4, - ), - array( - 'ISBN'=>'0321278658', - 'title'=>'Extreme Programming Explained : Embrace Change', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>34.99, - 'instock'=>true, - 'rating'=>3, - ), - ); - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack && !$this->IsCallBack) - { - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } - } - - public function toggleColumnVisibility($sender,$param) - { - foreach($this->DataGrid->Columns as $index=>$column) - $column->Visible=$sender->Items[$index]->Selected; - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } -} - +'0596007124', + 'title'=>'Head First Design Patterns', + 'publisher'=>'O\'Reilly Media, Inc.', + 'price'=>29.67, + 'instock'=>true, + 'rating'=>4, + ), + array( + 'ISBN'=>'0201633612', + 'title'=>'Design Patterns: Elements of Reusable Object-Oriented Software', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>47.04, + 'instock'=>true, + 'rating'=>5, + ), + array( + 'ISBN'=>'0321247140', + 'title'=>'Design Patterns Explained : A New Perspective on Object-Oriented Design', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>37.49, + 'instock'=>true, + 'rating'=>4, + ), + array( + 'ISBN'=>'0201485672', + 'title'=>'Refactoring: Improving the Design of Existing Code', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>47.14, + 'instock'=>true, + 'rating'=>3, + ), + array( + 'ISBN'=>'0321213351', + 'title'=>'Refactoring to Patterns', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>38.49, + 'instock'=>true, + 'rating'=>2, + ), + array( + 'ISBN'=>'0735619670', + 'title'=>'Code Complete', + 'publisher'=>'Microsoft Press', + 'price'=>32.99, + 'instock'=>false, + 'rating'=>4, + ), + array( + 'ISBN'=>'0321278658', + 'title'=>'Extreme Programming Explained : Embrace Change', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>34.99, + 'instock'=>true, + 'rating'=>3, + ), + ); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack && !$this->IsCallBack) + { + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + } + + public function toggleColumnVisibility($sender,$param) + { + foreach($this->DataGrid->Columns as $index=>$column) + $column->Visible=$sender->Items[$index]->Selected; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample3.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample3.php index 9768ca31..5e2fb355 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample3.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample3.php @@ -1,190 +1,190 @@ -_data===null) - $this->loadData(); - return $this->_data; - } - - protected function loadData() - { - // We use viewstate keep track of data. - // In real applications, data should come from database using an SQL SELECT statement. - // In the following tabular data, field 'ISBN' is the primary key. - // All update and delete operations should come with an 'id' value in order to go through. - if(($this->_data=$this->getViewState('Data',null))===null) - { - $this->_data=array( - array( - 'ISBN'=>'0596007124', - 'title'=>'Head First Design Patterns', - 'publisher'=>'O\'Reilly Media, Inc.', - 'price'=>29.67, - 'instock'=>true, - 'rating'=>4, - ), - array( - 'ISBN'=>'0201633612', - 'title'=>'Design Patterns: Elements of Reusable Object-Oriented Software', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>47.04, - 'instock'=>true, - 'rating'=>5, - ), - array( - 'ISBN'=>'0321247140', - 'title'=>'Design Patterns Explained : A New Perspective on Object-Oriented Design', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>37.49, - 'instock'=>true, - 'rating'=>4, - ), - array( - 'ISBN'=>'0201485672', - 'title'=>'Refactoring: Improving the Design of Existing Code', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>47.14, - 'instock'=>true, - 'rating'=>3, - ), - array( - 'ISBN'=>'0321213351', - 'title'=>'Refactoring to Patterns', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>38.49, - 'instock'=>true, - 'rating'=>2, - ), - array( - 'ISBN'=>'0735619670', - 'title'=>'Code Complete', - 'publisher'=>'Microsoft Press', - 'price'=>32.99, - 'instock'=>false, - 'rating'=>4, - ), - array( - 'ISBN'=>'0321278658 ', - 'title'=>'Extreme Programming Explained : Embrace Change', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>34.99, - 'instock'=>true, - 'rating'=>3, - ), - ); - $this->saveData(); - } - } - - protected function saveData() - { - $this->setViewState('Data',$this->_data); - } - - protected function updateBook($isbn,$title,$publisher,$price,$instock,$rating) - { - // In real applications, data should be saved to database using an SQL UPDATE statement - if($this->_data===null) - $this->loadData(); - $updateRow=null; - foreach($this->_data as $index=>$row) - if($row['ISBN']===$isbn) - $updateRow=&$this->_data[$index]; - if($updateRow!==null) - { - $updateRow['title']=$title; - $updateRow['publisher']=$publisher; - $updateRow['price']=TPropertyValue::ensureFloat(ltrim($price,'$')); - $updateRow['instock']=TPropertyValue::ensureBoolean($instock); - $updateRow['rating']=TPropertyValue::ensureInteger($rating); - $this->saveData(); - } - } - - protected function deleteBook($isbn) - { - // In real applications, data should be saved to database using an SQL DELETE statement - if($this->_data===null) - $this->loadData(); - $deleteIndex=-1; - foreach($this->_data as $index=>$row) - if($row['ISBN']===$isbn) - $deleteIndex=$index; - if($deleteIndex>=0) - { - unset($this->_data[$deleteIndex]); - $this->saveData(); - } - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack && !$this->IsCallBack) - { - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } - } - - public function itemCreated($sender,$param) - { - $item=$param->Item; - if($item->ItemType==='EditItem') - { - // set column width of textboxes - $item->BookTitleColumn->TextBox->Columns=40; - $item->PriceColumn->TextBox->Columns=5; - } - if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem' || $item->ItemType==='EditItem') - { - // add an aleart dialog to delete buttons - $item->DeleteColumn->Button->Attributes->onclick='if(!confirm(\'Are you sure?\')) return false;'; - } - } - - public function editItem($sender,$param) - { - $this->DataGrid->EditItemIndex=$param->Item->ItemIndex; - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } - - public function saveItem($sender,$param) - { - $item=$param->Item; - $this->updateBook( - $this->DataGrid->DataKeys[$item->ItemIndex], // ISBN - $item->BookTitleColumn->TextBox->Text, // title - $item->PublisherColumn->TextBox->Text, // publisher - $item->PriceColumn->TextBox->Text, // price - $item->InStockColumn->CheckBox->Checked, // instock - $item->RatingColumn->DropDownList->SelectedValue // rating - ); - $this->DataGrid->EditItemIndex=-1; - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } - - public function cancelItem($sender,$param) - { - $this->DataGrid->EditItemIndex=-1; - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } - - public function deleteItem($sender,$param) - { - $this->deleteBook($this->DataGrid->DataKeys[$param->Item->ItemIndex]); - $this->DataGrid->EditItemIndex=-1; - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } -} - +_data===null) + $this->loadData(); + return $this->_data; + } + + protected function loadData() + { + // We use viewstate keep track of data. + // In real applications, data should come from database using an SQL SELECT statement. + // In the following tabular data, field 'ISBN' is the primary key. + // All update and delete operations should come with an 'id' value in order to go through. + if(($this->_data=$this->getViewState('Data',null))===null) + { + $this->_data=array( + array( + 'ISBN'=>'0596007124', + 'title'=>'Head First Design Patterns', + 'publisher'=>'O\'Reilly Media, Inc.', + 'price'=>29.67, + 'instock'=>true, + 'rating'=>4, + ), + array( + 'ISBN'=>'0201633612', + 'title'=>'Design Patterns: Elements of Reusable Object-Oriented Software', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>47.04, + 'instock'=>true, + 'rating'=>5, + ), + array( + 'ISBN'=>'0321247140', + 'title'=>'Design Patterns Explained : A New Perspective on Object-Oriented Design', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>37.49, + 'instock'=>true, + 'rating'=>4, + ), + array( + 'ISBN'=>'0201485672', + 'title'=>'Refactoring: Improving the Design of Existing Code', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>47.14, + 'instock'=>true, + 'rating'=>3, + ), + array( + 'ISBN'=>'0321213351', + 'title'=>'Refactoring to Patterns', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>38.49, + 'instock'=>true, + 'rating'=>2, + ), + array( + 'ISBN'=>'0735619670', + 'title'=>'Code Complete', + 'publisher'=>'Microsoft Press', + 'price'=>32.99, + 'instock'=>false, + 'rating'=>4, + ), + array( + 'ISBN'=>'0321278658 ', + 'title'=>'Extreme Programming Explained : Embrace Change', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>34.99, + 'instock'=>true, + 'rating'=>3, + ), + ); + $this->saveData(); + } + } + + protected function saveData() + { + $this->setViewState('Data',$this->_data); + } + + protected function updateBook($isbn,$title,$publisher,$price,$instock,$rating) + { + // In real applications, data should be saved to database using an SQL UPDATE statement + if($this->_data===null) + $this->loadData(); + $updateRow=null; + foreach($this->_data as $index=>$row) + if($row['ISBN']===$isbn) + $updateRow=&$this->_data[$index]; + if($updateRow!==null) + { + $updateRow['title']=$title; + $updateRow['publisher']=$publisher; + $updateRow['price']=TPropertyValue::ensureFloat(ltrim($price,'$')); + $updateRow['instock']=TPropertyValue::ensureBoolean($instock); + $updateRow['rating']=TPropertyValue::ensureInteger($rating); + $this->saveData(); + } + } + + protected function deleteBook($isbn) + { + // In real applications, data should be saved to database using an SQL DELETE statement + if($this->_data===null) + $this->loadData(); + $deleteIndex=-1; + foreach($this->_data as $index=>$row) + if($row['ISBN']===$isbn) + $deleteIndex=$index; + if($deleteIndex>=0) + { + unset($this->_data[$deleteIndex]); + $this->saveData(); + } + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack && !$this->IsCallBack) + { + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + } + + public function itemCreated($sender,$param) + { + $item=$param->Item; + if($item->ItemType==='EditItem') + { + // set column width of textboxes + $item->BookTitleColumn->TextBox->Columns=40; + $item->PriceColumn->TextBox->Columns=5; + } + if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem' || $item->ItemType==='EditItem') + { + // add an aleart dialog to delete buttons + $item->DeleteColumn->Button->Attributes->onclick='if(!confirm(\'Are you sure?\')) return false;'; + } + } + + public function editItem($sender,$param) + { + $this->DataGrid->EditItemIndex=$param->Item->ItemIndex; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + + public function saveItem($sender,$param) + { + $item=$param->Item; + $this->updateBook( + $this->DataGrid->DataKeys[$item->ItemIndex], // ISBN + $item->BookTitleColumn->TextBox->Text, // title + $item->PublisherColumn->TextBox->Text, // publisher + $item->PriceColumn->TextBox->Text, // price + $item->InStockColumn->CheckBox->Checked, // instock + $item->RatingColumn->DropDownList->SelectedValue // rating + ); + $this->DataGrid->EditItemIndex=-1; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + + public function cancelItem($sender,$param) + { + $this->DataGrid->EditItemIndex=-1; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + + public function deleteItem($sender,$param) + { + $this->deleteBook($this->DataGrid->DataKeys[$param->Item->ItemIndex]); + $this->DataGrid->EditItemIndex=-1; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample4.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample4.php index eb1a0e5b..46c7dc81 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample4.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample4.php @@ -1,21 +1,21 @@ - $b["'.$key.'"]) ? 1 : -1;}'); - usort($data,$compare) ; - return $data ; - } - - public function sortDataGrid($sender,$param) - { - $this->DataGrid->DataSource=$this->sortData($this->Data,$param->SortExpression); - $this->DataGrid->dataBind(); - } -} - + $b["'.$key.'"]) ? 1 : -1;}'); + usort($data,$compare) ; + return $data ; + } + + public function sortDataGrid($sender,$param) + { + $this->DataGrid->DataSource=$this->sortData($this->Data,$param->SortExpression); + $this->DataGrid->dataBind(); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample5.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample5.php index 95bf9a0e..dc4a4dd6 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample5.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataGrid/Sample5.php @@ -1,79 +1,79 @@ -IsPostback && ! $this->IsCallback) - { - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } - } - - public function changePage($sender,$param) - { - $this->DataGrid->CurrentPageIndex=$param->NewPageIndex; - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } - - public function pagerCreated($sender,$param) - { - $param->Pager->Controls->insertAt(0,'Page: '); - } - - public function changePagerPosition($sender,$param) - { - $top=$sender->Items[0]->Selected; - $bottom=$sender->Items[1]->Selected; - if($top && $bottom) - $position='TopAndBottom'; - else if($top) - $position='Top'; - else if($bottom) - $position='Bottom'; - else - $position=''; - if($position==='') - $this->DataGrid->PagerStyle->Visible=false; - else - { - $this->DataGrid->PagerStyle->Position=$position; - $this->DataGrid->PagerStyle->Visible=true; - } - } - - public function useNumericPager($sender,$param) - { - $this->DataGrid->PagerStyle->Mode='Numeric'; - $this->DataGrid->PagerStyle->NextPageText=$this->NextPageText->Text; - $this->DataGrid->PagerStyle->PrevPageText=$this->PrevPageText->Text; - $this->DataGrid->PagerStyle->PageButtonCount=$this->PageButtonCount->Text; - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } - - public function useNextPrevPager($sender,$param) - { - $this->DataGrid->PagerStyle->Mode='NextPrev'; - $this->DataGrid->PagerStyle->NextPageText=$this->NextPageText->Text; - $this->DataGrid->PagerStyle->PrevPageText=$this->PrevPageText->Text; - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } - - public function changePageSize($sender,$param) - { - $this->DataGrid->PageSize=TPropertyValue::ensureInteger($this->PageSize->Text); - $this->DataGrid->CurrentPageIndex=0; - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } -} - +IsPostback && ! $this->IsCallback) + { + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + } + + public function changePage($sender,$param) + { + $this->DataGrid->CurrentPageIndex=$param->NewPageIndex; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + + public function pagerCreated($sender,$param) + { + $param->Pager->Controls->insertAt(0,'Page: '); + } + + public function changePagerPosition($sender,$param) + { + $top=$sender->Items[0]->Selected; + $bottom=$sender->Items[1]->Selected; + if($top && $bottom) + $position='TopAndBottom'; + else if($top) + $position='Top'; + else if($bottom) + $position='Bottom'; + else + $position=''; + if($position==='') + $this->DataGrid->PagerStyle->Visible=false; + else + { + $this->DataGrid->PagerStyle->Position=$position; + $this->DataGrid->PagerStyle->Visible=true; + } + } + + public function useNumericPager($sender,$param) + { + $this->DataGrid->PagerStyle->Mode='Numeric'; + $this->DataGrid->PagerStyle->NextPageText=$this->NextPageText->Text; + $this->DataGrid->PagerStyle->PrevPageText=$this->PrevPageText->Text; + $this->DataGrid->PagerStyle->PageButtonCount=$this->PageButtonCount->Text; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + + public function useNextPrevPager($sender,$param) + { + $this->DataGrid->PagerStyle->Mode='NextPrev'; + $this->DataGrid->PagerStyle->NextPageText=$this->NextPageText->Text; + $this->DataGrid->PagerStyle->PrevPageText=$this->PrevPageText->Text; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + + public function changePageSize($sender,$param) + { + $this->DataGrid->PageSize=TPropertyValue::ensureInteger($this->PageSize->Text); + $this->DataGrid->CurrentPageIndex=0; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataList/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataList/Home.php index c62a239d..b77fe63c 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataList/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDataList/Home.php @@ -1,132 +1,132 @@ -_data===null) - $this->loadData(); - return $this->_data; - } - - protected function loadData() - { - // We use viewstate keep track of data. - // In real applications, data should come from database using an SQL SELECT statement. - // In the following tabular data, field 'id' is the primary key. - // All update and delete operations should come with an 'id' value in order to go through. - if(($this->_data=$this->getViewState('Data',null))===null) - { - $this->_data=array( - array('id'=>'ITN001','name'=>'Motherboard','quantity'=>1,'price'=>100.00,'imported'=>true), - array('id'=>'ITN002','name'=>'CPU','quantity'=>1,'price'=>150.00,'imported'=>true), - array('id'=>'ITN003','name'=>'Harddrive','quantity'=>2,'price'=>80.00,'imported'=>false), - array('id'=>'ITN004','name'=>'Sound card','quantity'=>1,'price'=>40.00,'imported'=>false), - array('id'=>'ITN005','name'=>'Video card','quantity'=>1,'price'=>150.00,'imported'=>true), - array('id'=>'ITN006','name'=>'Keyboard','quantity'=>1,'price'=>20.00,'imported'=>true), - array('id'=>'ITN007','name'=>'Monitor','quantity'=>2,'price'=>300.00,'imported'=>false), - ); - $this->saveData(); - } - } - - protected function saveData() - { - $this->setViewState('Data',$this->_data); - } - - protected function updateProduct($id,$name,$quantity,$price,$imported) - { - // In real applications, data should be saved to database using an SQL UPDATE statement - if($this->_data===null) - $this->loadData(); - $updateRow=null; - foreach($this->_data as $index=>$row) - if($row['id']===$id) - $updateRow=&$this->_data[$index]; - if($updateRow!==null) - { - $updateRow['name']=$name; - $updateRow['quantity']=TPropertyValue::ensureInteger($quantity); - $updateRow['price']=TPropertyValue::ensureFloat($price); - $updateRow['imported']=TPropertyValue::ensureBoolean($imported); - $this->saveData(); - } - } - - protected function deleteProduct($id) - { - // In real applications, data should be saved to database using an SQL DELETE statement - if($this->_data===null) - $this->loadData(); - $deleteIndex=-1; - foreach($this->_data as $index=>$row) - if($row['id']===$id) - $deleteIndex=$index; - if($deleteIndex>=0) - { - unset($this->_data[$deleteIndex]); - $this->saveData(); - } - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $this->DataList->DataSource=$this->Data; - $this->DataList->dataBind(); - } - } - - public function editItem($sender,$param) - { - $this->DataList->SelectedItemIndex=-1; - $this->DataList->EditItemIndex=$param->Item->ItemIndex; - $this->DataList->DataSource=$this->Data; - $this->DataList->dataBind(); - } - - public function cancelItem($sender,$param) - { - $this->DataList->SelectedItemIndex=-1; - $this->DataList->EditItemIndex=-1; - $this->DataList->DataSource=$this->Data; - $this->DataList->dataBind(); - } - - public function updateItem($sender,$param) - { - $item=$param->Item; - $this->updateProduct( - $this->DataList->DataKeys[$item->ItemIndex], - $item->ProductName->Text, - $item->ProductQuantity->Text, - $item->ProductPrice->Text, - $item->ProductImported->Checked); - $this->DataList->EditItemIndex=-1; - $this->DataList->DataSource=$this->Data; - $this->DataList->dataBind(); - } - - public function deleteItem($sender,$param) - { - $this->deleteProduct($this->DataList->DataKeys[$param->Item->ItemIndex]); - $this->DataList->SelectedItemIndex=-1; - $this->DataList->EditItemIndex=-1; - $this->DataList->DataSource=$this->Data; - $this->DataList->dataBind(); - } - - public function selectItem($sender,$param) - { - $this->DataList->EditItemIndex=-1; - $this->DataList->DataSource=$this->Data; - $this->DataList->dataBind(); - } -} - +_data===null) + $this->loadData(); + return $this->_data; + } + + protected function loadData() + { + // We use viewstate keep track of data. + // In real applications, data should come from database using an SQL SELECT statement. + // In the following tabular data, field 'id' is the primary key. + // All update and delete operations should come with an 'id' value in order to go through. + if(($this->_data=$this->getViewState('Data',null))===null) + { + $this->_data=array( + array('id'=>'ITN001','name'=>'Motherboard','quantity'=>1,'price'=>100.00,'imported'=>true), + array('id'=>'ITN002','name'=>'CPU','quantity'=>1,'price'=>150.00,'imported'=>true), + array('id'=>'ITN003','name'=>'Harddrive','quantity'=>2,'price'=>80.00,'imported'=>false), + array('id'=>'ITN004','name'=>'Sound card','quantity'=>1,'price'=>40.00,'imported'=>false), + array('id'=>'ITN005','name'=>'Video card','quantity'=>1,'price'=>150.00,'imported'=>true), + array('id'=>'ITN006','name'=>'Keyboard','quantity'=>1,'price'=>20.00,'imported'=>true), + array('id'=>'ITN007','name'=>'Monitor','quantity'=>2,'price'=>300.00,'imported'=>false), + ); + $this->saveData(); + } + } + + protected function saveData() + { + $this->setViewState('Data',$this->_data); + } + + protected function updateProduct($id,$name,$quantity,$price,$imported) + { + // In real applications, data should be saved to database using an SQL UPDATE statement + if($this->_data===null) + $this->loadData(); + $updateRow=null; + foreach($this->_data as $index=>$row) + if($row['id']===$id) + $updateRow=&$this->_data[$index]; + if($updateRow!==null) + { + $updateRow['name']=$name; + $updateRow['quantity']=TPropertyValue::ensureInteger($quantity); + $updateRow['price']=TPropertyValue::ensureFloat($price); + $updateRow['imported']=TPropertyValue::ensureBoolean($imported); + $this->saveData(); + } + } + + protected function deleteProduct($id) + { + // In real applications, data should be saved to database using an SQL DELETE statement + if($this->_data===null) + $this->loadData(); + $deleteIndex=-1; + foreach($this->_data as $index=>$row) + if($row['id']===$id) + $deleteIndex=$index; + if($deleteIndex>=0) + { + unset($this->_data[$deleteIndex]); + $this->saveData(); + } + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $this->DataList->DataSource=$this->Data; + $this->DataList->dataBind(); + } + } + + public function editItem($sender,$param) + { + $this->DataList->SelectedItemIndex=-1; + $this->DataList->EditItemIndex=$param->Item->ItemIndex; + $this->DataList->DataSource=$this->Data; + $this->DataList->dataBind(); + } + + public function cancelItem($sender,$param) + { + $this->DataList->SelectedItemIndex=-1; + $this->DataList->EditItemIndex=-1; + $this->DataList->DataSource=$this->Data; + $this->DataList->dataBind(); + } + + public function updateItem($sender,$param) + { + $item=$param->Item; + $this->updateProduct( + $this->DataList->DataKeys[$item->ItemIndex], + $item->ProductName->Text, + $item->ProductQuantity->Text, + $item->ProductPrice->Text, + $item->ProductImported->Checked); + $this->DataList->EditItemIndex=-1; + $this->DataList->DataSource=$this->Data; + $this->DataList->dataBind(); + } + + public function deleteItem($sender,$param) + { + $this->deleteProduct($this->DataList->DataKeys[$param->Item->ItemIndex]); + $this->DataList->SelectedItemIndex=-1; + $this->DataList->EditItemIndex=-1; + $this->DataList->DataSource=$this->Data; + $this->DataList->dataBind(); + } + + public function selectItem($sender,$param) + { + $this->DataList->EditItemIndex=-1; + $this->DataList->DataSource=$this->Data; + $this->DataList->dataBind(); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDropDownList/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDropDownList/Home.php index 0ba728c6..5b16af2c 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDropDownList/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveDropDownList/Home.php @@ -1,60 +1,60 @@ -IsPostBack && !$this->IsCallback) - { - $this->resetClicked(null,null); - } - } - - protected function collectSelectionResult($input,$output) - { - $indices=$input->SelectedIndices; - $result=''; - foreach($indices as $index) - { - $item=$input->Items[$index]; - $result.="(Index: $index, Value: $item->Value, Text: $item->Text)"; - } - if($result==='') - $output->Text='Your selection is empty.'; - else - $output->Text='Your selection is: '.$result; - } - - public function selectionChanged($sender,$param) - { - $this->collectSelectionResult($sender,$this->SelectionResult); - } - - public function buttonClicked($sender, $param) - { - $data=array(); - for($i = 0; $i <= $this->ddl1->Items->Count; $i++) - $data[$i]="Item number #".$i; - $this->ddl1->DataSource=$data; - $this->ddl1->dataBind(); - $this->label1->Text="Total ".count($data)." items"; - } - - public function resetClicked($sender, $param) - { - $data=array('item 1','item 2','item 3','item 4'); - $this->ddl2->DataSource=$data; - $this->ddl2->dataBind(); - $this->label2->Text="DropDownList has been reset"; - } - - public function clearClicked($sender, $param) - { - $this->ddl2->DataSource=array(); - $this->ddl2->dataBind(); - $this->label2->Text="DropDownList cleared"; - } -} - +IsPostBack && !$this->IsCallback) + { + $this->resetClicked(null,null); + } + } + + protected function collectSelectionResult($input,$output) + { + $indices=$input->SelectedIndices; + $result=''; + foreach($indices as $index) + { + $item=$input->Items[$index]; + $result.="(Index: $index, Value: $item->Value, Text: $item->Text)"; + } + if($result==='') + $output->Text='Your selection is empty.'; + else + $output->Text='Your selection is: '.$result; + } + + public function selectionChanged($sender,$param) + { + $this->collectSelectionResult($sender,$this->SelectionResult); + } + + public function buttonClicked($sender, $param) + { + $data=array(); + for($i = 0; $i <= $this->ddl1->Items->Count; $i++) + $data[$i]="Item number #".$i; + $this->ddl1->DataSource=$data; + $this->ddl1->dataBind(); + $this->label1->Text="Total ".count($data)." items"; + } + + public function resetClicked($sender, $param) + { + $data=array('item 1','item 2','item 3','item 4'); + $this->ddl2->DataSource=$data; + $this->ddl2->dataBind(); + $this->label2->Text="DropDownList has been reset"; + } + + public function clearClicked($sender, $param) + { + $this->ddl2->DataSource=array(); + $this->ddl2->dataBind(); + $this->label2->Text="DropDownList cleared"; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveFileUpload/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveFileUpload/Home.php index d5cf990a..29d05a1c 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveFileUpload/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveFileUpload/Home.php @@ -1,21 +1,21 @@ -HasFile) - { - $this->Result->Text=" - You just uploaded a file: -
- Name: {$sender->FileName} -
- Size: {$sender->FileSize} -
- Type: {$sender->FileType}"; - } - } -} - +HasFile) + { + $this->Result->Text=" + You just uploaded a file: +
+ Name: {$sender->FileName} +
+ Size: {$sender->FileSize} +
+ Type: {$sender->FileType}"; + } + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveHyperLink/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveHyperLink/Home.php index c125d902..45ea1584 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveHyperLink/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveHyperLink/Home.php @@ -1,26 +1,26 @@ -link1->NavigateUrl = 'http://www.google.com'; - } - - function button2_clicked($sender, $param) - { - $this->link2->Target = '_self'; - } - - function button3_clicked($sender, $param) - { - $this->link3->Text = 'PradoSoft.com'; - } - - function button4_clicked($sender, $param) - { - $img = $this->publishFilePath(dirname(__FILE__).'/hello_world.gif'); - $this->link4->ImageUrl = $img; - } -} +link1->NavigateUrl = 'http://www.google.com'; + } + + function button2_clicked($sender, $param) + { + $this->link2->Target = '_self'; + } + + function button3_clicked($sender, $param) + { + $this->link3->Text = 'PradoSoft.com'; + } + + function button4_clicked($sender, $param) + { + $img = $this->publishFilePath(dirname(__FILE__).'/hello_world.gif'); + $this->link4->ImageUrl = $img; + } +} ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveImage/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveImage/Home.php index 3628ad0a..6850fb40 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveImage/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveImage/Home.php @@ -1,17 +1,17 @@ -imageTest->ImageUrl=$this->publishAsset("hello_world.gif"); - } - - public function buttonClicked2($sender, $param) - { - $this->imageTest->ImageUrl=$this->publishAsset("hello_world2.gif"); - } -} - +imageTest->ImageUrl=$this->publishAsset("hello_world.gif"); + } + + public function buttonClicked2($sender, $param) + { + $this->imageTest->ImageUrl=$this->publishAsset("hello_world2.gif"); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveImageButton/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveImageButton/Home.php index b1f2c53b..28be10f9 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveImageButton/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveImageButton/Home.php @@ -1,18 +1,18 @@ -Result2->Text="Callback parameter: $param->CallbackParameter"; - } - else - { - $this->Result->Text="You clicked at ($param->X,$param->Y)"; - } - } -} - +Result2->Text="Callback parameter: $param->CallbackParameter"; + } + else + { + $this->Result->Text="You clicked at ($param->X,$param->Y)"; + } + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveLinkButton/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveLinkButton/Home.php index 64e2dede..e929c07b 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveLinkButton/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveLinkButton/Home.php @@ -1,14 +1,14 @@ -Text="Callback Parameter: {$param->CallbackParameter}"; - else - $sender->Text="I'm clicked"; - } -} - +Text="Callback Parameter: {$param->CallbackParameter}"; + else + $sender->Text="I'm clicked"; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveListBox/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveListBox/Home.php index 795e3eca..509e32ab 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveListBox/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveListBox/Home.php @@ -1,65 +1,65 @@ -IsPostBack && !$this->IsCallback) - { - $this->resetClicked(null,null); - } - } - - protected function collectSelectionResult($input,$output) - { - $indices=$input->SelectedIndices; - $result=''; - foreach($indices as $index) - { - $item=$input->Items[$index]; - $result.="(Index: $index, Value: $item->Value, Text: $item->Text)"; - } - if($result==='') - $output->Text='Your selection is empty.'; - else - $output->Text='Your selection is: '.$result; - } - - public function selectionChanged($sender,$param) - { - $this->collectSelectionResult($sender,$this->SelectionResult); - } - - public function multiSelectionChanged($sender,$param) - { - $this->collectSelectionResult($sender,$this->MSelectionResult); - } - - public function buttonClicked($sender, $param) - { - $data=array(); - for($i = 0; $i <= $this->box1->Items->Count; $i++) - $data[$i]="Item number #".$i; - $this->box1->DataSource=$data; - $this->box1->dataBind(); - $this->label1->Text="Total ".count($data)." items"; - } - - public function resetClicked($sender, $param) - { - $data=array('item 1','item 2','item 3','item 4'); - $this->box2->DataSource=$data; - $this->box2->dataBind(); - $this->label2->Text="ListBox has been reset"; - } - - public function clearClicked($sender, $param) - { - $this->box2->DataSource=array(); - $this->box2->dataBind(); - $this->label2->Text="ListBox cleared"; - } -} - +IsPostBack && !$this->IsCallback) + { + $this->resetClicked(null,null); + } + } + + protected function collectSelectionResult($input,$output) + { + $indices=$input->SelectedIndices; + $result=''; + foreach($indices as $index) + { + $item=$input->Items[$index]; + $result.="(Index: $index, Value: $item->Value, Text: $item->Text)"; + } + if($result==='') + $output->Text='Your selection is empty.'; + else + $output->Text='Your selection is: '.$result; + } + + public function selectionChanged($sender,$param) + { + $this->collectSelectionResult($sender,$this->SelectionResult); + } + + public function multiSelectionChanged($sender,$param) + { + $this->collectSelectionResult($sender,$this->MSelectionResult); + } + + public function buttonClicked($sender, $param) + { + $data=array(); + for($i = 0; $i <= $this->box1->Items->Count; $i++) + $data[$i]="Item number #".$i; + $this->box1->DataSource=$data; + $this->box1->dataBind(); + $this->label1->Text="Total ".count($data)." items"; + } + + public function resetClicked($sender, $param) + { + $data=array('item 1','item 2','item 3','item 4'); + $this->box2->DataSource=$data; + $this->box2->dataBind(); + $this->label2->Text="ListBox has been reset"; + } + + public function clearClicked($sender, $param) + { + $this->box2->DataSource=array(); + $this->box2->dataBind(); + $this->label2->Text="ListBox cleared"; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveMultiView/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveMultiView/Home.php index 1a5dbed3..24a240ca 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveMultiView/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveMultiView/Home.php @@ -1,15 +1,15 @@ -MultiView->ActiveViewIndex===2) - { - $this->Result1->Text="Your text input is: ".$this->Memo->Text; - $this->Result2->Text="Your color choice is: ".$this->DropDownList->SelectedValue; - } - } -} - +MultiView->ActiveViewIndex===2) + { + $this->Result1->Text="Your text input is: ".$this->Memo->Text; + $this->Result2->Text="Your color choice is: ".$this->DropDownList->SelectedValue; + } + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActivePanel/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActivePanel/Home.php index ae174f59..362fdebe 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActivePanel/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActivePanel/Home.php @@ -1,21 +1,21 @@ -check1->Checked = !$this->check1->Checked; - if($this->txt1->Text=="") - $this->txt1->Text="changes happens"; - else - $this->txt1->Text=""; - if($this->label1->Text=="") - $this->label1->Text="label has changed, too"; - else - $this->label1->Text=""; - - $this->panel1->render($param->NewWriter); - } -} - +check1->Checked = !$this->check1->Checked; + if($this->txt1->Text=="") + $this->txt1->Text="changes happens"; + else + $this->txt1->Text=""; + if($this->label1->Text=="") + $this->label1->Text="label has changed, too"; + else + $this->label1->Text=""; + + $this->panel1->render($param->NewWriter); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRadioButton/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRadioButton/Home.php index 034d2fcc..a0c2af32 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRadioButton/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRadioButton/Home.php @@ -1,27 +1,27 @@ -Text="I'm clicked"; - } - - public function selectRadioButton($sender,$param) - { - $selection=''; - if($this->Radio1->Checked) - $selection.='1'; - if($this->Radio2->Checked) - $selection.='2'; - if($this->Radio3->Checked) - $selection.='3'; - if($this->Radio4->Checked) - $selection.='4'; - if($selection==='') - $selection='empty'; - $this->Result->Text='Your selection is '.$selection; - } -} - +Text="I'm clicked"; + } + + public function selectRadioButton($sender,$param) + { + $selection=''; + if($this->Radio1->Checked) + $selection.='1'; + if($this->Radio2->Checked) + $selection.='2'; + if($this->Radio3->Checked) + $selection.='3'; + if($this->Radio4->Checked) + $selection.='4'; + if($selection==='') + $selection='empty'; + $this->Result->Text='Your selection is '.$selection; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRadioButtonList/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRadioButtonList/Home.php index dfa52ce4..1033837c 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRadioButtonList/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRadioButtonList/Home.php @@ -1,26 +1,26 @@ -SelectedIndices; - $result=''; - foreach($indices as $index) - { - $item=$input->Items[$index]; - $result.="(Index: $index, Value: $item->Value, Text: $item->Text)"; - } - if($result==='') - $output->Text='Your selection is empty.'; - else - $output->Text='Your selection is: '.$result; - } - - public function selectionChanged($sender,$param) - { - $this->collectSelectionResult($this->RadioButtonList,$this->SelectionResult); - } -} - +SelectedIndices; + $result=''; + foreach($indices as $index) + { + $item=$input->Items[$index]; + $result.="(Index: $index, Value: $item->Value, Text: $item->Text)"; + } + if($result==='') + $output->Text='Your selection is empty.'; + else + $output->Text='Your selection is: '.$result; + } + + public function selectionChanged($sender,$param) + { + $this->collectSelectionResult($this->RadioButtonList,$this->SelectionResult); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRepeater/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRepeater/Home.php index f7c8d61c..ae765ee1 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRepeater/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveRepeater/Home.php @@ -1,79 +1,79 @@ -'ITN001','name'=>'Motherboard','category'=>'CAT004','price'=>100.00,'imported'=>true), - array('id'=>'ITN002','name'=>'CPU','category'=>'CAT004','price'=>150.00,'imported'=>true), - array('id'=>'ITN003','name'=>'Harddrive','category'=>'CAT003','price'=>80.00,'imported'=>true), - array('id'=>'ITN006','name'=>'Keyboard','category'=>'CAT002','price'=>20.00,'imported'=>false), - array('id'=>'ITN008','name'=>'CDRW drive','category'=>'CAT003','price'=>40.00,'imported'=>true), - array('id'=>'ITN009','name'=>'Cooling fan','category'=>'CAT001','price'=>10.00,'imported'=>false), - array('id'=>'ITN012','name'=>'Floppy drive','category'=>'CAT003','price'=>12.00,'imported'=>false), - array('id'=>'ITN013','name'=>'CD drive','category'=>'CAT003','price'=>20.00,'imported'=>true), - array('id'=>'ITN014','name'=>'DVD drive','category'=>'CAT003','price'=>80.00,'imported'=>true), - array('id'=>'ITN015','name'=>'Mouse pad','category'=>'CAT001','price'=>5.00,'imported'=>false), - ); - } - - protected function getCategories() - { - return array( - array('id'=>'CAT001','name'=>'Accessories'), - array('id'=>'CAT002','name'=>'Input Devices'), - array('id'=>'CAT003','name'=>'Drives'), - array('id'=>'CAT004','name'=>'Barebone'), - ); - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $this->Repeater->DataSource=$this->Products; - $this->Repeater->dataBind(); - } - } - - public function repeaterDataBound($sender,$param) - { - $item=$param->Item; - if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem') - { - $item->ProductCategory->DataSource=$this->Categories; - $item->ProductCategory->DataTextField='name'; - $item->ProductCategory->DataValueField='id'; - $item->ProductCategory->dataBind(); - $item->ProductCategory->SelectedValue=$item->DataItem['category']; - } - } - - public function saveInput($sender,$param) - { - if($this->IsValid) - { - $index=0; - $products=$this->Products; - $data=array(); - foreach($this->Repeater->Items as $item) - { - $item=array( - 'id'=>$products[$index]['id'], - 'name'=>$item->ProductName->Text, - 'category'=>$item->ProductCategory->SelectedItem->Text, - 'price'=>TPropertyValue::ensureFloat($item->ProductPrice->Text), - 'imported'=>$item->ProductImported->Checked, - ); - $data[]=$item; - $index++; - } - $this->Repeater2->DataSource=$data; - $this->Repeater2->dataBind(); - } - } -} - +'ITN001','name'=>'Motherboard','category'=>'CAT004','price'=>100.00,'imported'=>true), + array('id'=>'ITN002','name'=>'CPU','category'=>'CAT004','price'=>150.00,'imported'=>true), + array('id'=>'ITN003','name'=>'Harddrive','category'=>'CAT003','price'=>80.00,'imported'=>true), + array('id'=>'ITN006','name'=>'Keyboard','category'=>'CAT002','price'=>20.00,'imported'=>false), + array('id'=>'ITN008','name'=>'CDRW drive','category'=>'CAT003','price'=>40.00,'imported'=>true), + array('id'=>'ITN009','name'=>'Cooling fan','category'=>'CAT001','price'=>10.00,'imported'=>false), + array('id'=>'ITN012','name'=>'Floppy drive','category'=>'CAT003','price'=>12.00,'imported'=>false), + array('id'=>'ITN013','name'=>'CD drive','category'=>'CAT003','price'=>20.00,'imported'=>true), + array('id'=>'ITN014','name'=>'DVD drive','category'=>'CAT003','price'=>80.00,'imported'=>true), + array('id'=>'ITN015','name'=>'Mouse pad','category'=>'CAT001','price'=>5.00,'imported'=>false), + ); + } + + protected function getCategories() + { + return array( + array('id'=>'CAT001','name'=>'Accessories'), + array('id'=>'CAT002','name'=>'Input Devices'), + array('id'=>'CAT003','name'=>'Drives'), + array('id'=>'CAT004','name'=>'Barebone'), + ); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $this->Repeater->DataSource=$this->Products; + $this->Repeater->dataBind(); + } + } + + public function repeaterDataBound($sender,$param) + { + $item=$param->Item; + if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem') + { + $item->ProductCategory->DataSource=$this->Categories; + $item->ProductCategory->DataTextField='name'; + $item->ProductCategory->DataValueField='id'; + $item->ProductCategory->dataBind(); + $item->ProductCategory->SelectedValue=$item->DataItem['category']; + } + } + + public function saveInput($sender,$param) + { + if($this->IsValid) + { + $index=0; + $products=$this->Products; + $data=array(); + foreach($this->Repeater->Items as $item) + { + $item=array( + 'id'=>$products[$index]['id'], + 'name'=>$item->ProductName->Text, + 'category'=>$item->ProductCategory->SelectedItem->Text, + 'price'=>TPropertyValue::ensureFloat($item->ProductPrice->Text), + 'imported'=>$item->ProductImported->Checked, + ); + $data[]=$item; + $index++; + } + $this->Repeater2->DataSource=$data; + $this->Repeater2->dataBind(); + } + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveTableRow/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveTableRow/Home.php index b056eba8..d74160bb 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveTableRow/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TActiveTableRow/Home.php @@ -1,22 +1,22 @@ -Text .= "
Clicked"; - $this->lblResult->Text='You clicked on cell #'.$param->SelectedCellIndex.' with id='.$sender->id; - $sender->render($param->NewWriter); - } - - public function clickRow ($sender, $param) - { - $sender->BackColor="yellow"; - $this->lblResult->Text='You clicked on row #'.$param->SelectedRowIndex.' with id='.$sender->id; - $sender->render($param->NewWriter); - } -} - +Text .= "
Clicked"; + $this->lblResult->Text='You clicked on cell #'.$param->SelectedCellIndex.' with id='.$sender->id; + $sender->render($param->NewWriter); + } + + public function clickRow ($sender, $param) + { + $sender->BackColor="yellow"; + $this->lblResult->Text='You clicked on row #'.$param->SelectedRowIndex.' with id='.$sender->id; + $sender->render($param->NewWriter); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TAutoComplete/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TAutoComplete/Home.php index ca8a9e59..290995c7 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TAutoComplete/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TAutoComplete/Home.php @@ -1,34 +1,34 @@ -getToken(); - // Sender is the Suggestions repeater - $sender->DataSource=$this->getDummyData($token); - $sender->dataBind(); - } - - public function suggestionSelected1($sender,$param) { - $id=$sender->Suggestions->DataKeys[ $param->selectedIndex ]; - $this->Selection1->Text='Selected ID: '.$id; - } - - public function suggestionSelected2($sender,$param) { - $id=$sender->Suggestions->DataKeys[ $param->selectedIndex ]; - $this->Selection2->Text='Selected ID: '.$id; - } - - public function getDummyData($token) { - // You would look for matches to the given token here - return array( - array('id'=>1, 'name'=>'John'), - array('id'=>2, 'name'=>'Paul'), - array('id'=>3, 'name'=>'George'), - array('id'=>4, 'name'=>'Ringo') - ); - } -} - -?> +getToken(); + // Sender is the Suggestions repeater + $sender->DataSource=$this->getDummyData($token); + $sender->dataBind(); + } + + public function suggestionSelected1($sender,$param) { + $id=$sender->Suggestions->DataKeys[ $param->selectedIndex ]; + $this->Selection1->Text='Selected ID: '.$id; + } + + public function suggestionSelected2($sender,$param) { + $id=$sender->Suggestions->DataKeys[ $param->selectedIndex ]; + $this->Selection2->Text='Selected ID: '.$id; + } + + public function getDummyData($token) { + // You would look for matches to the given token here + return array( + array('id'=>1, 'name'=>'John'), + array('id'=>2, 'name'=>'Paul'), + array('id'=>3, 'name'=>'George'), + array('id'=>4, 'name'=>'Ringo') + ); + } +} + +?> diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TCallbackClientScript/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TCallbackClientScript/Home.php index 500d7987..a8cef26c 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TCallbackClientScript/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TCallbackClientScript/Home.php @@ -1,29 +1,29 @@ -radio1->SelectedValue) - { - case 1: - $this->getCallbackClient()->evaluateScript(""); - break; - case 2: - $this->getCallbackClient()->check($this->check1, !$this->check1->Checked); - break; - case 3: - $this->getCallbackClient()->hide($this->label1); - break; - case 4: - $this->getCallbackClient()->show($this->label1); - break; - case 5: - $this->getCallbackClient()->focus($this->txt1); - break; - } - } -} - +radio1->SelectedValue) + { + case 1: + $this->getCallbackClient()->evaluateScript(""); + break; + case 2: + $this->getCallbackClient()->check($this->check1, !$this->check1->Checked); + break; + case 3: + $this->getCallbackClient()->hide($this->label1); + break; + case 4: + $this->getCallbackClient()->show($this->label1); + break; + case 5: + $this->getCallbackClient()->focus($this->txt1); + break; + } + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TCallbackClientSide/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TCallbackClientSide/Home.php index 8dd794fe..f642ccbb 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TCallbackClientSide/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TCallbackClientSide/Home.php @@ -1,12 +1,12 @@ - \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ActiveControls/Samples/TCallbackOptions/Home.php b/demos/quickstart/protected/pages/ActiveControls/Samples/TCallbackOptions/Home.php index 6f101107..caff7360 100644 --- a/demos/quickstart/protected/pages/ActiveControls/Samples/TCallbackOptions/Home.php +++ b/demos/quickstart/protected/pages/ActiveControls/Samples/TCallbackOptions/Home.php @@ -1,12 +1,12 @@ - \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Advanced/Samples/I18N/Home.php b/demos/quickstart/protected/pages/Advanced/Samples/I18N/Home.php index cce1ed4e..634c1773 100644 --- a/demos/quickstart/protected/pages/Advanced/Samples/I18N/Home.php +++ b/demos/quickstart/protected/pages/Advanced/Samples/I18N/Home.php @@ -1,45 +1,45 @@ -Request['lang']; - $info = new CultureInfo(); - if($info->validCulture($lang)) //only valid lang is permitted - $this->getApplication()->getGlobalization()->setCulture($lang); - } - - /** - * Initialize the page with some arbituary data. - * @param TEventParameter event parameter. - */ - public function onLoad($param) - { - parent::onLoad($param); - $time1 = $this->Time1; - $time1->Value = time(); - - $number2 = $this->Number2; - $number2->Value = 46412.416; - - $this->dataBind(); - } - - /** - * Get the localized current culture name. - * @return string localized curreny culture name. - */ - public function getCurrentCulture() - { - $culture = $this->getApplication()->getGlobalization()->getCulture(); - $cultureInfo = new CultureInfo($culture); - return $cultureInfo->getNativeName(); - } -} - +Request['lang']; + $info = new CultureInfo(); + if($info->validCulture($lang)) //only valid lang is permitted + $this->getApplication()->getGlobalization()->setCulture($lang); + } + + /** + * Initialize the page with some arbituary data. + * @param TEventParameter event parameter. + */ + public function onLoad($param) + { + parent::onLoad($param); + $time1 = $this->Time1; + $time1->Value = time(); + + $number2 = $this->Number2; + $number2->Value = 46412.416; + + $this->dataBind(); + } + + /** + * Get the localized current culture name. + * @return string localized curreny culture name. + */ + public function getCurrentCulture() + { + $culture = $this->getApplication()->getGlobalization()->getCulture(); + $cultureInfo = new CultureInfo($culture); + return $cultureInfo->getNativeName(); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Advanced/Samples/I18N/LanguageList.php b/demos/quickstart/protected/pages/Advanced/Samples/I18N/LanguageList.php index d3db187d..bdeb5039 100644 --- a/demos/quickstart/protected/pages/Advanced/Samples/I18N/LanguageList.php +++ b/demos/quickstart/protected/pages/Advanced/Samples/I18N/LanguageList.php @@ -1,19 +1,19 @@ - \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox1/Home.php b/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox1/Home.php index 2309bd88..cfc01a31 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox1/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox1/Home.php @@ -1,13 +1,13 @@ -Text=$this->Input->TextBox->Text; - } -} - +Text=$this->Input->TextBox->Text; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox1/LabeledTextBox.php b/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox1/LabeledTextBox.php index 999639d7..0c374b72 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox1/LabeledTextBox.php +++ b/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox1/LabeledTextBox.php @@ -1,18 +1,18 @@ -ensureChildControls(); - return $this->getRegisteredObject('Label'); - } - - public function getTextBox() - { - $this->ensureChildControls(); - return $this->getRegisteredObject('TextBox'); - } -} - +ensureChildControls(); + return $this->getRegisteredObject('Label'); + } + + public function getTextBox() + { + $this->ensureChildControls(); + return $this->getRegisteredObject('TextBox'); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/Home.php b/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/Home.php index 2b18972d..ae3f9e8b 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/Home.php @@ -1,13 +1,13 @@ -Text=$this->Input->TextBox->Text; - } -} - +Text=$this->Input->TextBox->Text; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/LabeledTextBox.php b/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/LabeledTextBox.php index fc912003..601cebc6 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/LabeledTextBox.php +++ b/demos/quickstart/protected/pages/Controls/Samples/LabeledTextBox2/LabeledTextBox.php @@ -1,33 +1,33 @@ -_label=new TLabel; - $this->_label->setID('Label'); - $this->getControls()->add($this->_label); - $this->getControls()->add(' '); - $this->_textbox=new TTextBox; - $this->_textbox->setID('TextBox'); - $this->_label->setForControl('TextBox'); - $this->getControls()->add($this->_textbox); - } - - public function getLabel() - { - $this->ensureChildControls(); - return $this->_label; - } - - public function getTextBox() - { - $this->ensureChildControls(); - return $this->_textbox; - } -} - +_label=new TLabel; + $this->_label->setID('Label'); + $this->getControls()->add($this->_label); + $this->getControls()->add(' '); + $this->_textbox=new TTextBox; + $this->_textbox->setID('TextBox'); + $this->_label->setForControl('TextBox'); + $this->getControls()->add($this->_textbox); + } + + public function getLabel() + { + $this->ensureChildControls(); + return $this->_label; + } + + public function getTextBox() + { + $this->ensureChildControls(); + return $this->_textbox; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/ResetValidation/Home.php b/demos/quickstart/protected/pages/Controls/Samples/ResetValidation/Home.php index 88d2dbf2..1c5efbcf 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/ResetValidation/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/ResetValidation/Home.php @@ -1,8 +1,8 @@ - \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TAccordion/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TAccordion/Home.php index 3da69927..4faaef1c 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TAccordion/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TAccordion/Home.php @@ -1,17 +1,17 @@ -lab1->Text=""; - } - - public function executeTransaction($sender, $param) - { - $this->lab1->Text="executeTransaction ok"; - } -} - +lab1->Text=""; + } + + public function executeTransaction($sender, $param) + { + $this->lab1->Text="executeTransaction ok"; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TBulletedList/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TBulletedList/Home.php index d3e04787..93c947fe 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TBulletedList/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TBulletedList/Home.php @@ -1,12 +1,12 @@ -Items[$param->Index]; - $this->Result->Text="You clicked $item->Text : $item->Value."; - } -} - +Items[$param->Index]; + $this->Result->Text="You clicked $item->Text : $item->Value."; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TButton/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TButton/Home.php index f18072f2..3711ca46 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TButton/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TButton/Home.php @@ -1,14 +1,14 @@ -Text="Name: {$param->CommandName}, Param: {$param->CommandParameter}"; - else - $sender->Text="I'm clicked"; - } -} - +Text="Name: {$param->CommandName}, Param: {$param->CommandParameter}"; + else + $sender->Text="I'm clicked"; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TCaptcha/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TCaptcha/Home.php index 6965bbbd..c88b9378 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TCaptcha/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TCaptcha/Home.php @@ -1,27 +1,27 @@ -IsPostBack) - { - $this->CaptchaList->DataSource=range(0,63); - $this->CaptchaList->dataBind(); - } - } - - public function regenerateToken($sender,$param) - { - $this->Captcha->regenerateToken(); - $this->SubmitButton->Text="Submit"; - } - - public function buttonClicked($sender,$param) - { - if($this->IsValid) - $sender->Text="You passed!"; - } -} - +IsPostBack) + { + $this->CaptchaList->DataSource=range(0,63); + $this->CaptchaList->dataBind(); + } + } + + public function regenerateToken($sender,$param) + { + $this->Captcha->regenerateToken(); + $this->SubmitButton->Text="Submit"; + } + + public function buttonClicked($sender,$param) + { + if($this->IsValid) + $sender->Text="You passed!"; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TCheckBox/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TCheckBox/Home.php index 37eae19b..89fb6852 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TCheckBox/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TCheckBox/Home.php @@ -1,11 +1,11 @@ -Text="I'm clicked"; - } -} - +Text="I'm clicked"; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.php index 08c6f3ca..ac7ca8bc 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TCheckBoxList/Home.php @@ -1,70 +1,70 @@ -IsPostBack) - { - $data=array('item 1','item 2','item 3','item 4'); - $this->DBCheckBoxList1->DataSource=$data; - $this->DBCheckBoxList1->dataBind(); - - $data=array('key 1'=>'item 1','key 2'=>'item 2', - 'key 3'=>'item 3','key 4'=>'item 4'); - $this->DBCheckBoxList2->DataSource=$data; - $this->DBCheckBoxList2->dataBind(); - - $data=array( - array('id'=>'001','name'=>'John','age'=>31), - array('id'=>'002','name'=>'Mary','age'=>30), - array('id'=>'003','name'=>'Cary','age'=>20)); - $this->DBCheckBoxList3->DataSource=$data; - $this->DBCheckBoxList3->dataBind(); - } - } - - protected function collectSelectionResult($input,$output) - { - $indices=$input->SelectedIndices; - $result=''; - foreach($indices as $index) - { - $item=$input->Items[$index]; - $result.="(Index: $index, Value: $item->Value, Text: $item->Text)"; - } - if($result==='') - $output->Text='Your selection is empty.'; - else - $output->Text='Your selection is: '.$result; - } - - public function buttonClicked($sender,$param) - { - $this->collectSelectionResult($this->CheckBoxList,$this->SelectionResult); - } - - public function selectionChanged($sender,$param) - { - $this->collectSelectionResult($sender,$this->SelectionResult2); - } - - public function DBCheckBoxList1Changed($sender,$param) - { - $this->collectSelectionResult($sender,$this->DBCheckBoxList1Result); - } - - public function DBCheckBoxList2Changed($sender,$param) - { - $this->collectSelectionResult($sender,$this->DBCheckBoxList2Result); - } - - public function DBCheckBoxList3Changed($sender,$param) - { - $this->collectSelectionResult($sender,$this->DBCheckBoxList3Result); - } - -} - +IsPostBack) + { + $data=array('item 1','item 2','item 3','item 4'); + $this->DBCheckBoxList1->DataSource=$data; + $this->DBCheckBoxList1->dataBind(); + + $data=array('key 1'=>'item 1','key 2'=>'item 2', + 'key 3'=>'item 3','key 4'=>'item 4'); + $this->DBCheckBoxList2->DataSource=$data; + $this->DBCheckBoxList2->dataBind(); + + $data=array( + array('id'=>'001','name'=>'John','age'=>31), + array('id'=>'002','name'=>'Mary','age'=>30), + array('id'=>'003','name'=>'Cary','age'=>20)); + $this->DBCheckBoxList3->DataSource=$data; + $this->DBCheckBoxList3->dataBind(); + } + } + + protected function collectSelectionResult($input,$output) + { + $indices=$input->SelectedIndices; + $result=''; + foreach($indices as $index) + { + $item=$input->Items[$index]; + $result.="(Index: $index, Value: $item->Value, Text: $item->Text)"; + } + if($result==='') + $output->Text='Your selection is empty.'; + else + $output->Text='Your selection is: '.$result; + } + + public function buttonClicked($sender,$param) + { + $this->collectSelectionResult($this->CheckBoxList,$this->SelectionResult); + } + + public function selectionChanged($sender,$param) + { + $this->collectSelectionResult($sender,$this->SelectionResult2); + } + + public function DBCheckBoxList1Changed($sender,$param) + { + $this->collectSelectionResult($sender,$this->DBCheckBoxList1Result); + } + + public function DBCheckBoxList2Changed($sender,$param) + { + $this->collectSelectionResult($sender,$this->DBCheckBoxList2Result); + } + + public function DBCheckBoxList3Changed($sender,$param) + { + $this->collectSelectionResult($sender,$this->DBCheckBoxList3Result); + } + +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.php index d6dded08..cccbf845 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TClientSideValidator/Home.php @@ -1,17 +1,17 @@ -enabled = $this->check1->checked; - } - - function onPreRender($param) - { - //always re-enable the validator2 so as to display the client-side validator - $this->validator2->enabled=true; - } -} - +enabled = $this->check1->checked; + } + + function onPreRender($param) + { + //always re-enable the validator2 so as to display the client-side validator + $this->validator2->enabled=true; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.php index 88d2dbf2..1c5efbcf 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TCompareValidator/Home.php @@ -1,8 +1,8 @@ - \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TConditional/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TConditional/Home.php index badbca73..b03361b8 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TConditional/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TConditional/Home.php @@ -1,7 +1,7 @@ - \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TCustomValidator/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TCustomValidator/Home.php index da0d15b2..a3b83ff5 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TCustomValidator/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TCustomValidator/Home.php @@ -1,18 +1,18 @@ -Value!=='test') - $param->IsValid=false; - } - - public function serverValidateNoControl($sender,$param) - { - if($this->TextBox4->Text!=='test') - $param->IsValid=false; - } -} - +Value!=='test') + $param->IsValid=false; + } + + public function serverValidateNoControl($sender,$param) + { + if($this->TextBox4->Text!=='test') + $param->IsValid=false; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample1.php b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample1.php index ec78006b..628d0740 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample1.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample1.php @@ -1,41 +1,41 @@ -'ITN001','name'=>'Motherboard','quantity'=>1,'price'=>100.00,'imported'=>true), - array('id'=>'ITN002','name'=>'CPU','quantity'=>1,'price'=>150.00,'imported'=>true), - array('id'=>'ITN003','name'=>'Harddrive','quantity'=>2,'price'=>80.00,'imported'=>true), - array('id'=>'ITN004','name'=>'Sound card','quantity'=>1,'price'=>40.00,'imported'=>false), - array('id'=>'ITN005','name'=>'Video card','quantity'=>1,'price'=>150.00,'imported'=>true), - array('id'=>'ITN006','name'=>'Keyboard','quantity'=>1,'price'=>20.00,'imported'=>false), - array('id'=>'ITN007','name'=>'Monitor','quantity'=>2,'price'=>300.00,'imported'=>true), - array('id'=>'ITN008','name'=>'CDRW drive','quantity'=>1,'price'=>40.00,'imported'=>true), - array('id'=>'ITN009','name'=>'Cooling fan','quantity'=>2,'price'=>10.00,'imported'=>false), - array('id'=>'ITN010','name'=>'Video camera','quantity'=>20,'price'=>30.00,'imported'=>true), - array('id'=>'ITN011','name'=>'Card reader','quantity'=>10,'price'=>24.00,'imported'=>true), - array('id'=>'ITN012','name'=>'Floppy drive','quantity'=>50,'price'=>12.00,'imported'=>false), - array('id'=>'ITN013','name'=>'CD drive','quantity'=>25,'price'=>20.00,'imported'=>true), - array('id'=>'ITN014','name'=>'DVD drive','quantity'=>15,'price'=>80.00,'imported'=>true), - array('id'=>'ITN015','name'=>'Mouse pad','quantity'=>50,'price'=>5.00,'imported'=>false), - array('id'=>'ITN016','name'=>'Network cable','quantity'=>40,'price'=>8.00,'imported'=>true), - array('id'=>'ITN017','name'=>'Case','quantity'=>8,'price'=>65.00,'imported'=>false), - array('id'=>'ITN018','name'=>'Surge protector','quantity'=>45,'price'=>15.00,'imported'=>false), - array('id'=>'ITN019','name'=>'Speaker','quantity'=>35,'price'=>65.00,'imported'=>false), - ); - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } - } -} - +'ITN001','name'=>'Motherboard','quantity'=>1,'price'=>100.00,'imported'=>true), + array('id'=>'ITN002','name'=>'CPU','quantity'=>1,'price'=>150.00,'imported'=>true), + array('id'=>'ITN003','name'=>'Harddrive','quantity'=>2,'price'=>80.00,'imported'=>true), + array('id'=>'ITN004','name'=>'Sound card','quantity'=>1,'price'=>40.00,'imported'=>false), + array('id'=>'ITN005','name'=>'Video card','quantity'=>1,'price'=>150.00,'imported'=>true), + array('id'=>'ITN006','name'=>'Keyboard','quantity'=>1,'price'=>20.00,'imported'=>false), + array('id'=>'ITN007','name'=>'Monitor','quantity'=>2,'price'=>300.00,'imported'=>true), + array('id'=>'ITN008','name'=>'CDRW drive','quantity'=>1,'price'=>40.00,'imported'=>true), + array('id'=>'ITN009','name'=>'Cooling fan','quantity'=>2,'price'=>10.00,'imported'=>false), + array('id'=>'ITN010','name'=>'Video camera','quantity'=>20,'price'=>30.00,'imported'=>true), + array('id'=>'ITN011','name'=>'Card reader','quantity'=>10,'price'=>24.00,'imported'=>true), + array('id'=>'ITN012','name'=>'Floppy drive','quantity'=>50,'price'=>12.00,'imported'=>false), + array('id'=>'ITN013','name'=>'CD drive','quantity'=>25,'price'=>20.00,'imported'=>true), + array('id'=>'ITN014','name'=>'DVD drive','quantity'=>15,'price'=>80.00,'imported'=>true), + array('id'=>'ITN015','name'=>'Mouse pad','quantity'=>50,'price'=>5.00,'imported'=>false), + array('id'=>'ITN016','name'=>'Network cable','quantity'=>40,'price'=>8.00,'imported'=>true), + array('id'=>'ITN017','name'=>'Case','quantity'=>8,'price'=>65.00,'imported'=>false), + array('id'=>'ITN018','name'=>'Surge protector','quantity'=>45,'price'=>15.00,'imported'=>false), + array('id'=>'ITN019','name'=>'Speaker','quantity'=>35,'price'=>65.00,'imported'=>false), + ); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample2.php b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample2.php index a49077b5..026d1a5a 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample2.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample2.php @@ -1,86 +1,86 @@ -'0596007124', - 'title'=>'Head First Design Patterns', - 'publisher'=>'O\'Reilly Media, Inc.', - 'price'=>29.67, - 'instock'=>true, - 'rating'=>4, - ), - array( - 'ISBN'=>'0201633612', - 'title'=>'Design Patterns: Elements of Reusable Object-Oriented Software', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>47.04, - 'instock'=>true, - 'rating'=>5, - ), - array( - 'ISBN'=>'0321247140', - 'title'=>'Design Patterns Explained : A New Perspective on Object-Oriented Design', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>37.49, - 'instock'=>true, - 'rating'=>4, - ), - array( - 'ISBN'=>'0201485672', - 'title'=>'Refactoring: Improving the Design of Existing Code', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>47.14, - 'instock'=>true, - 'rating'=>3, - ), - array( - 'ISBN'=>'0321213351', - 'title'=>'Refactoring to Patterns', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>38.49, - 'instock'=>true, - 'rating'=>2, - ), - array( - 'ISBN'=>'0735619670', - 'title'=>'Code Complete', - 'publisher'=>'Microsoft Press', - 'price'=>32.99, - 'instock'=>false, - 'rating'=>4, - ), - array( - 'ISBN'=>'0321278658', - 'title'=>'Extreme Programming Explained : Embrace Change', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>34.99, - 'instock'=>true, - 'rating'=>3, - ), - ); - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } - } - - public function toggleColumnVisibility($sender,$param) - { - foreach($this->DataGrid->Columns as $index=>$column) - $column->Visible=$sender->Items[$index]->Selected; - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } -} - +'0596007124', + 'title'=>'Head First Design Patterns', + 'publisher'=>'O\'Reilly Media, Inc.', + 'price'=>29.67, + 'instock'=>true, + 'rating'=>4, + ), + array( + 'ISBN'=>'0201633612', + 'title'=>'Design Patterns: Elements of Reusable Object-Oriented Software', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>47.04, + 'instock'=>true, + 'rating'=>5, + ), + array( + 'ISBN'=>'0321247140', + 'title'=>'Design Patterns Explained : A New Perspective on Object-Oriented Design', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>37.49, + 'instock'=>true, + 'rating'=>4, + ), + array( + 'ISBN'=>'0201485672', + 'title'=>'Refactoring: Improving the Design of Existing Code', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>47.14, + 'instock'=>true, + 'rating'=>3, + ), + array( + 'ISBN'=>'0321213351', + 'title'=>'Refactoring to Patterns', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>38.49, + 'instock'=>true, + 'rating'=>2, + ), + array( + 'ISBN'=>'0735619670', + 'title'=>'Code Complete', + 'publisher'=>'Microsoft Press', + 'price'=>32.99, + 'instock'=>false, + 'rating'=>4, + ), + array( + 'ISBN'=>'0321278658', + 'title'=>'Extreme Programming Explained : Embrace Change', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>34.99, + 'instock'=>true, + 'rating'=>3, + ), + ); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + } + + public function toggleColumnVisibility($sender,$param) + { + foreach($this->DataGrid->Columns as $index=>$column) + $column->Visible=$sender->Items[$index]->Selected; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.php b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.php index bb18f36b..74085a0f 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample3.php @@ -1,190 +1,190 @@ -_data===null) - $this->loadData(); - return $this->_data; - } - - protected function loadData() - { - // We use viewstate keep track of data. - // In real applications, data should come from database using an SQL SELECT statement. - // In the following tabular data, field 'ISBN' is the primary key. - // All update and delete operations should come with an 'id' value in order to go through. - if(($this->_data=$this->getViewState('Data',null))===null) - { - $this->_data=array( - array( - 'ISBN'=>'0596007124', - 'title'=>'Head First Design Patterns', - 'publisher'=>'O\'Reilly Media, Inc.', - 'price'=>29.67, - 'instock'=>true, - 'rating'=>4, - ), - array( - 'ISBN'=>'0201633612', - 'title'=>'Design Patterns: Elements of Reusable Object-Oriented Software', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>47.04, - 'instock'=>true, - 'rating'=>5, - ), - array( - 'ISBN'=>'0321247140', - 'title'=>'Design Patterns Explained : A New Perspective on Object-Oriented Design', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>37.49, - 'instock'=>true, - 'rating'=>4, - ), - array( - 'ISBN'=>'0201485672', - 'title'=>'Refactoring: Improving the Design of Existing Code', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>47.14, - 'instock'=>true, - 'rating'=>3, - ), - array( - 'ISBN'=>'0321213351', - 'title'=>'Refactoring to Patterns', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>38.49, - 'instock'=>true, - 'rating'=>2, - ), - array( - 'ISBN'=>'0735619670', - 'title'=>'Code Complete', - 'publisher'=>'Microsoft Press', - 'price'=>32.99, - 'instock'=>false, - 'rating'=>4, - ), - array( - 'ISBN'=>'0321278658 ', - 'title'=>'Extreme Programming Explained : Embrace Change', - 'publisher'=>'Addison-Wesley Professional', - 'price'=>34.99, - 'instock'=>true, - 'rating'=>3, - ), - ); - $this->saveData(); - } - } - - protected function saveData() - { - $this->setViewState('Data',$this->_data); - } - - protected function updateBook($isbn,$title,$publisher,$price,$instock,$rating) - { - // In real applications, data should be saved to database using an SQL UPDATE statement - if($this->_data===null) - $this->loadData(); - $updateRow=null; - foreach($this->_data as $index=>$row) - if($row['ISBN']===$isbn) - $updateRow=&$this->_data[$index]; - if($updateRow!==null) - { - $updateRow['title']=$title; - $updateRow['publisher']=$publisher; - $updateRow['price']=TPropertyValue::ensureFloat(ltrim($price,'$')); - $updateRow['instock']=TPropertyValue::ensureBoolean($instock); - $updateRow['rating']=TPropertyValue::ensureInteger($rating); - $this->saveData(); - } - } - - protected function deleteBook($isbn) - { - // In real applications, data should be saved to database using an SQL DELETE statement - if($this->_data===null) - $this->loadData(); - $deleteIndex=-1; - foreach($this->_data as $index=>$row) - if($row['ISBN']===$isbn) - $deleteIndex=$index; - if($deleteIndex>=0) - { - unset($this->_data[$deleteIndex]); - $this->saveData(); - } - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } - } - - public function itemCreated($sender,$param) - { - $item=$param->Item; - if($item->ItemType==='EditItem') - { - // set column width of textboxes - $item->BookTitleColumn->TextBox->Columns=40; - $item->PriceColumn->TextBox->Columns=5; - } - if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem' || $item->ItemType==='EditItem') - { - // add an aleart dialog to delete buttons - $item->DeleteColumn->Button->Attributes->onclick='if(!confirm(\'Are you sure?\')) return false;'; - } - } - - public function editItem($sender,$param) - { - $this->DataGrid->EditItemIndex=$param->Item->ItemIndex; - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } - - public function saveItem($sender,$param) - { - $item=$param->Item; - $this->updateBook( - $this->DataGrid->DataKeys[$item->ItemIndex], // ISBN - $item->BookTitleColumn->TextBox->Text, // title - $item->PublisherColumn->TextBox->Text, // publisher - $item->PriceColumn->TextBox->Text, // price - $item->InStockColumn->CheckBox->Checked, // instock - $item->RatingColumn->DropDownList->SelectedValue // rating - ); - $this->DataGrid->EditItemIndex=-1; - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } - - public function cancelItem($sender,$param) - { - $this->DataGrid->EditItemIndex=-1; - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } - - public function deleteItem($sender,$param) - { - $this->deleteBook($this->DataGrid->DataKeys[$param->Item->ItemIndex]); - $this->DataGrid->EditItemIndex=-1; - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } -} - +_data===null) + $this->loadData(); + return $this->_data; + } + + protected function loadData() + { + // We use viewstate keep track of data. + // In real applications, data should come from database using an SQL SELECT statement. + // In the following tabular data, field 'ISBN' is the primary key. + // All update and delete operations should come with an 'id' value in order to go through. + if(($this->_data=$this->getViewState('Data',null))===null) + { + $this->_data=array( + array( + 'ISBN'=>'0596007124', + 'title'=>'Head First Design Patterns', + 'publisher'=>'O\'Reilly Media, Inc.', + 'price'=>29.67, + 'instock'=>true, + 'rating'=>4, + ), + array( + 'ISBN'=>'0201633612', + 'title'=>'Design Patterns: Elements of Reusable Object-Oriented Software', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>47.04, + 'instock'=>true, + 'rating'=>5, + ), + array( + 'ISBN'=>'0321247140', + 'title'=>'Design Patterns Explained : A New Perspective on Object-Oriented Design', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>37.49, + 'instock'=>true, + 'rating'=>4, + ), + array( + 'ISBN'=>'0201485672', + 'title'=>'Refactoring: Improving the Design of Existing Code', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>47.14, + 'instock'=>true, + 'rating'=>3, + ), + array( + 'ISBN'=>'0321213351', + 'title'=>'Refactoring to Patterns', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>38.49, + 'instock'=>true, + 'rating'=>2, + ), + array( + 'ISBN'=>'0735619670', + 'title'=>'Code Complete', + 'publisher'=>'Microsoft Press', + 'price'=>32.99, + 'instock'=>false, + 'rating'=>4, + ), + array( + 'ISBN'=>'0321278658 ', + 'title'=>'Extreme Programming Explained : Embrace Change', + 'publisher'=>'Addison-Wesley Professional', + 'price'=>34.99, + 'instock'=>true, + 'rating'=>3, + ), + ); + $this->saveData(); + } + } + + protected function saveData() + { + $this->setViewState('Data',$this->_data); + } + + protected function updateBook($isbn,$title,$publisher,$price,$instock,$rating) + { + // In real applications, data should be saved to database using an SQL UPDATE statement + if($this->_data===null) + $this->loadData(); + $updateRow=null; + foreach($this->_data as $index=>$row) + if($row['ISBN']===$isbn) + $updateRow=&$this->_data[$index]; + if($updateRow!==null) + { + $updateRow['title']=$title; + $updateRow['publisher']=$publisher; + $updateRow['price']=TPropertyValue::ensureFloat(ltrim($price,'$')); + $updateRow['instock']=TPropertyValue::ensureBoolean($instock); + $updateRow['rating']=TPropertyValue::ensureInteger($rating); + $this->saveData(); + } + } + + protected function deleteBook($isbn) + { + // In real applications, data should be saved to database using an SQL DELETE statement + if($this->_data===null) + $this->loadData(); + $deleteIndex=-1; + foreach($this->_data as $index=>$row) + if($row['ISBN']===$isbn) + $deleteIndex=$index; + if($deleteIndex>=0) + { + unset($this->_data[$deleteIndex]); + $this->saveData(); + } + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + } + + public function itemCreated($sender,$param) + { + $item=$param->Item; + if($item->ItemType==='EditItem') + { + // set column width of textboxes + $item->BookTitleColumn->TextBox->Columns=40; + $item->PriceColumn->TextBox->Columns=5; + } + if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem' || $item->ItemType==='EditItem') + { + // add an aleart dialog to delete buttons + $item->DeleteColumn->Button->Attributes->onclick='if(!confirm(\'Are you sure?\')) return false;'; + } + } + + public function editItem($sender,$param) + { + $this->DataGrid->EditItemIndex=$param->Item->ItemIndex; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + + public function saveItem($sender,$param) + { + $item=$param->Item; + $this->updateBook( + $this->DataGrid->DataKeys[$item->ItemIndex], // ISBN + $item->BookTitleColumn->TextBox->Text, // title + $item->PublisherColumn->TextBox->Text, // publisher + $item->PriceColumn->TextBox->Text, // price + $item->InStockColumn->CheckBox->Checked, // instock + $item->RatingColumn->DropDownList->SelectedValue // rating + ); + $this->DataGrid->EditItemIndex=-1; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + + public function cancelItem($sender,$param) + { + $this->DataGrid->EditItemIndex=-1; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + + public function deleteItem($sender,$param) + { + $this->deleteBook($this->DataGrid->DataKeys[$param->Item->ItemIndex]); + $this->DataGrid->EditItemIndex=-1; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample4.php b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample4.php index f9c0804d..ba7cba11 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample4.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample4.php @@ -1,21 +1,21 @@ - $b["'.$key.'"]) ? 1 : -1;}'); - usort($data,$compare) ; - return $data ; - } - - public function sortDataGrid($sender,$param) - { - $this->DataGrid->DataSource=$this->sortData($this->Data,$param->SortExpression); - $this->DataGrid->dataBind(); - } -} - + $b["'.$key.'"]) ? 1 : -1;}'); + usort($data,$compare) ; + return $data ; + } + + public function sortDataGrid($sender,$param) + { + $this->DataGrid->DataSource=$this->sortData($this->Data,$param->SortExpression); + $this->DataGrid->dataBind(); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample5.php b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample5.php index bdca2ca8..fcf075ea 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample5.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample5.php @@ -1,68 +1,68 @@ -DataGrid->CurrentPageIndex=$param->NewPageIndex; - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } - - public function pagerCreated($sender,$param) - { - $param->Pager->Controls->insertAt(0,'Page: '); - } - - public function changePagerPosition($sender,$param) - { - $top=$sender->Items[0]->Selected; - $bottom=$sender->Items[1]->Selected; - if($top && $bottom) - $position='TopAndBottom'; - else if($top) - $position='Top'; - else if($bottom) - $position='Bottom'; - else - $position=''; - if($position==='') - $this->DataGrid->PagerStyle->Visible=false; - else - { - $this->DataGrid->PagerStyle->Position=$position; - $this->DataGrid->PagerStyle->Visible=true; - } - } - - public function useNumericPager($sender,$param) - { - $this->DataGrid->PagerStyle->Mode='Numeric'; - $this->DataGrid->PagerStyle->NextPageText=$this->NextPageText->Text; - $this->DataGrid->PagerStyle->PrevPageText=$this->PrevPageText->Text; - $this->DataGrid->PagerStyle->PageButtonCount=$this->PageButtonCount->Text; - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } - - public function useNextPrevPager($sender,$param) - { - $this->DataGrid->PagerStyle->Mode='NextPrev'; - $this->DataGrid->PagerStyle->NextPageText=$this->NextPageText->Text; - $this->DataGrid->PagerStyle->PrevPageText=$this->PrevPageText->Text; - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } - - public function changePageSize($sender,$param) - { - $this->DataGrid->PageSize=TPropertyValue::ensureInteger($this->PageSize->Text); - $this->DataGrid->CurrentPageIndex=0; - $this->DataGrid->DataSource=$this->Data; - $this->DataGrid->dataBind(); - } -} - +DataGrid->CurrentPageIndex=$param->NewPageIndex; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + + public function pagerCreated($sender,$param) + { + $param->Pager->Controls->insertAt(0,'Page: '); + } + + public function changePagerPosition($sender,$param) + { + $top=$sender->Items[0]->Selected; + $bottom=$sender->Items[1]->Selected; + if($top && $bottom) + $position='TopAndBottom'; + else if($top) + $position='Top'; + else if($bottom) + $position='Bottom'; + else + $position=''; + if($position==='') + $this->DataGrid->PagerStyle->Visible=false; + else + { + $this->DataGrid->PagerStyle->Position=$position; + $this->DataGrid->PagerStyle->Visible=true; + } + } + + public function useNumericPager($sender,$param) + { + $this->DataGrid->PagerStyle->Mode='Numeric'; + $this->DataGrid->PagerStyle->NextPageText=$this->NextPageText->Text; + $this->DataGrid->PagerStyle->PrevPageText=$this->PrevPageText->Text; + $this->DataGrid->PagerStyle->PageButtonCount=$this->PageButtonCount->Text; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + + public function useNextPrevPager($sender,$param) + { + $this->DataGrid->PagerStyle->Mode='NextPrev'; + $this->DataGrid->PagerStyle->NextPageText=$this->NextPageText->Text; + $this->DataGrid->PagerStyle->PrevPageText=$this->PrevPageText->Text; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } + + public function changePageSize($sender,$param) + { + $this->DataGrid->PageSize=TPropertyValue::ensureInteger($this->PageSize->Text); + $this->DataGrid->CurrentPageIndex=0; + $this->DataGrid->DataSource=$this->Data; + $this->DataGrid->dataBind(); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample6.php b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample6.php index 90e3f7fe..3f24c9ac 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample6.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TDataGrid/Sample6.php @@ -1,56 +1,56 @@ -getData(); - $page=array(); - for($i=0;$i<$rows;++$i) - { - if($offset+$i<$this->getRowCount()) - $page[$i]=$data[$offset+$i]; - } - return $page; - } - - /** - * Returns total number of data rows. - * In real DB applications, this may be replaced by an SQL select - * query with count(). - * @return integer total number of data rows - */ - protected function getRowCount() - { - return 19; - } - - public function onLoad($param) - { - if(!$this->IsPostBack) - { - $this->DataGrid->DataSource=$this->getDataRows(0,$this->DataGrid->PageSize); - $this->DataGrid->dataBind(); - } - } - - public function changePage($sender,$param) - { - $this->DataGrid->CurrentPageIndex=$param->NewPageIndex; - $offset=$param->NewPageIndex*$this->DataGrid->PageSize; - $this->DataGrid->DataSource=$this->getDataRows($offset,$this->DataGrid->PageSize); - $this->DataGrid->dataBind(); - } -} - +getData(); + $page=array(); + for($i=0;$i<$rows;++$i) + { + if($offset+$i<$this->getRowCount()) + $page[$i]=$data[$offset+$i]; + } + return $page; + } + + /** + * Returns total number of data rows. + * In real DB applications, this may be replaced by an SQL select + * query with count(). + * @return integer total number of data rows + */ + protected function getRowCount() + { + return 19; + } + + public function onLoad($param) + { + if(!$this->IsPostBack) + { + $this->DataGrid->DataSource=$this->getDataRows(0,$this->DataGrid->PageSize); + $this->DataGrid->dataBind(); + } + } + + public function changePage($sender,$param) + { + $this->DataGrid->CurrentPageIndex=$param->NewPageIndex; + $offset=$param->NewPageIndex*$this->DataGrid->PageSize; + $this->DataGrid->DataSource=$this->getDataRows($offset,$this->DataGrid->PageSize); + $this->DataGrid->dataBind(); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample1.php b/demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample1.php index 7b8a2ae4..037036f5 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample1.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample1.php @@ -1,41 +1,41 @@ -'ITN001','name'=>'Motherboard','quantity'=>1,'price'=>100.00,'imported'=>true), - array('id'=>'ITN002','name'=>'CPU','quantity'=>1,'price'=>150.00,'imported'=>true), - array('id'=>'ITN003','name'=>'Harddrive','quantity'=>2,'price'=>80.00,'imported'=>true), - array('id'=>'ITN004','name'=>'Sound card','quantity'=>1,'price'=>40.00,'imported'=>false), - array('id'=>'ITN005','name'=>'Video card','quantity'=>1,'price'=>150.00,'imported'=>true), - array('id'=>'ITN006','name'=>'Keyboard','quantity'=>1,'price'=>20.00,'imported'=>false), - array('id'=>'ITN007','name'=>'Monitor','quantity'=>2,'price'=>300.00,'imported'=>true), - array('id'=>'ITN008','name'=>'CDRW drive','quantity'=>1,'price'=>40.00,'imported'=>true), - array('id'=>'ITN009','name'=>'Cooling fan','quantity'=>2,'price'=>10.00,'imported'=>false), - array('id'=>'ITN010','name'=>'Video camera','quantity'=>20,'price'=>30.00,'imported'=>true), - array('id'=>'ITN011','name'=>'Card reader','quantity'=>10,'price'=>24.00,'imported'=>true), - array('id'=>'ITN012','name'=>'Floppy drive','quantity'=>50,'price'=>12.00,'imported'=>false), - array('id'=>'ITN013','name'=>'CD drive','quantity'=>25,'price'=>20.00,'imported'=>true), - array('id'=>'ITN014','name'=>'DVD drive','quantity'=>15,'price'=>80.00,'imported'=>true), - array('id'=>'ITN015','name'=>'Mouse pad','quantity'=>50,'price'=>5.00,'imported'=>false), - array('id'=>'ITN016','name'=>'Network cable','quantity'=>40,'price'=>8.00,'imported'=>true), - array('id'=>'ITN017','name'=>'Case','quantity'=>8,'price'=>65.00,'imported'=>false), - array('id'=>'ITN018','name'=>'Surge protector','quantity'=>45,'price'=>15.00,'imported'=>false), - array('id'=>'ITN019','name'=>'Speaker','quantity'=>35,'price'=>65.00,'imported'=>false), - ); - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $this->DataList->DataSource=$this->Data; - $this->DataList->dataBind(); - } - } -} - +'ITN001','name'=>'Motherboard','quantity'=>1,'price'=>100.00,'imported'=>true), + array('id'=>'ITN002','name'=>'CPU','quantity'=>1,'price'=>150.00,'imported'=>true), + array('id'=>'ITN003','name'=>'Harddrive','quantity'=>2,'price'=>80.00,'imported'=>true), + array('id'=>'ITN004','name'=>'Sound card','quantity'=>1,'price'=>40.00,'imported'=>false), + array('id'=>'ITN005','name'=>'Video card','quantity'=>1,'price'=>150.00,'imported'=>true), + array('id'=>'ITN006','name'=>'Keyboard','quantity'=>1,'price'=>20.00,'imported'=>false), + array('id'=>'ITN007','name'=>'Monitor','quantity'=>2,'price'=>300.00,'imported'=>true), + array('id'=>'ITN008','name'=>'CDRW drive','quantity'=>1,'price'=>40.00,'imported'=>true), + array('id'=>'ITN009','name'=>'Cooling fan','quantity'=>2,'price'=>10.00,'imported'=>false), + array('id'=>'ITN010','name'=>'Video camera','quantity'=>20,'price'=>30.00,'imported'=>true), + array('id'=>'ITN011','name'=>'Card reader','quantity'=>10,'price'=>24.00,'imported'=>true), + array('id'=>'ITN012','name'=>'Floppy drive','quantity'=>50,'price'=>12.00,'imported'=>false), + array('id'=>'ITN013','name'=>'CD drive','quantity'=>25,'price'=>20.00,'imported'=>true), + array('id'=>'ITN014','name'=>'DVD drive','quantity'=>15,'price'=>80.00,'imported'=>true), + array('id'=>'ITN015','name'=>'Mouse pad','quantity'=>50,'price'=>5.00,'imported'=>false), + array('id'=>'ITN016','name'=>'Network cable','quantity'=>40,'price'=>8.00,'imported'=>true), + array('id'=>'ITN017','name'=>'Case','quantity'=>8,'price'=>65.00,'imported'=>false), + array('id'=>'ITN018','name'=>'Surge protector','quantity'=>45,'price'=>15.00,'imported'=>false), + array('id'=>'ITN019','name'=>'Speaker','quantity'=>35,'price'=>65.00,'imported'=>false), + ); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $this->DataList->DataSource=$this->Data; + $this->DataList->dataBind(); + } + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample2.php b/demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample2.php index 9715f5ba..7273dd39 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample2.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TDataList/Sample2.php @@ -1,132 +1,132 @@ -_data===null) - $this->loadData(); - return $this->_data; - } - - protected function loadData() - { - // We use viewstate keep track of data. - // In real applications, data should come from database using an SQL SELECT statement. - // In the following tabular data, field 'id' is the primary key. - // All update and delete operations should come with an 'id' value in order to go through. - if(($this->_data=$this->getViewState('Data',null))===null) - { - $this->_data=array( - array('id'=>'ITN001','name'=>'Motherboard','quantity'=>1,'price'=>100.00,'imported'=>true), - array('id'=>'ITN002','name'=>'CPU','quantity'=>1,'price'=>150.00,'imported'=>true), - array('id'=>'ITN003','name'=>'Harddrive','quantity'=>2,'price'=>80.00,'imported'=>false), - array('id'=>'ITN004','name'=>'Sound card','quantity'=>1,'price'=>40.00,'imported'=>false), - array('id'=>'ITN005','name'=>'Video card','quantity'=>1,'price'=>150.00,'imported'=>true), - array('id'=>'ITN006','name'=>'Keyboard','quantity'=>1,'price'=>20.00,'imported'=>true), - array('id'=>'ITN007','name'=>'Monitor','quantity'=>2,'price'=>300.00,'imported'=>false), - ); - $this->saveData(); - } - } - - protected function saveData() - { - $this->setViewState('Data',$this->_data); - } - - protected function updateProduct($id,$name,$quantity,$price,$imported) - { - // In real applications, data should be saved to database using an SQL UPDATE statement - if($this->_data===null) - $this->loadData(); - $updateRow=null; - foreach($this->_data as $index=>$row) - if($row['id']===$id) - $updateRow=&$this->_data[$index]; - if($updateRow!==null) - { - $updateRow['name']=$name; - $updateRow['quantity']=TPropertyValue::ensureInteger($quantity); - $updateRow['price']=TPropertyValue::ensureFloat($price); - $updateRow['imported']=TPropertyValue::ensureBoolean($imported); - $this->saveData(); - } - } - - protected function deleteProduct($id) - { - // In real applications, data should be saved to database using an SQL DELETE statement - if($this->_data===null) - $this->loadData(); - $deleteIndex=-1; - foreach($this->_data as $index=>$row) - if($row['id']===$id) - $deleteIndex=$index; - if($deleteIndex>=0) - { - unset($this->_data[$deleteIndex]); - $this->saveData(); - } - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $this->DataList->DataSource=$this->Data; - $this->DataList->dataBind(); - } - } - - public function editItem($sender,$param) - { - $this->DataList->SelectedItemIndex=-1; - $this->DataList->EditItemIndex=$param->Item->ItemIndex; - $this->DataList->DataSource=$this->Data; - $this->DataList->dataBind(); - } - - public function cancelItem($sender,$param) - { - $this->DataList->SelectedItemIndex=-1; - $this->DataList->EditItemIndex=-1; - $this->DataList->DataSource=$this->Data; - $this->DataList->dataBind(); - } - - public function updateItem($sender,$param) - { - $item=$param->Item; - $this->updateProduct( - $this->DataList->DataKeys[$item->ItemIndex], - $item->ProductName->Text, - $item->ProductQuantity->Text, - $item->ProductPrice->Text, - $item->ProductImported->Checked); - $this->DataList->EditItemIndex=-1; - $this->DataList->DataSource=$this->Data; - $this->DataList->dataBind(); - } - - public function deleteItem($sender,$param) - { - $this->deleteProduct($this->DataList->DataKeys[$param->Item->ItemIndex]); - $this->DataList->SelectedItemIndex=-1; - $this->DataList->EditItemIndex=-1; - $this->DataList->DataSource=$this->Data; - $this->DataList->dataBind(); - } - - public function selectItem($sender,$param) - { - $this->DataList->EditItemIndex=-1; - $this->DataList->DataSource=$this->Data; - $this->DataList->dataBind(); - } -} - +_data===null) + $this->loadData(); + return $this->_data; + } + + protected function loadData() + { + // We use viewstate keep track of data. + // In real applications, data should come from database using an SQL SELECT statement. + // In the following tabular data, field 'id' is the primary key. + // All update and delete operations should come with an 'id' value in order to go through. + if(($this->_data=$this->getViewState('Data',null))===null) + { + $this->_data=array( + array('id'=>'ITN001','name'=>'Motherboard','quantity'=>1,'price'=>100.00,'imported'=>true), + array('id'=>'ITN002','name'=>'CPU','quantity'=>1,'price'=>150.00,'imported'=>true), + array('id'=>'ITN003','name'=>'Harddrive','quantity'=>2,'price'=>80.00,'imported'=>false), + array('id'=>'ITN004','name'=>'Sound card','quantity'=>1,'price'=>40.00,'imported'=>false), + array('id'=>'ITN005','name'=>'Video card','quantity'=>1,'price'=>150.00,'imported'=>true), + array('id'=>'ITN006','name'=>'Keyboard','quantity'=>1,'price'=>20.00,'imported'=>true), + array('id'=>'ITN007','name'=>'Monitor','quantity'=>2,'price'=>300.00,'imported'=>false), + ); + $this->saveData(); + } + } + + protected function saveData() + { + $this->setViewState('Data',$this->_data); + } + + protected function updateProduct($id,$name,$quantity,$price,$imported) + { + // In real applications, data should be saved to database using an SQL UPDATE statement + if($this->_data===null) + $this->loadData(); + $updateRow=null; + foreach($this->_data as $index=>$row) + if($row['id']===$id) + $updateRow=&$this->_data[$index]; + if($updateRow!==null) + { + $updateRow['name']=$name; + $updateRow['quantity']=TPropertyValue::ensureInteger($quantity); + $updateRow['price']=TPropertyValue::ensureFloat($price); + $updateRow['imported']=TPropertyValue::ensureBoolean($imported); + $this->saveData(); + } + } + + protected function deleteProduct($id) + { + // In real applications, data should be saved to database using an SQL DELETE statement + if($this->_data===null) + $this->loadData(); + $deleteIndex=-1; + foreach($this->_data as $index=>$row) + if($row['id']===$id) + $deleteIndex=$index; + if($deleteIndex>=0) + { + unset($this->_data[$deleteIndex]); + $this->saveData(); + } + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $this->DataList->DataSource=$this->Data; + $this->DataList->dataBind(); + } + } + + public function editItem($sender,$param) + { + $this->DataList->SelectedItemIndex=-1; + $this->DataList->EditItemIndex=$param->Item->ItemIndex; + $this->DataList->DataSource=$this->Data; + $this->DataList->dataBind(); + } + + public function cancelItem($sender,$param) + { + $this->DataList->SelectedItemIndex=-1; + $this->DataList->EditItemIndex=-1; + $this->DataList->DataSource=$this->Data; + $this->DataList->dataBind(); + } + + public function updateItem($sender,$param) + { + $item=$param->Item; + $this->updateProduct( + $this->DataList->DataKeys[$item->ItemIndex], + $item->ProductName->Text, + $item->ProductQuantity->Text, + $item->ProductPrice->Text, + $item->ProductImported->Checked); + $this->DataList->EditItemIndex=-1; + $this->DataList->DataSource=$this->Data; + $this->DataList->dataBind(); + } + + public function deleteItem($sender,$param) + { + $this->deleteProduct($this->DataList->DataKeys[$param->Item->ItemIndex]); + $this->DataList->SelectedItemIndex=-1; + $this->DataList->EditItemIndex=-1; + $this->DataList->DataSource=$this->Data; + $this->DataList->dataBind(); + } + + public function selectItem($sender,$param) + { + $this->DataList->EditItemIndex=-1; + $this->DataList->DataSource=$this->Data; + $this->DataList->dataBind(); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDataTypeValidator/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TDataTypeValidator/Home.php index 88d2dbf2..1c5efbcf 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TDataTypeValidator/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TDataTypeValidator/Home.php @@ -1,8 +1,8 @@ - \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.php index 133a797a..74e47b6c 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TDropDownList/Home.php @@ -1,69 +1,69 @@ -IsPostBack) - { - $data=array('item 1','item 2','item 3','item 4'); - $this->DBDropDownList1->DataSource=$data; - $this->DBDropDownList1->dataBind(); - - $data=array('key 1'=>'item 1','key 2'=>'item 2', - 'key 3'=>'item 3','key 4'=>'item 4'); - $this->DBDropDownList2->DataSource=$data; - $this->DBDropDownList2->dataBind(); - - $data=array( - array('id'=>'001','name'=>'John','age'=>31), - array('id'=>'002','name'=>'Mary','age'=>30), - array('id'=>'003','name'=>'Cary','age'=>20)); - $this->DBDropDownList3->DataSource=$data; - $this->DBDropDownList3->dataBind(); - } - } - - protected function collectSelectionResult($input,$output) - { - $indices=$input->SelectedIndices; - $result=''; - foreach($indices as $index) - { - $item=$input->Items[$index]; - $result.="(Index: $index, Value: $item->Value, Text: $item->Text)"; - } - if($result==='') - $output->Text='Your selection is empty.'; - else - $output->Text='Your selection is: '.$result; - } - - public function DBDropDownList1Changed($sender,$param) - { - $this->collectSelectionResult($sender,$this->DBDropDownList1Result); - } - - public function DBDropDownList2Changed($sender,$param) - { - $this->collectSelectionResult($sender,$this->DBDropDownList2Result); - } - - public function DBDropDownList3Changed($sender,$param) - { - $this->collectSelectionResult($sender,$this->DBDropDownList3Result); - } - - public function selectionChanged($sender,$param) - { - $this->collectSelectionResult($sender,$this->SelectionResult); - } - - public function buttonClicked($sender,$param) - { - $this->collectSelectionResult($this->DropDownList1,$this->SelectionResult2); - } -} - +IsPostBack) + { + $data=array('item 1','item 2','item 3','item 4'); + $this->DBDropDownList1->DataSource=$data; + $this->DBDropDownList1->dataBind(); + + $data=array('key 1'=>'item 1','key 2'=>'item 2', + 'key 3'=>'item 3','key 4'=>'item 4'); + $this->DBDropDownList2->DataSource=$data; + $this->DBDropDownList2->dataBind(); + + $data=array( + array('id'=>'001','name'=>'John','age'=>31), + array('id'=>'002','name'=>'Mary','age'=>30), + array('id'=>'003','name'=>'Cary','age'=>20)); + $this->DBDropDownList3->DataSource=$data; + $this->DBDropDownList3->dataBind(); + } + } + + protected function collectSelectionResult($input,$output) + { + $indices=$input->SelectedIndices; + $result=''; + foreach($indices as $index) + { + $item=$input->Items[$index]; + $result.="(Index: $index, Value: $item->Value, Text: $item->Text)"; + } + if($result==='') + $output->Text='Your selection is empty.'; + else + $output->Text='Your selection is: '.$result; + } + + public function DBDropDownList1Changed($sender,$param) + { + $this->collectSelectionResult($sender,$this->DBDropDownList1Result); + } + + public function DBDropDownList2Changed($sender,$param) + { + $this->collectSelectionResult($sender,$this->DBDropDownList2Result); + } + + public function DBDropDownList3Changed($sender,$param) + { + $this->collectSelectionResult($sender,$this->DBDropDownList3Result); + } + + public function selectionChanged($sender,$param) + { + $this->collectSelectionResult($sender,$this->SelectionResult); + } + + public function buttonClicked($sender,$param) + { + $this->collectSelectionResult($this->DropDownList1,$this->SelectionResult2); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.php index 88d2dbf2..1c5efbcf 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TEmailAddressValidator/Home.php @@ -1,8 +1,8 @@ - \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TFileUpload/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TFileUpload/Home.php index d5cf990a..29d05a1c 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TFileUpload/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TFileUpload/Home.php @@ -1,21 +1,21 @@ -HasFile) - { - $this->Result->Text=" - You just uploaded a file: -
- Name: {$sender->FileName} -
- Size: {$sender->FileSize} -
- Type: {$sender->FileType}"; - } - } -} - +HasFile) + { + $this->Result->Text=" + You just uploaded a file: +
+ Name: {$sender->FileName} +
+ Size: {$sender->FileSize} +
+ Type: {$sender->FileType}"; + } + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/THtmlArea/Home.php b/demos/quickstart/protected/pages/Controls/Samples/THtmlArea/Home.php index c56b5229..255a2bf3 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/THtmlArea/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/THtmlArea/Home.php @@ -1,21 +1,21 @@ -Result1->Text="You have entered: ".$this->HtmlArea1->Text; - } - - public function button2Clicked($sender,$param) - { - $this->Result2->Text="You have entered: ".$this->HtmlArea2->Text; - } - - public function button3Clicked($sender,$param) - { - $this->Result3->Text="You have entered: ".$this->HtmlArea3->Text; - } -} - +Result1->Text="You have entered: ".$this->HtmlArea1->Text; + } + + public function button2Clicked($sender,$param) + { + $this->Result2->Text="You have entered: ".$this->HtmlArea2->Text; + } + + public function button3Clicked($sender,$param) + { + $this->Result3->Text="You have entered: ".$this->HtmlArea3->Text; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TImageButton/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TImageButton/Home.php index df61ed82..e30aab2b 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TImageButton/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TImageButton/Home.php @@ -1,18 +1,18 @@ -Result2->Text="Command name: $param->CommandName, Command parameter: $param->CommandParameter"; - } - else - { - $this->Result->Text="You clicked at ($param->X,$param->Y)"; - } - } -} - +Result2->Text="Command name: $param->CommandName, Command parameter: $param->CommandParameter"; + } + else + { + $this->Result->Text="You clicked at ($param->X,$param->Y)"; + } + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TImageMap/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TImageMap/Home.php index b8e17941..01294c60 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TImageMap/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TImageMap/Home.php @@ -1,11 +1,11 @@ -Result->Text="Your post value is : ".$param->PostBackValue; - } -} - +Result->Text="Your post value is : ".$param->PostBackValue; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TKeyboard/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TKeyboard/Home.php index 689f45c8..d725dc06 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TKeyboard/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TKeyboard/Home.php @@ -1,11 +1,11 @@ -Result->Text='You have entered "'.$this->PasswordInput->Text.'".'; - } -} - +Result->Text='You have entered "'.$this->PasswordInput->Text.'".'; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TLinkButton/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TLinkButton/Home.php index f18072f2..3711ca46 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TLinkButton/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TLinkButton/Home.php @@ -1,14 +1,14 @@ -Text="Name: {$param->CommandName}, Param: {$param->CommandParameter}"; - else - $sender->Text="I'm clicked"; - } -} - +Text="Name: {$param->CommandName}, Param: {$param->CommandParameter}"; + else + $sender->Text="I'm clicked"; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.php index a570d38b..9e5add52 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TListBox/Home.php @@ -1,79 +1,79 @@ -IsPostBack) - { - $data=array('item 1','item 2','item 3','item 4'); - $this->DBListBox1->DataSource=$data; - $this->DBListBox1->dataBind(); - - $data=array('key 1'=>'item 1','key 2'=>'item 2', - 'key 3'=>'item 3','key 4'=>'item 4'); - $this->DBListBox2->DataSource=$data; - $this->DBListBox2->dataBind(); - - $data=array( - array('id'=>'001','name'=>'John','age'=>31), - array('id'=>'002','name'=>'Mary','age'=>30), - array('id'=>'003','name'=>'Cary','age'=>20)); - $this->DBListBox3->DataSource=$data; - $this->DBListBox3->dataBind(); - } - } - - public function DBListBox1Changed($sender,$param) - { - $this->collectSelectionResult($sender,$this->DBListBox1Result); - } - - public function DBListBox2Changed($sender,$param) - { - $this->collectSelectionResult($sender,$this->DBListBox2Result); - } - - public function DBListBox3Changed($sender,$param) - { - $this->collectSelectionResult($sender,$this->DBListBox3Result); - } - - protected function collectSelectionResult($input,$output) - { - $indices=$input->SelectedIndices; - $result=''; - foreach($indices as $index) - { - $item=$input->Items[$index]; - $result.="(Index: $index, Value: $item->Value, Text: $item->Text)"; - } - if($result==='') - $output->Text='Your selection is empty.'; - else - $output->Text='Your selection is: '.$result; - } - - public function selectionChanged($sender,$param) - { - $this->collectSelectionResult($sender,$this->SelectionResult); - } - - public function buttonClicked($sender,$param) - { - $this->collectSelectionResult($this->ListBox1,$this->SelectionResult2); - } - - public function multiSelectionChanged($sender,$param) - { - $this->collectSelectionResult($sender,$this->MultiSelectionResult); - } - - public function buttonClicked2($sender,$param) - { - $this->collectSelectionResult($this->ListBox2,$this->MultiSelectionResult2); - } -} - +IsPostBack) + { + $data=array('item 1','item 2','item 3','item 4'); + $this->DBListBox1->DataSource=$data; + $this->DBListBox1->dataBind(); + + $data=array('key 1'=>'item 1','key 2'=>'item 2', + 'key 3'=>'item 3','key 4'=>'item 4'); + $this->DBListBox2->DataSource=$data; + $this->DBListBox2->dataBind(); + + $data=array( + array('id'=>'001','name'=>'John','age'=>31), + array('id'=>'002','name'=>'Mary','age'=>30), + array('id'=>'003','name'=>'Cary','age'=>20)); + $this->DBListBox3->DataSource=$data; + $this->DBListBox3->dataBind(); + } + } + + public function DBListBox1Changed($sender,$param) + { + $this->collectSelectionResult($sender,$this->DBListBox1Result); + } + + public function DBListBox2Changed($sender,$param) + { + $this->collectSelectionResult($sender,$this->DBListBox2Result); + } + + public function DBListBox3Changed($sender,$param) + { + $this->collectSelectionResult($sender,$this->DBListBox3Result); + } + + protected function collectSelectionResult($input,$output) + { + $indices=$input->SelectedIndices; + $result=''; + foreach($indices as $index) + { + $item=$input->Items[$index]; + $result.="(Index: $index, Value: $item->Value, Text: $item->Text)"; + } + if($result==='') + $output->Text='Your selection is empty.'; + else + $output->Text='Your selection is: '.$result; + } + + public function selectionChanged($sender,$param) + { + $this->collectSelectionResult($sender,$this->SelectionResult); + } + + public function buttonClicked($sender,$param) + { + $this->collectSelectionResult($this->ListBox1,$this->SelectionResult2); + } + + public function multiSelectionChanged($sender,$param) + { + $this->collectSelectionResult($sender,$this->MultiSelectionResult); + } + + public function buttonClicked2($sender,$param) + { + $this->collectSelectionResult($this->ListBox2,$this->MultiSelectionResult2); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TMultiView/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TMultiView/Home.php index 1a5dbed3..24a240ca 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TMultiView/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TMultiView/Home.php @@ -1,15 +1,15 @@ -MultiView->ActiveViewIndex===2) - { - $this->Result1->Text="Your text input is: ".$this->Memo->Text; - $this->Result2->Text="Your color choice is: ".$this->DropDownList->SelectedValue; - } - } -} - +MultiView->ActiveViewIndex===2) + { + $this->Result1->Text="Your text input is: ".$this->Memo->Text; + $this->Result2->Text="Your color choice is: ".$this->DropDownList->SelectedValue; + } + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TPager/Sample1.php b/demos/quickstart/protected/pages/Controls/Samples/TPager/Sample1.php index e5446f60..86563cc1 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TPager/Sample1.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TPager/Sample1.php @@ -1,82 +1,82 @@ -'ITN001','name'=>'Motherboard','quantity'=>1,'price'=>100.00,'imported'=>true), - array('id'=>'ITN002','name'=>'CPU','quantity'=>1,'price'=>150.00,'imported'=>true), - array('id'=>'ITN003','name'=>'Harddrive','quantity'=>2,'price'=>80.00,'imported'=>true), - array('id'=>'ITN004','name'=>'Sound card','quantity'=>1,'price'=>40.00,'imported'=>false), - array('id'=>'ITN005','name'=>'Video card','quantity'=>1,'price'=>150.00,'imported'=>true), - array('id'=>'ITN006','name'=>'Keyboard','quantity'=>1,'price'=>20.00,'imported'=>false), - array('id'=>'ITN007','name'=>'Monitor','quantity'=>2,'price'=>300.00,'imported'=>true), - array('id'=>'ITN008','name'=>'CDRW drive','quantity'=>1,'price'=>40.00,'imported'=>true), - array('id'=>'ITN009','name'=>'Cooling fan','quantity'=>2,'price'=>10.00,'imported'=>false), - array('id'=>'ITN010','name'=>'Video camera','quantity'=>20,'price'=>30.00,'imported'=>true), - array('id'=>'ITN011','name'=>'Card reader','quantity'=>10,'price'=>24.00,'imported'=>true), - array('id'=>'ITN012','name'=>'Floppy drive','quantity'=>50,'price'=>12.00,'imported'=>false), - array('id'=>'ITN013','name'=>'CD drive','quantity'=>25,'price'=>20.00,'imported'=>true), - array('id'=>'ITN014','name'=>'DVD drive','quantity'=>15,'price'=>80.00,'imported'=>true), - array('id'=>'ITN015','name'=>'Mouse pad','quantity'=>50,'price'=>5.00,'imported'=>false), - array('id'=>'ITN016','name'=>'Network cable','quantity'=>40,'price'=>8.00,'imported'=>true), - array('id'=>'ITN017','name'=>'Case','quantity'=>8,'price'=>65.00,'imported'=>false), - array('id'=>'ITN018','name'=>'Surge protector','quantity'=>45,'price'=>15.00,'imported'=>false), - array('id'=>'ITN019','name'=>'Speaker','quantity'=>35,'price'=>65.00,'imported'=>false), - ); - return array_slice($data,$offset,$limit); - } - - /** - * Determines which page of data to be displayed and - * populates the datalist with the fetched data. - */ - protected function populateData() - { - $offset=$this->DataList->CurrentPageIndex*$this->DataList->PageSize; - $limit=$this->DataList->PageSize; - if($offset+$limit>$this->DataList->VirtualItemCount) - $limit=$this->DataList->VirtualItemCount-$offset; - $data=$this->getData($offset,$limit); - $this->DataList->DataSource=$data; - $this->DataList->dataBind(); - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $this->DataList->VirtualItemCount=$this->DataItemCount; - $this->populateData(); - } - } - - /** - * Event handler to the OnPageIndexChanged event of pagers. - */ - public function pageChanged($sender,$param) - { - $this->DataList->CurrentPageIndex=$param->NewPageIndex; - $this->populateData(); - } -} - +'ITN001','name'=>'Motherboard','quantity'=>1,'price'=>100.00,'imported'=>true), + array('id'=>'ITN002','name'=>'CPU','quantity'=>1,'price'=>150.00,'imported'=>true), + array('id'=>'ITN003','name'=>'Harddrive','quantity'=>2,'price'=>80.00,'imported'=>true), + array('id'=>'ITN004','name'=>'Sound card','quantity'=>1,'price'=>40.00,'imported'=>false), + array('id'=>'ITN005','name'=>'Video card','quantity'=>1,'price'=>150.00,'imported'=>true), + array('id'=>'ITN006','name'=>'Keyboard','quantity'=>1,'price'=>20.00,'imported'=>false), + array('id'=>'ITN007','name'=>'Monitor','quantity'=>2,'price'=>300.00,'imported'=>true), + array('id'=>'ITN008','name'=>'CDRW drive','quantity'=>1,'price'=>40.00,'imported'=>true), + array('id'=>'ITN009','name'=>'Cooling fan','quantity'=>2,'price'=>10.00,'imported'=>false), + array('id'=>'ITN010','name'=>'Video camera','quantity'=>20,'price'=>30.00,'imported'=>true), + array('id'=>'ITN011','name'=>'Card reader','quantity'=>10,'price'=>24.00,'imported'=>true), + array('id'=>'ITN012','name'=>'Floppy drive','quantity'=>50,'price'=>12.00,'imported'=>false), + array('id'=>'ITN013','name'=>'CD drive','quantity'=>25,'price'=>20.00,'imported'=>true), + array('id'=>'ITN014','name'=>'DVD drive','quantity'=>15,'price'=>80.00,'imported'=>true), + array('id'=>'ITN015','name'=>'Mouse pad','quantity'=>50,'price'=>5.00,'imported'=>false), + array('id'=>'ITN016','name'=>'Network cable','quantity'=>40,'price'=>8.00,'imported'=>true), + array('id'=>'ITN017','name'=>'Case','quantity'=>8,'price'=>65.00,'imported'=>false), + array('id'=>'ITN018','name'=>'Surge protector','quantity'=>45,'price'=>15.00,'imported'=>false), + array('id'=>'ITN019','name'=>'Speaker','quantity'=>35,'price'=>65.00,'imported'=>false), + ); + return array_slice($data,$offset,$limit); + } + + /** + * Determines which page of data to be displayed and + * populates the datalist with the fetched data. + */ + protected function populateData() + { + $offset=$this->DataList->CurrentPageIndex*$this->DataList->PageSize; + $limit=$this->DataList->PageSize; + if($offset+$limit>$this->DataList->VirtualItemCount) + $limit=$this->DataList->VirtualItemCount-$offset; + $data=$this->getData($offset,$limit); + $this->DataList->DataSource=$data; + $this->DataList->dataBind(); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $this->DataList->VirtualItemCount=$this->DataItemCount; + $this->populateData(); + } + } + + /** + * Event handler to the OnPageIndexChanged event of pagers. + */ + public function pageChanged($sender,$param) + { + $this->DataList->CurrentPageIndex=$param->NewPageIndex; + $this->populateData(); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TPanel/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TPanel/Home.php index d6cf1bd5..1864f380 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TPanel/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TPanel/Home.php @@ -1,11 +1,11 @@ -Result->Text="You have clicked on '$sender->Text'."; - } -} - +Result->Text="You have clicked on '$sender->Text'."; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TPlaceHolder/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TPlaceHolder/Home.php index ecae7876..8987c230 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TPlaceHolder/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TPlaceHolder/Home.php @@ -1,16 +1,16 @@ -Text='dynamic'; - $label->BackColor='silver'; - $this->PlaceHolder1->Controls[]=$label; - $this->PlaceHolder1->Controls[]=' content'; - } -} - +Text='dynamic'; + $label->BackColor='silver'; + $this->PlaceHolder1->Controls[]=$label; + $this->PlaceHolder1->Controls[]=' content'; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRadioButton/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TRadioButton/Home.php index 034d2fcc..a0c2af32 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TRadioButton/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TRadioButton/Home.php @@ -1,27 +1,27 @@ -Text="I'm clicked"; - } - - public function selectRadioButton($sender,$param) - { - $selection=''; - if($this->Radio1->Checked) - $selection.='1'; - if($this->Radio2->Checked) - $selection.='2'; - if($this->Radio3->Checked) - $selection.='3'; - if($this->Radio4->Checked) - $selection.='4'; - if($selection==='') - $selection='empty'; - $this->Result->Text='Your selection is '.$selection; - } -} - +Text="I'm clicked"; + } + + public function selectRadioButton($sender,$param) + { + $selection=''; + if($this->Radio1->Checked) + $selection.='1'; + if($this->Radio2->Checked) + $selection.='2'; + if($this->Radio3->Checked) + $selection.='3'; + if($this->Radio4->Checked) + $selection.='4'; + if($selection==='') + $selection='empty'; + $this->Result->Text='Your selection is '.$selection; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.php index b45441f9..62b4d7e7 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TRadioButtonList/Home.php @@ -1,69 +1,69 @@ -IsPostBack) - { - $data=array('item 1','item 2','item 3','item 4'); - $this->DBRadioButtonList1->DataSource=$data; - $this->DBRadioButtonList1->dataBind(); - - $data=array('key 1'=>'item 1','key 2'=>'item 2', - 'key 3'=>'item 3','key 4'=>'item 4'); - $this->DBRadioButtonList2->DataSource=$data; - $this->DBRadioButtonList2->dataBind(); - - $data=array( - array('id'=>'001','name'=>'John','age'=>31), - array('id'=>'002','name'=>'Mary','age'=>30), - array('id'=>'003','name'=>'Cary','age'=>20)); - $this->DBRadioButtonList3->DataSource=$data; - $this->DBRadioButtonList3->dataBind(); - } - } - - protected function collectSelectionResult($input,$output) - { - $indices=$input->SelectedIndices; - $result=''; - foreach($indices as $index) - { - $item=$input->Items[$index]; - $result.="(Index: $index, Value: $item->Value, Text: $item->Text)"; - } - if($result==='') - $output->Text='Your selection is empty.'; - else - $output->Text='Your selection is: '.$result; - } - - public function buttonClicked($sender,$param) - { - $this->collectSelectionResult($this->RadioButtonList,$this->SelectionResult); - } - - public function selectionChanged($sender,$param) - { - $this->collectSelectionResult($sender,$this->SelectionResult2); - } - - public function DBRadioButtonList1Changed($sender,$param) - { - $this->collectSelectionResult($sender,$this->DBRadioButtonList1Result); - } - - public function DBRadioButtonList2Changed($sender,$param) - { - $this->collectSelectionResult($sender,$this->DBRadioButtonList2Result); - } - - public function DBRadioButtonList3Changed($sender,$param) - { - $this->collectSelectionResult($sender,$this->DBRadioButtonList3Result); - } -} - +IsPostBack) + { + $data=array('item 1','item 2','item 3','item 4'); + $this->DBRadioButtonList1->DataSource=$data; + $this->DBRadioButtonList1->dataBind(); + + $data=array('key 1'=>'item 1','key 2'=>'item 2', + 'key 3'=>'item 3','key 4'=>'item 4'); + $this->DBRadioButtonList2->DataSource=$data; + $this->DBRadioButtonList2->dataBind(); + + $data=array( + array('id'=>'001','name'=>'John','age'=>31), + array('id'=>'002','name'=>'Mary','age'=>30), + array('id'=>'003','name'=>'Cary','age'=>20)); + $this->DBRadioButtonList3->DataSource=$data; + $this->DBRadioButtonList3->dataBind(); + } + } + + protected function collectSelectionResult($input,$output) + { + $indices=$input->SelectedIndices; + $result=''; + foreach($indices as $index) + { + $item=$input->Items[$index]; + $result.="(Index: $index, Value: $item->Value, Text: $item->Text)"; + } + if($result==='') + $output->Text='Your selection is empty.'; + else + $output->Text='Your selection is: '.$result; + } + + public function buttonClicked($sender,$param) + { + $this->collectSelectionResult($this->RadioButtonList,$this->SelectionResult); + } + + public function selectionChanged($sender,$param) + { + $this->collectSelectionResult($sender,$this->SelectionResult2); + } + + public function DBRadioButtonList1Changed($sender,$param) + { + $this->collectSelectionResult($sender,$this->DBRadioButtonList1Result); + } + + public function DBRadioButtonList2Changed($sender,$param) + { + $this->collectSelectionResult($sender,$this->DBRadioButtonList2Result); + } + + public function DBRadioButtonList3Changed($sender,$param) + { + $this->collectSelectionResult($sender,$this->DBRadioButtonList3Result); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRangeValidator/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TRangeValidator/Home.php index 88d2dbf2..1c5efbcf 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TRangeValidator/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TRangeValidator/Home.php @@ -1,8 +1,8 @@ - \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.php index 88d2dbf2..1c5efbcf 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TRegularExpressionValidator/Home.php @@ -1,8 +1,8 @@ - \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/RegionDisplay.php b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/RegionDisplay.php index 40d1841e..4f7ab6c2 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/RegionDisplay.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/RegionDisplay.php @@ -1,28 +1,28 @@ -Data is available which - * refers to the data row associated with the parent repeater item. - */ - public function onDataBinding($param) - { - parent::onDataBinding($param); - $this->Repeater->DataSource=$this->Data['detail']; - $this->Repeater->dataBind(); - } - - public function itemCreated($sender,$param) - { - static $itemIndex=0; - $item=$param->Item; - if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem') - $item->Row->BackColor=$itemIndex%2 ? "#BFCFFF" : "#E6ECFF"; - $itemIndex++; - } -} - +Data is available which + * refers to the data row associated with the parent repeater item. + */ + public function onDataBinding($param) + { + parent::onDataBinding($param); + $this->Repeater->DataSource=$this->Data['detail']; + $this->Repeater->dataBind(); + } + + public function itemCreated($sender,$param) + { + static $itemIndex=0; + $item=$param->Item; + if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem') + $item->Row->BackColor=$itemIndex%2 ? "#BFCFFF" : "#E6ECFF"; + $itemIndex++; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample1.php b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample1.php index 905a3b8d..c3cff79b 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample1.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample1.php @@ -1,41 +1,41 @@ -'ITN001','name'=>'Motherboard','quantity'=>1,'price'=>100.00,'imported'=>true), - array('id'=>'ITN002','name'=>'CPU','quantity'=>1,'price'=>150.00,'imported'=>true), - array('id'=>'ITN003','name'=>'Harddrive','quantity'=>2,'price'=>80.00,'imported'=>true), - array('id'=>'ITN004','name'=>'Sound card','quantity'=>1,'price'=>40.00,'imported'=>false), - array('id'=>'ITN005','name'=>'Video card','quantity'=>1,'price'=>150.00,'imported'=>true), - array('id'=>'ITN006','name'=>'Keyboard','quantity'=>1,'price'=>20.00,'imported'=>false), - array('id'=>'ITN007','name'=>'Monitor','quantity'=>2,'price'=>300.00,'imported'=>true), - array('id'=>'ITN008','name'=>'CDRW drive','quantity'=>1,'price'=>40.00,'imported'=>true), - array('id'=>'ITN009','name'=>'Cooling fan','quantity'=>2,'price'=>10.00,'imported'=>false), - array('id'=>'ITN010','name'=>'Video camera','quantity'=>20,'price'=>30.00,'imported'=>true), - array('id'=>'ITN011','name'=>'Card reader','quantity'=>10,'price'=>24.00,'imported'=>true), - array('id'=>'ITN012','name'=>'Floppy drive','quantity'=>50,'price'=>12.00,'imported'=>false), - array('id'=>'ITN013','name'=>'CD drive','quantity'=>25,'price'=>20.00,'imported'=>true), - array('id'=>'ITN014','name'=>'DVD drive','quantity'=>15,'price'=>80.00,'imported'=>true), - array('id'=>'ITN015','name'=>'Mouse pad','quantity'=>50,'price'=>5.00,'imported'=>false), - array('id'=>'ITN016','name'=>'Network cable','quantity'=>40,'price'=>8.00,'imported'=>true), - array('id'=>'ITN017','name'=>'Case','quantity'=>8,'price'=>65.00,'imported'=>false), - array('id'=>'ITN018','name'=>'Surge protector','quantity'=>45,'price'=>15.00,'imported'=>false), - array('id'=>'ITN019','name'=>'Speaker','quantity'=>35,'price'=>65.00,'imported'=>false), - ); - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $this->Repeater->DataSource=$this->getData(); - $this->Repeater->dataBind(); - } - } -} - +'ITN001','name'=>'Motherboard','quantity'=>1,'price'=>100.00,'imported'=>true), + array('id'=>'ITN002','name'=>'CPU','quantity'=>1,'price'=>150.00,'imported'=>true), + array('id'=>'ITN003','name'=>'Harddrive','quantity'=>2,'price'=>80.00,'imported'=>true), + array('id'=>'ITN004','name'=>'Sound card','quantity'=>1,'price'=>40.00,'imported'=>false), + array('id'=>'ITN005','name'=>'Video card','quantity'=>1,'price'=>150.00,'imported'=>true), + array('id'=>'ITN006','name'=>'Keyboard','quantity'=>1,'price'=>20.00,'imported'=>false), + array('id'=>'ITN007','name'=>'Monitor','quantity'=>2,'price'=>300.00,'imported'=>true), + array('id'=>'ITN008','name'=>'CDRW drive','quantity'=>1,'price'=>40.00,'imported'=>true), + array('id'=>'ITN009','name'=>'Cooling fan','quantity'=>2,'price'=>10.00,'imported'=>false), + array('id'=>'ITN010','name'=>'Video camera','quantity'=>20,'price'=>30.00,'imported'=>true), + array('id'=>'ITN011','name'=>'Card reader','quantity'=>10,'price'=>24.00,'imported'=>true), + array('id'=>'ITN012','name'=>'Floppy drive','quantity'=>50,'price'=>12.00,'imported'=>false), + array('id'=>'ITN013','name'=>'CD drive','quantity'=>25,'price'=>20.00,'imported'=>true), + array('id'=>'ITN014','name'=>'DVD drive','quantity'=>15,'price'=>80.00,'imported'=>true), + array('id'=>'ITN015','name'=>'Mouse pad','quantity'=>50,'price'=>5.00,'imported'=>false), + array('id'=>'ITN016','name'=>'Network cable','quantity'=>40,'price'=>8.00,'imported'=>true), + array('id'=>'ITN017','name'=>'Case','quantity'=>8,'price'=>65.00,'imported'=>false), + array('id'=>'ITN018','name'=>'Surge protector','quantity'=>45,'price'=>15.00,'imported'=>false), + array('id'=>'ITN019','name'=>'Speaker','quantity'=>35,'price'=>65.00,'imported'=>false), + ); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $this->Repeater->DataSource=$this->getData(); + $this->Repeater->dataBind(); + } + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample2.php b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample2.php index e84580a2..803201e9 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample2.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample2.php @@ -1,79 +1,79 @@ -array( - array('name'=>'John','age'=>30,'position'=>'Program Manager'), - array('name'=>'Edward','age'=>35,'position'=>'Developer'), - array('name'=>'Walter','age'=>28,'position'=>'Developer'), - ), - 'West'=>array( - array('name'=>'Cary','age'=>31,'position'=>'Senior Manager'), - array('name'=>'Ted','age'=>25,'position'=>'Developer'), - array('name'=>'Kevin','age'=>28,'position'=>'Developer'), - ), - 'East'=>array( - array('name'=>'Shawn','age'=>30,'position'=>'Sales Manager'), - array('name'=>'Larry','age'=>28,'position'=>'Document Writer'), - ), - 'South'=>array( - array('name'=>'King','age'=>30,'position'=>'Program Manager'), - array('name'=>'Carter','age'=>22,'position'=>'Developer'), - ), - ); - return $data[$region]; - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $this->Repeater->DataSource=$this->getMasterData(); - $this->Repeater->dataBind(); - } - } - - public function dataBindRepeater2($sender,$param) - { - $item=$param->Item; - if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem') - { - $item->Repeater2->DataSource=$this->getDetailData($item->DataItem); - $item->Repeater2->dataBind(); - } - } - - public function repeaterItemCreated($sender,$param) - { - static $itemIndex=0; - $item=$param->Item; - if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem') - { - $item->Cell->BackColor=$itemIndex%2 ? "#6078BF" : "#809FFF"; - $item->Cell->ForeColor='white'; - $itemIndex++; - } - } - - public function repeater2ItemCreated($sender,$param) - { - static $itemIndex=0; - $item=$param->Item; - if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem') - { - $item->Row->BackColor=$itemIndex%2 ? "#BFCFFF" : "#E6ECFF"; - $itemIndex++; - } - } -} - +array( + array('name'=>'John','age'=>30,'position'=>'Program Manager'), + array('name'=>'Edward','age'=>35,'position'=>'Developer'), + array('name'=>'Walter','age'=>28,'position'=>'Developer'), + ), + 'West'=>array( + array('name'=>'Cary','age'=>31,'position'=>'Senior Manager'), + array('name'=>'Ted','age'=>25,'position'=>'Developer'), + array('name'=>'Kevin','age'=>28,'position'=>'Developer'), + ), + 'East'=>array( + array('name'=>'Shawn','age'=>30,'position'=>'Sales Manager'), + array('name'=>'Larry','age'=>28,'position'=>'Document Writer'), + ), + 'South'=>array( + array('name'=>'King','age'=>30,'position'=>'Program Manager'), + array('name'=>'Carter','age'=>22,'position'=>'Developer'), + ), + ); + return $data[$region]; + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $this->Repeater->DataSource=$this->getMasterData(); + $this->Repeater->dataBind(); + } + } + + public function dataBindRepeater2($sender,$param) + { + $item=$param->Item; + if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem') + { + $item->Repeater2->DataSource=$this->getDetailData($item->DataItem); + $item->Repeater2->dataBind(); + } + } + + public function repeaterItemCreated($sender,$param) + { + static $itemIndex=0; + $item=$param->Item; + if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem') + { + $item->Cell->BackColor=$itemIndex%2 ? "#6078BF" : "#809FFF"; + $item->Cell->ForeColor='white'; + $itemIndex++; + } + } + + public function repeater2ItemCreated($sender,$param) + { + static $itemIndex=0; + $item=$param->Item; + if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem') + { + $item->Row->BackColor=$itemIndex%2 ? "#BFCFFF" : "#E6ECFF"; + $itemIndex++; + } + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample3.php b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample3.php index d4f4c8e9..dbaf598f 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample3.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample3.php @@ -1,79 +1,79 @@ -'ITN001','name'=>'Motherboard','category'=>'CAT004','price'=>100.00,'imported'=>true), - array('id'=>'ITN002','name'=>'CPU','category'=>'CAT004','price'=>150.00,'imported'=>true), - array('id'=>'ITN003','name'=>'Harddrive','category'=>'CAT003','price'=>80.00,'imported'=>true), - array('id'=>'ITN006','name'=>'Keyboard','category'=>'CAT002','price'=>20.00,'imported'=>false), - array('id'=>'ITN008','name'=>'CDRW drive','category'=>'CAT003','price'=>40.00,'imported'=>true), - array('id'=>'ITN009','name'=>'Cooling fan','category'=>'CAT001','price'=>10.00,'imported'=>false), - array('id'=>'ITN012','name'=>'Floppy drive','category'=>'CAT003','price'=>12.00,'imported'=>false), - array('id'=>'ITN013','name'=>'CD drive','category'=>'CAT003','price'=>20.00,'imported'=>true), - array('id'=>'ITN014','name'=>'DVD drive','category'=>'CAT003','price'=>80.00,'imported'=>true), - array('id'=>'ITN015','name'=>'Mouse pad','category'=>'CAT001','price'=>5.00,'imported'=>false), - ); - } - - protected function getCategories() - { - return array( - array('id'=>'CAT001','name'=>'Accessories'), - array('id'=>'CAT002','name'=>'Input Devices'), - array('id'=>'CAT003','name'=>'Drives'), - array('id'=>'CAT004','name'=>'Barebone'), - ); - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $this->Repeater->DataSource=$this->Products; - $this->Repeater->dataBind(); - } - } - - public function repeaterDataBound($sender,$param) - { - $item=$param->Item; - if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem') - { - $item->ProductCategory->DataSource=$this->Categories; - $item->ProductCategory->DataTextField='name'; - $item->ProductCategory->DataValueField='id'; - $item->ProductCategory->dataBind(); - $item->ProductCategory->SelectedValue=$item->DataItem['category']; - } - } - - public function saveInput($sender,$param) - { - if($this->IsValid) - { - $index=0; - $products=$this->Products; - $data=array(); - foreach($this->Repeater->Items as $item) - { - $item=array( - 'id'=>$products[$index]['id'], - 'name'=>$item->ProductName->Text, - 'category'=>$item->ProductCategory->SelectedItem->Text, - 'price'=>TPropertyValue::ensureFloat($item->ProductPrice->Text), - 'imported'=>$item->ProductImported->Checked, - ); - $data[]=$item; - $index++; - } - $this->Repeater2->DataSource=$data; - $this->Repeater2->dataBind(); - } - } -} - +'ITN001','name'=>'Motherboard','category'=>'CAT004','price'=>100.00,'imported'=>true), + array('id'=>'ITN002','name'=>'CPU','category'=>'CAT004','price'=>150.00,'imported'=>true), + array('id'=>'ITN003','name'=>'Harddrive','category'=>'CAT003','price'=>80.00,'imported'=>true), + array('id'=>'ITN006','name'=>'Keyboard','category'=>'CAT002','price'=>20.00,'imported'=>false), + array('id'=>'ITN008','name'=>'CDRW drive','category'=>'CAT003','price'=>40.00,'imported'=>true), + array('id'=>'ITN009','name'=>'Cooling fan','category'=>'CAT001','price'=>10.00,'imported'=>false), + array('id'=>'ITN012','name'=>'Floppy drive','category'=>'CAT003','price'=>12.00,'imported'=>false), + array('id'=>'ITN013','name'=>'CD drive','category'=>'CAT003','price'=>20.00,'imported'=>true), + array('id'=>'ITN014','name'=>'DVD drive','category'=>'CAT003','price'=>80.00,'imported'=>true), + array('id'=>'ITN015','name'=>'Mouse pad','category'=>'CAT001','price'=>5.00,'imported'=>false), + ); + } + + protected function getCategories() + { + return array( + array('id'=>'CAT001','name'=>'Accessories'), + array('id'=>'CAT002','name'=>'Input Devices'), + array('id'=>'CAT003','name'=>'Drives'), + array('id'=>'CAT004','name'=>'Barebone'), + ); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $this->Repeater->DataSource=$this->Products; + $this->Repeater->dataBind(); + } + } + + public function repeaterDataBound($sender,$param) + { + $item=$param->Item; + if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem') + { + $item->ProductCategory->DataSource=$this->Categories; + $item->ProductCategory->DataTextField='name'; + $item->ProductCategory->DataValueField='id'; + $item->ProductCategory->dataBind(); + $item->ProductCategory->SelectedValue=$item->DataItem['category']; + } + } + + public function saveInput($sender,$param) + { + if($this->IsValid) + { + $index=0; + $products=$this->Products; + $data=array(); + foreach($this->Repeater->Items as $item) + { + $item=array( + 'id'=>$products[$index]['id'], + 'name'=>$item->ProductName->Text, + 'category'=>$item->ProductCategory->SelectedItem->Text, + 'price'=>TPropertyValue::ensureFloat($item->ProductPrice->Text), + 'imported'=>$item->ProductImported->Checked, + ); + $data[]=$item; + $index++; + } + $this->Repeater2->DataSource=$data; + $this->Repeater2->dataBind(); + } + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample4.php b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample4.php index aabab157..fb0e4922 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample4.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample4.php @@ -1,37 +1,37 @@ -IsPostBack) - { - // use a dummy data source to create 3 repeater items - $this->Repeater->DataSource=new TDummyDataSource(3); - $this->Repeater->dataBind(); - } - } - - public function itemCreated($sender,$param) - { - // $param->Item refers to the newly created repeater item - $param->Item->Style="width:300px; margin:10px; margin-left:0px"; - } - - public function buttonClicked($sender,$param) - { - $links=array(); - foreach($this->Repeater->Items as $textBox) - { - if($textBox->Text!=='') - $links[]=$textBox->Text; - } - $this->Repeater2->DataSource=$links; - $this->Repeater2->dataBind(); - } -} - +IsPostBack) + { + // use a dummy data source to create 3 repeater items + $this->Repeater->DataSource=new TDummyDataSource(3); + $this->Repeater->dataBind(); + } + } + + public function itemCreated($sender,$param) + { + // $param->Item refers to the newly created repeater item + $param->Item->Style="width:300px; margin:10px; margin-left:0px"; + } + + public function buttonClicked($sender,$param) + { + $links=array(); + foreach($this->Repeater->Items as $textBox) + { + if($textBox->Text!=='') + $links[]=$textBox->Text; + } + $this->Repeater2->DataSource=$links; + $this->Repeater2->dataBind(); + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample5.php b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample5.php index 60beb30e..de6e5bd9 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample5.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TRepeater/Sample5.php @@ -1,52 +1,52 @@ -'North', - 'detail'=>array( - array('name'=>'John','age'=>30,'position'=>'Program Manager'), - array('name'=>'Edward','age'=>35,'position'=>'Developer'), - array('name'=>'Walter','age'=>28,'position'=>'Developer'), - ), - ), - array( - 'name'=>'West', - 'detail'=>array( - array('name'=>'Cary','age'=>31,'position'=>'Senior Manager'), - array('name'=>'Ted','age'=>25,'position'=>'Developer'), - array('name'=>'Kevin','age'=>28,'position'=>'Developer'), - ), - ), - array( - 'name'=>'East', - 'detail'=>array( - array('name'=>'Shawn','age'=>30,'position'=>'Sales Manager'), - array('name'=>'Larry','age'=>28,'position'=>'Document Writer'), - ), - ), - array( - 'name'=>'South', - 'detail'=>array( - array('name'=>'King','age'=>30,'position'=>'Program Manager'), - array('name'=>'Carter','age'=>22,'position'=>'Developer'), - ), - ), - ); - } - - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->IsPostBack) - { - $this->Repeater->DataSource=$this->getData(); - $this->Repeater->dataBind(); - } - } -} - +'North', + 'detail'=>array( + array('name'=>'John','age'=>30,'position'=>'Program Manager'), + array('name'=>'Edward','age'=>35,'position'=>'Developer'), + array('name'=>'Walter','age'=>28,'position'=>'Developer'), + ), + ), + array( + 'name'=>'West', + 'detail'=>array( + array('name'=>'Cary','age'=>31,'position'=>'Senior Manager'), + array('name'=>'Ted','age'=>25,'position'=>'Developer'), + array('name'=>'Kevin','age'=>28,'position'=>'Developer'), + ), + ), + array( + 'name'=>'East', + 'detail'=>array( + array('name'=>'Shawn','age'=>30,'position'=>'Sales Manager'), + array('name'=>'Larry','age'=>28,'position'=>'Document Writer'), + ), + ), + array( + 'name'=>'South', + 'detail'=>array( + array('name'=>'King','age'=>30,'position'=>'Program Manager'), + array('name'=>'Carter','age'=>22,'position'=>'Developer'), + ), + ), + ); + } + + public function onLoad($param) + { + parent::onLoad($param); + if(!$this->IsPostBack) + { + $this->Repeater->DataSource=$this->getData(); + $this->Repeater->dataBind(); + } + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TRequiredFieldValidator/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TRequiredFieldValidator/Home.php index 88d2dbf2..1c5efbcf 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TRequiredFieldValidator/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TRequiredFieldValidator/Home.php @@ -1,8 +1,8 @@ - \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TSlider/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TSlider/Home.php index c1c8a711..228fd727 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TSlider/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TSlider/Home.php @@ -1,9 +1,9 @@ \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TTable/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TTable/Home.php index fa5efe38..505a6ded 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TTable/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TTable/Home.php @@ -1,33 +1,33 @@ -Table->GridLines='Both'; - - $row=new TTableRow; - $this->Table->Rows[]=$row; - - $cell=new TTableHeaderCell; - $cell->Text='Header 1'; - $row->Cells[]=$cell; - - $cell=new TTableHeaderCell; - $cell->Text='Header 2'; - $row->Cells[]=$cell; - - $row=new TTableRow; - $this->Table->Rows[]=$row; - - $cell=new TTableCell; - $cell->Text='Cell 1'; - $row->Cells[]=$cell; - - $cell=new TTableCell; - $cell->Text='Cell 2'; - $row->Cells[]=$cell; - } -} - +Table->GridLines='Both'; + + $row=new TTableRow; + $this->Table->Rows[]=$row; + + $cell=new TTableHeaderCell; + $cell->Text='Header 1'; + $row->Cells[]=$cell; + + $cell=new TTableHeaderCell; + $cell->Text='Header 2'; + $row->Cells[]=$cell; + + $row=new TTableRow; + $this->Table->Rows[]=$row; + + $cell=new TTableCell; + $cell->Text='Cell 1'; + $row->Cells[]=$cell; + + $cell=new TTableCell; + $cell->Text='Cell 2'; + $row->Cells[]=$cell; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TTextBox/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TTextBox/Home.php index f8aa0825..2ac0cb3f 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TTextBox/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TTextBox/Home.php @@ -1,22 +1,22 @@ -Output->dataBind(); - } - - public function textChanged($sender,$param) - { - $sender->Text="text changed"; - } - - public function submitText($sender,$param) - { - $this->TextBox1->Text="You just entered '".$this->TextBox1->Text."'."; - } -} - +Output->dataBind(); + } + + public function textChanged($sender,$param) + { + $sender->Text="text changed"; + } + + public function submitText($sender,$param) + { + $this->TextBox1->Text="You just entered '".$this->TextBox1->Text."'."; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TValidationSummary/Home.php b/demos/quickstart/protected/pages/Controls/Samples/TValidationSummary/Home.php index 88d2dbf2..1c5efbcf 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TValidationSummary/Home.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TValidationSummary/Home.php @@ -1,8 +1,8 @@ - \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample1.php b/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample1.php index 20440e62..5d9bcb1d 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample1.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample1.php @@ -1,11 +1,11 @@ -Result->Text="Your favorite color is: " . $this->DropDownList1->SelectedValue; - } -} - +Result->Text="Your favorite color is: " . $this->DropDownList1->SelectedValue; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample2.php b/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample2.php index a508fbf3..61572075 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample2.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample2.php @@ -1,11 +1,11 @@ -Result->Text="Your favorite color is: " . $this->DropDownList1->SelectedValue; - } -} - +Result->Text="Your favorite color is: " . $this->DropDownList1->SelectedValue; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample3.php b/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample3.php index d85d041a..6e767cd4 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample3.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample3.php @@ -1,25 +1,25 @@ -StudentCheckBox->Checked) - { - $str="You are a college student.
"; - $str.="You are in major: ".$this->DropDownList11->SelectedValue."
"; - $str.="Your favorite sport is: ".$this->DropDownList22->SelectedValue; - } - else - $str="Your favorite sport is: ".$this->DropDownList22->SelectedValue; - $this->Wizard3Result->Text=$str; - } - - public function wizard3NextStep($sender,$param) - { - if($param->CurrentStepIndex===0 && !$this->StudentCheckBox->Checked) - $this->Wizard3->ActiveStepIndex=2; - } -} - +StudentCheckBox->Checked) + { + $str="You are a college student.
"; + $str.="You are in major: ".$this->DropDownList11->SelectedValue."
"; + $str.="Your favorite sport is: ".$this->DropDownList22->SelectedValue; + } + else + $str="Your favorite sport is: ".$this->DropDownList22->SelectedValue; + $this->Wizard3Result->Text=$str; + } + + public function wizard3NextStep($sender,$param) + { + if($param->CurrentStepIndex===0 && !$this->StudentCheckBox->Checked) + $this->Wizard3->ActiveStepIndex=2; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample4.php b/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample4.php index 6b79698d..c7317654 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample4.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample4.php @@ -1,11 +1,11 @@ -Result->Text="Your favorite color is: " . $this->DropDownList1->SelectedValue; - } -} - +Result->Text="Your favorite color is: " . $this->DropDownList1->SelectedValue; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample5.php b/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample5.php index 4ab6d08b..4fb64395 100644 --- a/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample5.php +++ b/demos/quickstart/protected/pages/Controls/Samples/TWizard/Sample5.php @@ -1,12 +1,12 @@ -Result1->Text="Your favorite color is: " . $this->DropDownList1->SelectedValue; - $this->Result2->Text="Your favorite sport is: " . $this->Step2->DropDownList2->SelectedValue; - } -} - +Result1->Text="Your favorite color is: " . $this->DropDownList1->SelectedValue; + $this->Result2->Text="Your favorite sport is: " . $this->Step2->DropDownList2->SelectedValue; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Database/Samples/Scaffold/Home.php b/demos/quickstart/protected/pages/Database/Samples/Scaffold/Home.php index 45d72f1f..4801baed 100644 --- a/demos/quickstart/protected/pages/Database/Samples/Scaffold/Home.php +++ b/demos/quickstart/protected/pages/Database/Samples/Scaffold/Home.php @@ -1,33 +1,33 @@ - \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Fundamentals/Samples/Hangman/Home.php b/demos/quickstart/protected/pages/Fundamentals/Samples/Hangman/Home.php index 711600aa..6aff0859 100644 --- a/demos/quickstart/protected/pages/Fundamentals/Samples/Hangman/Home.php +++ b/demos/quickstart/protected/pages/Fundamentals/Samples/Hangman/Home.php @@ -1,121 +1,121 @@ -IsPostBack) - $this->GameMultiView->ActiveView=$this->IntroView; - } - - public function selectLevel($sender,$param) - { - if(($selection=$this->LevelSelection->SelectedValue)==='') - { - $this->LevelError->Visible=true; - return; - } - else - $this->Level=TPropertyValue::ensureInteger($selection); - $this->Word=$this->generateWord(); - $this->GuessWord=str_repeat('_',strlen($this->Word)); - $this->Misses=0; - $this->GameMultiView->ActiveView=$this->GuessView; - } - - public function guessWord($sender,$param) - { - $sender->Enabled=false; - $letter=$sender->Text; - $word=$this->Word; - $guessWord=$this->GuessWord; - $pos=0; - $success=false; - while(($pos=strpos($word,$letter,$pos))!==false) - { - $guessWord[$pos]=$letter; - $success=true; - $pos++; - } - if($success) - { - $this->GuessWord=$guessWord; - if($guessWord===$word) - $this->GameMultiView->ActiveView=$this->WinView; - } - else - { - $this->Misses++; - if($this->Misses>=$this->Level) - $this->giveUp(null,null); - } - } - - public function giveUp($sender,$param) - { - $this->GameMultiView->ActiveView=$this->LoseView; - } - - public function startAgain($sender,$param) - { - $this->GameMultiView->ActiveView=$this->IntroView; - $this->LevelError->Visible=false; - for($letter=65;$letter<=90;++$letter) - { - $guessLetter='Guess'.chr($letter); - $this->$guessLetter->Enabled=true; - } - } - - protected function generateWord() - { - $wordFile=dirname(__FILE__).'/words.txt'; - $words=preg_split("/[\s,]+/",file_get_contents($wordFile)); - do - { - $i=rand(0,count($words)-1); - $word=$words[$i]; - } while(strlen($word)<5 || !preg_match('/^[a-z]*$/i',$word)); - return strtoupper($word); - } - - public function setLevel($value) - { - $this->setViewState('Level',$value,0); - } - - public function getLevel() - { - return $this->getViewState('Level',0); - } - - public function setWord($value) - { - $this->setViewState('Word',$value,''); - } - - public function getWord() - { - return $this->getViewState('Word',''); - } - - public function getGuessWord() - { - return $this->getViewState('GuessWord',''); - } - - public function setGuessWord($value) - { - $this->setViewState('GuessWord',$value,''); - } - - public function setMisses($value) - { - $this->setViewState('Misses',$value,0); - } - - public function getMisses() - { - return $this->getViewState('Misses',0); - } -} +IsPostBack) + $this->GameMultiView->ActiveView=$this->IntroView; + } + + public function selectLevel($sender,$param) + { + if(($selection=$this->LevelSelection->SelectedValue)==='') + { + $this->LevelError->Visible=true; + return; + } + else + $this->Level=TPropertyValue::ensureInteger($selection); + $this->Word=$this->generateWord(); + $this->GuessWord=str_repeat('_',strlen($this->Word)); + $this->Misses=0; + $this->GameMultiView->ActiveView=$this->GuessView; + } + + public function guessWord($sender,$param) + { + $sender->Enabled=false; + $letter=$sender->Text; + $word=$this->Word; + $guessWord=$this->GuessWord; + $pos=0; + $success=false; + while(($pos=strpos($word,$letter,$pos))!==false) + { + $guessWord[$pos]=$letter; + $success=true; + $pos++; + } + if($success) + { + $this->GuessWord=$guessWord; + if($guessWord===$word) + $this->GameMultiView->ActiveView=$this->WinView; + } + else + { + $this->Misses++; + if($this->Misses>=$this->Level) + $this->giveUp(null,null); + } + } + + public function giveUp($sender,$param) + { + $this->GameMultiView->ActiveView=$this->LoseView; + } + + public function startAgain($sender,$param) + { + $this->GameMultiView->ActiveView=$this->IntroView; + $this->LevelError->Visible=false; + for($letter=65;$letter<=90;++$letter) + { + $guessLetter='Guess'.chr($letter); + $this->$guessLetter->Enabled=true; + } + } + + protected function generateWord() + { + $wordFile=dirname(__FILE__).'/words.txt'; + $words=preg_split("/[\s,]+/",file_get_contents($wordFile)); + do + { + $i=rand(0,count($words)-1); + $word=$words[$i]; + } while(strlen($word)<5 || !preg_match('/^[a-z]*$/i',$word)); + return strtoupper($word); + } + + public function setLevel($value) + { + $this->setViewState('Level',$value,0); + } + + public function getLevel() + { + return $this->getViewState('Level',0); + } + + public function setWord($value) + { + $this->setViewState('Word',$value,''); + } + + public function getWord() + { + return $this->getViewState('Word',''); + } + + public function getGuessWord() + { + return $this->getViewState('GuessWord',''); + } + + public function setGuessWord($value) + { + $this->setViewState('GuessWord',$value,''); + } + + public function setMisses($value) + { + $this->setViewState('Misses',$value,0); + } + + public function getMisses() + { + return $this->getViewState('Misses',0); + } +} ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/Search.php b/demos/quickstart/protected/pages/Search.php index d2dfa7da..c36eba54 100644 --- a/demos/quickstart/protected/pages/Search.php +++ b/demos/quickstart/protected/pages/Search.php @@ -1,56 +1,56 @@ -IsPostBack && strlen($text = $this->search->getText()) > 0) - { - $quickstart = $this->getApplication()->getModule("quickstart_search"); - $hits_1 = $quickstart->find($text); - $this->quickstart_results->setDataSource($hits_1); - $this->quickstart_results->dataBind(); - - $this->emptyResult->setVisible(!count($hits_1)); - } - } - - public function highlightSearch($text) - { - $words = str_word_count($text, 1); - $keys = str_word_count(strtolower($this->search->getText()),1); - $where = 0; - $t = count($words); - for($i = 0; $i<$t; $i++) - { - if($this->containsKeys(strtolower($words[$i]), $keys)) - { - $words[$i] = ''.$words[$i].''; - $where = $i; - break; - } - } - - $min = $where - 15 < 0 ? 0 : $where - 15; - $max = $where + 15 > $t ? $t : $where + 15; - $subtext = array_splice($words, $min, $max-$min); - $prefix = $min == 0 ? '' : '...'; - $suffix = $max == $t ? '' : '...'; - return $prefix.implode(' ', $subtext).$suffix; - } - - protected function containsKeys($word, $keys) - { - foreach($keys as $key) - { - if(is_int(strpos($word, $key))) - return true; - } - return false; - } -} - +IsPostBack && strlen($text = $this->search->getText()) > 0) + { + $quickstart = $this->getApplication()->getModule("quickstart_search"); + $hits_1 = $quickstart->find($text); + $this->quickstart_results->setDataSource($hits_1); + $this->quickstart_results->dataBind(); + + $this->emptyResult->setVisible(!count($hits_1)); + } + } + + public function highlightSearch($text) + { + $words = str_word_count($text, 1); + $keys = str_word_count(strtolower($this->search->getText()),1); + $where = 0; + $t = count($words); + for($i = 0; $i<$t; $i++) + { + if($this->containsKeys(strtolower($words[$i]), $keys)) + { + $words[$i] = ''.$words[$i].''; + $where = $i; + break; + } + } + + $min = $where - 15 < 0 ? 0 : $where - 15; + $max = $where + 15 > $t ? $t : $where + 15; + $subtext = array_splice($words, $min, $max-$min); + $prefix = $min == 0 ? '' : '...'; + $suffix = $max == $t ? '' : '...'; + return $prefix.implode(' ', $subtext).$suffix; + } + + protected function containsKeys($word, $keys) + { + foreach($keys as $key) + { + if(is_int(strpos($word, $key))) + return true; + } + return false; + } +} + ?> \ No newline at end of file diff --git a/demos/quickstart/protected/pages/ViewSource.php b/demos/quickstart/protected/pages/ViewSource.php index f267f318..2bbcf097 100644 --- a/demos/quickstart/protected/pages/ViewSource.php +++ b/demos/quickstart/protected/pages/ViewSource.php @@ -1,112 +1,112 @@ -Request['path']; - $fullPath=realpath($this->Service->BasePath.'/'.$path); - $fileExt=$this->getFileExtension($fullPath); - if($fullPath!==false && is_file($fullPath) && strpos($fullPath,$this->Service->BasePath)!==false) - { - if($this->isFileTypeAllowed($fileExt)) - { - $this->_fullPath=strtr($fullPath,'\\','/'); - $this->_path=strtr(substr($fullPath,strlen($this->Service->BasePath)),'\\','/'); - } - } - if($this->_fullPath===null) - throw new THttpException(500,'File Not Found: %s',$path); - - $this->SourceList->DataSource=$this->SourceFiles; - $this->SourceList->dataBind(); - - $this->Highlighter->Language=$this->getFileLanguage($fileExt); - if($this->Request['lines']==='false') - $this->Highlighter->ShowLineNumbers=false; - $this->SourceView->Text=file_get_contents($this->_fullPath); - } - - public function getFilePath() - { - return $this->_path; - } - - protected function getSourceFiles() - { - $list=array(); - $basePath=dirname($this->_fullPath); - if($dh=opendir($basePath)) - { - while(($file=readdir($dh))!==false) - { - if(is_file($basePath.'/'.$file)) - { - $extension=$this->getFileExtension($basePath.'/'.$file); - if($this->isFileTypeAllowed($extension)) - { - $fileType=$this->getFileType($extension); - $list[]=array( - 'name'=>$file, - 'type'=>$fileType, - 'active'=>basename($this->_fullPath)===$file, - 'url'=>'?page=ViewSource&path=/'.ltrim(strtr(dirname($this->_path),'\\','/').'/'.$file,'/') - ); - } - } - - } - closedir($dh); - } - foreach($list as $item) - $aux[]=$item['name']; - array_multisort($aux, SORT_ASC, $list); - return $list; - } - - protected function isFileTypeAllowed($extension) - { - return in_array($extension,array('tpl','page','php','html')); - } - - protected function getFileExtension($fileName) - { - if(($pos=strrpos($fileName,'.'))===false) - return ''; - else - return substr($fileName,$pos+1); - } - - protected function getFileType($extension) - { - if($extension==='tpl' || $extension==='page') - return 'Template file'; - else - return 'Class file'; - } - - protected function getFileLanguage($extension) - { - switch($extension) - { - case 'page' : - case 'tpl' : - return 'prado'; - case 'php' : - return 'php'; - break; - case 'xml' : - return 'xml'; - break; - default : - return 'html'; - } - } -} - +Request['path']; + $fullPath=realpath($this->Service->BasePath.'/'.$path); + $fileExt=$this->getFileExtension($fullPath); + if($fullPath!==false && is_file($fullPath) && strpos($fullPath,$this->Service->BasePath)!==false) + { + if($this->isFileTypeAllowed($fileExt)) + { + $this->_fullPath=strtr($fullPath,'\\','/'); + $this->_path=strtr(substr($fullPath,strlen($this->Service->BasePath)),'\\','/'); + } + } + if($this->_fullPath===null) + throw new THttpException(500,'File Not Found: %s',$path); + + $this->SourceList->DataSource=$this->SourceFiles; + $this->SourceList->dataBind(); + + $this->Highlighter->Language=$this->getFileLanguage($fileExt); + if($this->Request['lines']==='false') + $this->Highlighter->ShowLineNumbers=false; + $this->SourceView->Text=file_get_contents($this->_fullPath); + } + + public function getFilePath() + { + return $this->_path; + } + + protected function getSourceFiles() + { + $list=array(); + $basePath=dirname($this->_fullPath); + if($dh=opendir($basePath)) + { + while(($file=readdir($dh))!==false) + { + if(is_file($basePath.'/'.$file)) + { + $extension=$this->getFileExtension($basePath.'/'.$file); + if($this->isFileTypeAllowed($extension)) + { + $fileType=$this->getFileType($extension); + $list[]=array( + 'name'=>$file, + 'type'=>$fileType, + 'active'=>basename($this->_fullPath)===$file, + 'url'=>'?page=ViewSource&path=/'.ltrim(strtr(dirname($this->_path),'\\','/').'/'.$file,'/') + ); + } + } + + } + closedir($dh); + } + foreach($list as $item) + $aux[]=$item['name']; + array_multisort($aux, SORT_ASC, $list); + return $list; + } + + protected function isFileTypeAllowed($extension) + { + return in_array($extension,array('tpl','page','php','html')); + } + + protected function getFileExtension($fileName) + { + if(($pos=strrpos($fileName,'.'))===false) + return ''; + else + return substr($fileName,$pos+1); + } + + protected function getFileType($extension) + { + if($extension==='tpl' || $extension==='page') + return 'Template file'; + else + return 'Class file'; + } + + protected function getFileLanguage($extension) + { + switch($extension) + { + case 'page' : + case 'tpl' : + return 'prado'; + case 'php' : + return 'php'; + break; + case 'xml' : + return 'xml'; + break; + default : + return 'html'; + } + } +} + ?> \ No newline at end of file diff --git a/demos/sqlmap/index.php b/demos/sqlmap/index.php index afada2c1..3d7997fa 100644 --- a/demos/sqlmap/index.php +++ b/demos/sqlmap/index.php @@ -1,20 +1,20 @@ -run(); - +run(); + ?> \ No newline at end of file diff --git a/demos/sqlmap/protected/APP_CODE/Person.php b/demos/sqlmap/protected/APP_CODE/Person.php index ad9da4b3..e3daeec6 100644 --- a/demos/sqlmap/protected/APP_CODE/Person.php +++ b/demos/sqlmap/protected/APP_CODE/Person.php @@ -1,26 +1,26 @@ -_birthDate; - } - - public function setBirthDate($value) - { - $this->_birthDate = $value; - } -} - +_birthDate; + } + + public function setBirthDate($value) + { + $this->_birthDate = $value; + } +} + ?> \ No newline at end of file diff --git a/demos/sqlmap/protected/pages/Manual/Layout.php b/demos/sqlmap/protected/pages/Manual/Layout.php index e612d52d..cbdb6c04 100644 --- a/demos/sqlmap/protected/pages/Manual/Layout.php +++ b/demos/sqlmap/protected/pages/Manual/Layout.php @@ -1,7 +1,7 @@ - \ No newline at end of file diff --git a/demos/sqlmap/protected/pages/Manual/TopicList.php b/demos/sqlmap/protected/pages/Manual/TopicList.php index ce827cc0..eb5976a9 100644 --- a/demos/sqlmap/protected/pages/Manual/TopicList.php +++ b/demos/sqlmap/protected/pages/Manual/TopicList.php @@ -1,8 +1,8 @@ - \ No newline at end of file diff --git a/demos/sqlmap/protected/pages/Sample/crud1.php b/demos/sqlmap/protected/pages/Sample/crud1.php index 9ea6e05e..fe1131b8 100644 --- a/demos/sqlmap/protected/pages/Sample/crud1.php +++ b/demos/sqlmap/protected/pages/Sample/crud1.php @@ -1,21 +1,21 @@ -Application->Modules['person-sample']->Client; - $this->personList->DataSource = $sqlmap->queryForList('SelectAll'); - $this->personList->dataBind(); - } - - public function onLoad($param) - { - if(!$this->IsPostBack) - $this->loadData(); - } -} - +Application->Modules['person-sample']->Client; + $this->personList->DataSource = $sqlmap->queryForList('SelectAll'); + $this->personList->dataBind(); + } + + public function onLoad($param) + { + if(!$this->IsPostBack) + $this->loadData(); + } +} + ?> \ No newline at end of file diff --git a/demos/sqlmap/protected/pages/Sample/crud2.php b/demos/sqlmap/protected/pages/Sample/crud2.php index 3d2087bb..18720146 100644 --- a/demos/sqlmap/protected/pages/Sample/crud2.php +++ b/demos/sqlmap/protected/pages/Sample/crud2.php @@ -1,78 +1,78 @@ -Application->Modules['person-sample']->Client; - } - - private function loadData() - { - $this->personList->DataSource = $this->sqlmap()->queryForList('SelectAll'); - $this->personList->dataBind(); - } - - public function onLoad($param) - { - if(!$this->IsPostBack) - $this->loadData(); - } - - protected function editPerson($sender,$param) - { - $this->personList->EditItemIndex=$param->Item->ItemIndex; - $this->loadData(); - } - - protected function deletePerson($sender, $param) - { - $id = $this->getKey($sender, $param); - - $this->sqlmap()->update("Delete", $id); - $this->loadData(); - } - - protected function updatePerson($sender, $param) - { - $person = new Person(); - $person->FirstName = $this->getText($param, 0); - $person->LastName = $this->getText($param, 1); - $person->HeightInMeters = $this->getText($param, 2); - $person->WeightInKilograms = $this->getText($param, 3); - $person->ID = $this->getKey($sender, $param); - - $this->sqlmap()->update("Update", $person); - $this->refreshList($sender, $param); - } - - protected function addNewPerson($sender, $param) - { - $person = new Person; - $person->FirstName = "-- New Person --"; - $this->sqlmap()->insert("Insert", $person); - - $this->loadData();; - } - - protected function refreshList($sender, $param) - { - $this->personList->EditItemIndex=-1; - $this->loadData(); - } - - private function getText($param, $index) - { - $item = $param->Item; - return $item->Cells[$index]->Controls[0]->Text; - } - - private function getKey($sender, $param) - { - return $sender->DataKeys[$param->Item->DataSourceIndex]; - } -} - +Application->Modules['person-sample']->Client; + } + + private function loadData() + { + $this->personList->DataSource = $this->sqlmap()->queryForList('SelectAll'); + $this->personList->dataBind(); + } + + public function onLoad($param) + { + if(!$this->IsPostBack) + $this->loadData(); + } + + protected function editPerson($sender,$param) + { + $this->personList->EditItemIndex=$param->Item->ItemIndex; + $this->loadData(); + } + + protected function deletePerson($sender, $param) + { + $id = $this->getKey($sender, $param); + + $this->sqlmap()->update("Delete", $id); + $this->loadData(); + } + + protected function updatePerson($sender, $param) + { + $person = new Person(); + $person->FirstName = $this->getText($param, 0); + $person->LastName = $this->getText($param, 1); + $person->HeightInMeters = $this->getText($param, 2); + $person->WeightInKilograms = $this->getText($param, 3); + $person->ID = $this->getKey($sender, $param); + + $this->sqlmap()->update("Update", $person); + $this->refreshList($sender, $param); + } + + protected function addNewPerson($sender, $param) + { + $person = new Person; + $person->FirstName = "-- New Person --"; + $this->sqlmap()->insert("Insert", $person); + + $this->loadData();; + } + + protected function refreshList($sender, $param) + { + $this->personList->EditItemIndex=-1; + $this->loadData(); + } + + private function getText($param, $index) + { + $item = $param->Item; + return $item->Cells[$index]->Controls[0]->Text; + } + + private function getKey($sender, $param) + { + return $sender->DataKeys[$param->Item->DataSourceIndex]; + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/index.php b/demos/time-tracker/index.php index 7954aeb9..d1fbccf9 100644 --- a/demos/time-tracker/index.php +++ b/demos/time-tracker/index.php @@ -1,35 +1,35 @@ -getGlobalization(); - $charset = $app ? $app->getCharset() : 'UTF-8'; - return htmlentities($text, ENT_QUOTES, $charset); -} - -$application=new TApplication; -$application->run(); - +getGlobalization(); + $charset = $app ? $app->getCharset() : 'UTF-8'; + return htmlentities($text, ENT_QUOTES, $charset); +} + +$application=new TApplication; +$application->run(); + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/Dao/BaseDao.php b/demos/time-tracker/protected/App_Code/Dao/BaseDao.php index 5edb6af7..a75011d7 100644 --- a/demos/time-tracker/protected/App_Code/Dao/BaseDao.php +++ b/demos/time-tracker/protected/App_Code/Dao/BaseDao.php @@ -1,45 +1,45 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * Base DAO class. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class BaseDao -{ - /** - * @var TSqlMapGateway sqlmap client. - */ - private $_sqlmap; - - /** - * @param TSqlMapGateway sqlmap client. - */ - public function setSqlMap($sqlmap) - { - $this->_sqlmap = $sqlmap; - } - - /** - * @return TSqlMapGateway sqlmap client. - */ - protected function getSqlMap() - { - return $this->_sqlmap; - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * Base DAO class. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class BaseDao +{ + /** + * @var TSqlMapGateway sqlmap client. + */ + private $_sqlmap; + + /** + * @param TSqlMapGateway sqlmap client. + */ + public function setSqlMap($sqlmap) + { + $this->_sqlmap = $sqlmap; + } + + /** + * @return TSqlMapGateway sqlmap client. + */ + protected function getSqlMap() + { + return $this->_sqlmap; + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/Dao/CategoryDao.php b/demos/time-tracker/protected/App_Code/Dao/CategoryDao.php index 7476f036..e43639a0 100644 --- a/demos/time-tracker/protected/App_Code/Dao/CategoryDao.php +++ b/demos/time-tracker/protected/App_Code/Dao/CategoryDao.php @@ -1,53 +1,53 @@ -getSqlMap(); - $exists = $this->getCategoryByNameInProject( - $category->Name, $category->ProjectID); - if(!$exists) - $sqlmap->insert('AddNewCategory', $category); - } - - function getCategoryByID($categoryID) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForObject('GetCategoryByID', $categoryID); - } - - function getAllCategories() - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForList('GetAllCategories'); - } - - function deleteCategory($categoryID) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->delete('DeleteCategory', $categoryID); - } - - function getCategoriesByProjectID($projectID) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForList('GetCategoriesByProjectID', $projectID); - } - - function getCategoryByNameInProject($name, $projectID) - { - $sqlmap = $this->getSqlMap(); - $param['project'] = $projectID; - $param['category'] = $name; - return $sqlmap->queryForObject('GetCategoryByNameInProject', $param); - } - - function updateCategory($category) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->update('UpdateCategory', $category); - } -} - +getSqlMap(); + $exists = $this->getCategoryByNameInProject( + $category->Name, $category->ProjectID); + if(!$exists) + $sqlmap->insert('AddNewCategory', $category); + } + + function getCategoryByID($categoryID) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForObject('GetCategoryByID', $categoryID); + } + + function getAllCategories() + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForList('GetAllCategories'); + } + + function deleteCategory($categoryID) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->delete('DeleteCategory', $categoryID); + } + + function getCategoriesByProjectID($projectID) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForList('GetCategoriesByProjectID', $projectID); + } + + function getCategoryByNameInProject($name, $projectID) + { + $sqlmap = $this->getSqlMap(); + $param['project'] = $projectID; + $param['category'] = $name; + return $sqlmap->queryForObject('GetCategoryByNameInProject', $param); + } + + function updateCategory($category) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->update('UpdateCategory', $category); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/Dao/CategoryRecord.php b/demos/time-tracker/protected/App_Code/Dao/CategoryRecord.php index 876b582d..0394ce92 100644 --- a/demos/time-tracker/protected/App_Code/Dao/CategoryRecord.php +++ b/demos/time-tracker/protected/App_Code/Dao/CategoryRecord.php @@ -1,13 +1,13 @@ - \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/Dao/ProjectDao.php b/demos/time-tracker/protected/App_Code/Dao/ProjectDao.php index 9e8867bc..1d085b47 100644 --- a/demos/time-tracker/protected/App_Code/Dao/ProjectDao.php +++ b/demos/time-tracker/protected/App_Code/Dao/ProjectDao.php @@ -1,105 +1,105 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * Project DAO class. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class ProjectDao extends BaseDao -{ - public function projectNameExists($projectName) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForObject('ProjectNameExists', $projectName); - } - - public function addNewProject($project) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->insert('CreateNewProject', $project); - } - - public function getProjectByID($projectID) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForObject('GetProjectByID', $projectID); - } - - public function deleteProject($projectID) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->update('DeleteProject',$projectID); - } - - public function addUserToProject($projectID, $username) - { - $sqlmap = $this->getSqlMap(); - $members = $this->getProjectMembers($projectID); - if(!in_array($username, $members)) - { - $param['username'] = $username; - $param['project'] = $projectID; - $sqlmap->insert('AddUserToProject',$param); - } - } - - public function getProjectMembers($projectID) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForList('GetProjectMembers', $projectID); - } - - public function getAllProjects($sort='', $order='ASC') - { - $sqlmap = $this->getSqlMap(); - if($sort === '') - return $sqlmap->queryForList('GetAllProjects'); - else - { - $param['sort'] = $sort; - $param['order'] = $order; - return $sqlmap->queryForList('GetAllProjectsOrdered', $param); - } - } - - public function getProjectsByManagerName($manager) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForList('GetProjectsByManagerName', $manager); - } - - public function getProjectsByUserName($username) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForList('GetProjectsByUserName', $username); - } - - public function removeUserFromProject($projectID, $username) - { - $sqlmap = $this->getSqlMap(); - $param['username'] = $username; - $param['project'] = $projectID; - $sqlmap->delete('RemoveUserFromProject', $param); - } - - public function updateProject($project) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->update('UpdateProject', $project); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * Project DAO class. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class ProjectDao extends BaseDao +{ + public function projectNameExists($projectName) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForObject('ProjectNameExists', $projectName); + } + + public function addNewProject($project) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->insert('CreateNewProject', $project); + } + + public function getProjectByID($projectID) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForObject('GetProjectByID', $projectID); + } + + public function deleteProject($projectID) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->update('DeleteProject',$projectID); + } + + public function addUserToProject($projectID, $username) + { + $sqlmap = $this->getSqlMap(); + $members = $this->getProjectMembers($projectID); + if(!in_array($username, $members)) + { + $param['username'] = $username; + $param['project'] = $projectID; + $sqlmap->insert('AddUserToProject',$param); + } + } + + public function getProjectMembers($projectID) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForList('GetProjectMembers', $projectID); + } + + public function getAllProjects($sort='', $order='ASC') + { + $sqlmap = $this->getSqlMap(); + if($sort === '') + return $sqlmap->queryForList('GetAllProjects'); + else + { + $param['sort'] = $sort; + $param['order'] = $order; + return $sqlmap->queryForList('GetAllProjectsOrdered', $param); + } + } + + public function getProjectsByManagerName($manager) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForList('GetProjectsByManagerName', $manager); + } + + public function getProjectsByUserName($username) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForList('GetProjectsByUserName', $username); + } + + public function removeUserFromProject($projectID, $username) + { + $sqlmap = $this->getSqlMap(); + $param['username'] = $username; + $param['project'] = $projectID; + $sqlmap->delete('RemoveUserFromProject', $param); + } + + public function updateProject($project) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->update('UpdateProject', $project); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/Dao/ProjectRecord.php b/demos/time-tracker/protected/App_Code/Dao/ProjectRecord.php index 7812751b..1f6ededd 100644 --- a/demos/time-tracker/protected/App_Code/Dao/ProjectRecord.php +++ b/demos/time-tracker/protected/App_Code/Dao/ProjectRecord.php @@ -1,35 +1,35 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * Time Tracker Project class. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class ProjectRecord -{ - public $ActualDuration = 0; - public $CreatorUserName = ''; - public $CompletionDate = 0; - public $DateCreated = 0; - public $Description = ''; - public $EstimateDuration = 0.0; - public $ID = 0; - public $ManagerUserName = ''; - public $Name = ''; -} - - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * Time Tracker Project class. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class ProjectRecord +{ + public $ActualDuration = 0; + public $CreatorUserName = ''; + public $CompletionDate = 0; + public $DateCreated = 0; + public $Description = ''; + public $EstimateDuration = 0.0; + public $ID = 0; + public $ManagerUserName = ''; + public $Name = ''; +} + + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/Dao/ReportsDao.php b/demos/time-tracker/protected/App_Code/Dao/ReportsDao.php index 15d0c2a3..c03dd81d 100644 --- a/demos/time-tracker/protected/App_Code/Dao/ReportsDao.php +++ b/demos/time-tracker/protected/App_Code/Dao/ReportsDao.php @@ -1,87 +1,87 @@ -Categories = new TList; - } - - public function getActualHours() - { - $total = 0; - foreach($this->Categories as $cat) - $total += $cat->getActualHours(); - return $total; - } -} - -class CategoryReport extends TComponent -{ - public $CategoryName = ''; - public $EstimateHours = 0; - public $members = array(); - - public function getActualHours() - { - $total = 0; - foreach($this->members as $member) - $total += $member['hours']; - return $total; - } -} - -class UserReport extends TComponent -{ - public $Username; - public $Projects = array(); - - public function getTotalHours() - { - $hours = 0; - foreach($this->Projects as $project) - $hours += $project->Duration; - return $hours; - } -} - -class UserProjectReport -{ - public $ProjectName = ''; - public $CategoryName = ''; - public $Duration = 0; - public $Description=''; - public $ReportDate=0; -} - -class ReportsDao extends BaseDao -{ - public function getTimeReportsByProjectIDs($projects) - { - $ids = implode(',', array_map('intval', $projects)); - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForList('GetTimeReportByProjectIDs', $ids); - } - - public function getUserProjectTimeReports($users, $projects, $startDate, $endDate) - { - $sqlmap = $this->getSqlMap(); - $ids = implode(',', array_map('intval', $projects)); - $sqlmap->getDbConnection()->setActive(true); //db connection needs to be open for quoteString - $usernames = implode(',', array_map(array($sqlmap->getDbConnection(), 'quoteString'), $users)); - - $param['projects'] = $ids; - $param['members'] = $usernames; - $param['startDate'] = intval($startDate); - $param['endDate'] = intval($endDate); - - return $sqlmap->queryForList('GetTimeReportByUsername', $param); - } -} - +Categories = new TList; + } + + public function getActualHours() + { + $total = 0; + foreach($this->Categories as $cat) + $total += $cat->getActualHours(); + return $total; + } +} + +class CategoryReport extends TComponent +{ + public $CategoryName = ''; + public $EstimateHours = 0; + public $members = array(); + + public function getActualHours() + { + $total = 0; + foreach($this->members as $member) + $total += $member['hours']; + return $total; + } +} + +class UserReport extends TComponent +{ + public $Username; + public $Projects = array(); + + public function getTotalHours() + { + $hours = 0; + foreach($this->Projects as $project) + $hours += $project->Duration; + return $hours; + } +} + +class UserProjectReport +{ + public $ProjectName = ''; + public $CategoryName = ''; + public $Duration = 0; + public $Description=''; + public $ReportDate=0; +} + +class ReportsDao extends BaseDao +{ + public function getTimeReportsByProjectIDs($projects) + { + $ids = implode(',', array_map('intval', $projects)); + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForList('GetTimeReportByProjectIDs', $ids); + } + + public function getUserProjectTimeReports($users, $projects, $startDate, $endDate) + { + $sqlmap = $this->getSqlMap(); + $ids = implode(',', array_map('intval', $projects)); + $sqlmap->getDbConnection()->setActive(true); //db connection needs to be open for quoteString + $usernames = implode(',', array_map(array($sqlmap->getDbConnection(), 'quoteString'), $users)); + + $param['projects'] = $ids; + $param['members'] = $usernames; + $param['startDate'] = intval($startDate); + $param['endDate'] = intval($endDate); + + return $sqlmap->queryForList('GetTimeReportByUsername', $param); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/Dao/TimeEntryDao.php b/demos/time-tracker/protected/App_Code/Dao/TimeEntryDao.php index 4bd74eb5..f761fd25 100644 --- a/demos/time-tracker/protected/App_Code/Dao/TimeEntryDao.php +++ b/demos/time-tracker/protected/App_Code/Dao/TimeEntryDao.php @@ -1,38 +1,38 @@ -getSqlMap(); - $sqlmap->insert('AddNewTimeEntry', $entry); - } - - public function getTimeEntryByID($entryID) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForObject('GetTimeEntryByID', $entryID); - } - - public function deleteTimeEntry($entryID) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->delete('DeleteTimeEntry', $entryID); - } - - public function getTimeEntriesInProject($username, $projectID) - { - $sqlmap = $this->getSqlMap(); - $param['username'] = $username; - $param['project'] = $projectID; - return $sqlmap->queryForList('GetAllTimeEntriesByProjectIdAndUser', $param); - } - - public function updateTimeEntry($entry) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->update('UpdateTimeEntry', $entry); - } -} - +getSqlMap(); + $sqlmap->insert('AddNewTimeEntry', $entry); + } + + public function getTimeEntryByID($entryID) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForObject('GetTimeEntryByID', $entryID); + } + + public function deleteTimeEntry($entryID) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->delete('DeleteTimeEntry', $entryID); + } + + public function getTimeEntriesInProject($username, $projectID) + { + $sqlmap = $this->getSqlMap(); + $param['username'] = $username; + $param['project'] = $projectID; + return $sqlmap->queryForList('GetAllTimeEntriesByProjectIdAndUser', $param); + } + + public function updateTimeEntry($entry) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->update('UpdateTimeEntry', $entry); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/Dao/TimeEntryRecord.php b/demos/time-tracker/protected/App_Code/Dao/TimeEntryRecord.php index fa4f5b8f..8b533070 100644 --- a/demos/time-tracker/protected/App_Code/Dao/TimeEntryRecord.php +++ b/demos/time-tracker/protected/App_Code/Dao/TimeEntryRecord.php @@ -1,16 +1,16 @@ - \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/Dao/UserDao.php b/demos/time-tracker/protected/App_Code/Dao/UserDao.php index 4bb23b3a..dcb72ee7 100644 --- a/demos/time-tracker/protected/App_Code/Dao/UserDao.php +++ b/demos/time-tracker/protected/App_Code/Dao/UserDao.php @@ -1,165 +1,165 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * UserDao class list, create, find and delete users. - * In addition, it can validate username and password, and update - * the user roles. Furthermore, a unique new token can be generated, - * this token can be used to perform persistent cookie login. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class UserDao extends BaseDao -{ - /** - * @param string username - * @return TimeTrackerUser find by user name, null if not found or disabled. - */ - public function getUserByName($username) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForObject('GetUserByName', $username); - } - - /** - * @param string username - * @return boolean true if username already exists, false otherwise. - */ - public function usernameExists($username) - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForObject('UsernameExists', $username); - } - - /** - * @return array list of all enabled users. - */ - public function getAllUsers() - { - $sqlmap = $this->getSqlMap(); - return $sqlmap->queryForList('GetAllUsers'); - } - - /** - * @param TimeTrackerUser new user details. - * @param string new user password. - */ - public function addNewUser($user, $password) - { - $sqlmap = $this->getSqlMap(); - $param['user'] = $user; - $param['password'] = md5($password); - $sqlmap->insert('AddNewUser', $param); - if(count($user->getRoles()) > 0) - $this->updateUserRoles($user); - } - - /** - * @param string username to delete - */ - public function deleteUserByName($username) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->delete('DeleteUserByName', $username); - } - - /** - * Updates the user profile details, including user roles. - * @param TimeTrackerUser updated user details. - * @param string new user password, null to avoid updating password. - */ - public function updateUser($user,$password=null) - { - $sqlmap = $this->getSqlMap(); - if($password !== null) - { - $param['user'] = $user; - $param['password'] = md5($password); - $sqlmap->update('UpdateUserDetailsAndPassword', $param); - } - else - { - $sqlmap->update('UpdateUserDetails', $user); - } - $this->updateUserRoles($user); - } - - /** - * @param string username to be validated - * @param string matching password - * @return boolean true if the username and password matches. - */ - public function validateUser($username, $password) - { - $sqlmap = $this->getSqlMap(); - $param['username'] = $username; - $param['password'] = md5($password); - return $sqlmap->queryForObject('ValidateUser', $param); - } - - /** - * @param string unique persistent session token - * @return TimeTrackerUser user details if valid token, null otherwise. - */ - public function validateSignon($token) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->update('UpdateSignon', $token); - return $sqlmap->queryForObject('ValidateAutoSignon', $token); - } - - /** - * @param TimeTrackerUser user details to generate the token - * @return string unique persistent login token. - */ - public function createSignonToken($user) - { - $sqlmap = $this->getSqlMap(); - $param['username'] = $user->getName(); - $param['token'] = md5(microtime().$param['username']); - $sqlmap->insert('RegisterAutoSignon', $param); - return $param['token']; - } - - /** - * @param TimeTrackerUser deletes all signon token for given user, null to delete all - * tokens. - */ - public function clearSignonTokens($user=null) - { - $sqlmap = $this->getSqlMap(); - if($user !== null) - $sqlmap->delete('DeleteAutoSignon', $user->getName()); - else - $sqlmap->delete('DeleteAllSignon'); - } - - /** - * @param TimeTrackerUser user details for updating the assigned roles. - */ - public function updateUserRoles($user) - { - $sqlmap = $this->getSqlMap(); - $sqlmap->delete('DeleteUserRoles', $user); - foreach($user->getRoles() as $role) - { - $param['username'] = $user->getName(); - $param['role'] = $role; - $sqlmap->update('AddUserRole', $param); - } - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * UserDao class list, create, find and delete users. + * In addition, it can validate username and password, and update + * the user roles. Furthermore, a unique new token can be generated, + * this token can be used to perform persistent cookie login. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class UserDao extends BaseDao +{ + /** + * @param string username + * @return TimeTrackerUser find by user name, null if not found or disabled. + */ + public function getUserByName($username) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForObject('GetUserByName', $username); + } + + /** + * @param string username + * @return boolean true if username already exists, false otherwise. + */ + public function usernameExists($username) + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForObject('UsernameExists', $username); + } + + /** + * @return array list of all enabled users. + */ + public function getAllUsers() + { + $sqlmap = $this->getSqlMap(); + return $sqlmap->queryForList('GetAllUsers'); + } + + /** + * @param TimeTrackerUser new user details. + * @param string new user password. + */ + public function addNewUser($user, $password) + { + $sqlmap = $this->getSqlMap(); + $param['user'] = $user; + $param['password'] = md5($password); + $sqlmap->insert('AddNewUser', $param); + if(count($user->getRoles()) > 0) + $this->updateUserRoles($user); + } + + /** + * @param string username to delete + */ + public function deleteUserByName($username) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->delete('DeleteUserByName', $username); + } + + /** + * Updates the user profile details, including user roles. + * @param TimeTrackerUser updated user details. + * @param string new user password, null to avoid updating password. + */ + public function updateUser($user,$password=null) + { + $sqlmap = $this->getSqlMap(); + if($password !== null) + { + $param['user'] = $user; + $param['password'] = md5($password); + $sqlmap->update('UpdateUserDetailsAndPassword', $param); + } + else + { + $sqlmap->update('UpdateUserDetails', $user); + } + $this->updateUserRoles($user); + } + + /** + * @param string username to be validated + * @param string matching password + * @return boolean true if the username and password matches. + */ + public function validateUser($username, $password) + { + $sqlmap = $this->getSqlMap(); + $param['username'] = $username; + $param['password'] = md5($password); + return $sqlmap->queryForObject('ValidateUser', $param); + } + + /** + * @param string unique persistent session token + * @return TimeTrackerUser user details if valid token, null otherwise. + */ + public function validateSignon($token) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->update('UpdateSignon', $token); + return $sqlmap->queryForObject('ValidateAutoSignon', $token); + } + + /** + * @param TimeTrackerUser user details to generate the token + * @return string unique persistent login token. + */ + public function createSignonToken($user) + { + $sqlmap = $this->getSqlMap(); + $param['username'] = $user->getName(); + $param['token'] = md5(microtime().$param['username']); + $sqlmap->insert('RegisterAutoSignon', $param); + return $param['token']; + } + + /** + * @param TimeTrackerUser deletes all signon token for given user, null to delete all + * tokens. + */ + public function clearSignonTokens($user=null) + { + $sqlmap = $this->getSqlMap(); + if($user !== null) + $sqlmap->delete('DeleteAutoSignon', $user->getName()); + else + $sqlmap->delete('DeleteAllSignon'); + } + + /** + * @param TimeTrackerUser user details for updating the assigned roles. + */ + public function updateUserRoles($user) + { + $sqlmap = $this->getSqlMap(); + $sqlmap->delete('DeleteUserRoles', $user); + foreach($user->getRoles() as $role) + { + $param['username'] = $user->getName(); + $param['role'] = $role; + $sqlmap->update('AddUserRole', $param); + } + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/DaoManager.php b/demos/time-tracker/protected/App_Code/DaoManager.php index bf25c555..705dd4d0 100644 --- a/demos/time-tracker/protected/App_Code/DaoManager.php +++ b/demos/time-tracker/protected/App_Code/DaoManager.php @@ -1,79 +1,79 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -Prado::using('System.Data.SqlMap.TSqlMapConfig'); - -/** - * DaoManager class. - * - * A Registry for Dao and an implementation of that type. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class DaoManager extends TSqlMapConfig -{ - /** - * @var array registered list of dao - */ - private $_dao=array(); - - /** - * Initializes the module. - * This method is required by IModule and is invoked by application. - * It loads dao information from the module configuration. - * @param TXmlElement module configuration - */ - public function init($xml) - { - parent::init($xml); - foreach($xml->getElementsByTagName("dao") as $node) - { - $this->_dao[$node->getAttribute('id')] = - array('class' => $node->getAttribute('class')); - } - } - - /** - * @return array list of registered Daos - */ - public function getDaos() - { - return $this->_dao; - } - - /** - * Returns an implementation of a Dao type, implements the Registery - * pattern. Multiple calls returns the same Dao instance. - * @param string Dao type to find. - * @return object instance of the Dao implementation. - */ - public function getDao($class) - { - if(isset($this->_dao[$class])) - { - if(!isset($this->_dao[$class]['instance'])) - { - $dao = Prado::createComponent($this->_dao[$class]['class']); - $dao->setSqlMap($this->getClient()); - $this->_dao[$class]['instance'] = $dao; - } - return $this->_dao[$class]['instance']; - } - else - throw new TimeTrackerException('daomanager_undefined_dao', $class); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +Prado::using('System.Data.SqlMap.TSqlMapConfig'); + +/** + * DaoManager class. + * + * A Registry for Dao and an implementation of that type. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class DaoManager extends TSqlMapConfig +{ + /** + * @var array registered list of dao + */ + private $_dao=array(); + + /** + * Initializes the module. + * This method is required by IModule and is invoked by application. + * It loads dao information from the module configuration. + * @param TXmlElement module configuration + */ + public function init($xml) + { + parent::init($xml); + foreach($xml->getElementsByTagName("dao") as $node) + { + $this->_dao[$node->getAttribute('id')] = + array('class' => $node->getAttribute('class')); + } + } + + /** + * @return array list of registered Daos + */ + public function getDaos() + { + return $this->_dao; + } + + /** + * Returns an implementation of a Dao type, implements the Registery + * pattern. Multiple calls returns the same Dao instance. + * @param string Dao type to find. + * @return object instance of the Dao implementation. + */ + public function getDao($class) + { + if(isset($this->_dao[$class])) + { + if(!isset($this->_dao[$class]['instance'])) + { + $dao = Prado::createComponent($this->_dao[$class]['class']); + $dao->setSqlMap($this->getClient()); + $this->_dao[$class]['instance'] = $dao; + } + return $this->_dao[$class]['instance']; + } + else + throw new TimeTrackerException('daomanager_undefined_dao', $class); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/TimeTrackerException.php b/demos/time-tracker/protected/App_Code/TimeTrackerException.php index 41632c01..8c8e7efa 100644 --- a/demos/time-tracker/protected/App_Code/TimeTrackerException.php +++ b/demos/time-tracker/protected/App_Code/TimeTrackerException.php @@ -1,33 +1,33 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * Generic time tracker application exception. Exception messages are saved in - * "exceptions.txt" - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class TimeTrackerException extends TException -{ - /** - * @return string path to the error message file - */ - protected function getErrorMessageFile() - { - return dirname(__FILE__).'/exceptions.txt'; - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * Generic time tracker application exception. Exception messages are saved in + * "exceptions.txt" + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class TimeTrackerException extends TException +{ + /** + * @return string path to the error message file + */ + protected function getErrorMessageFile() + { + return dirname(__FILE__).'/exceptions.txt'; + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/TimeTrackerUser.php b/demos/time-tracker/protected/App_Code/TimeTrackerUser.php index b519fcde..1bf25ac1 100644 --- a/demos/time-tracker/protected/App_Code/TimeTrackerUser.php +++ b/demos/time-tracker/protected/App_Code/TimeTrackerUser.php @@ -1,48 +1,48 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * Import TUser and TUserManager - */ -Prado::using('System.Security.TUser'); -Prado::using('System.Security.TUserManager'); - -/** - * User class for Time Tracker application. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class TimeTrackerUser extends TUser -{ - private $_emailAddress; - - /** - * @param string user email address - */ - public function setEmailAddress($value) - { - $this->_emailAddress = $value; - } - - /** - * @return string user email address - */ - public function getEmailAddress() - { - return $this->_emailAddress; - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * Import TUser and TUserManager + */ +Prado::using('System.Security.TUser'); +Prado::using('System.Security.TUserManager'); + +/** + * User class for Time Tracker application. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class TimeTrackerUser extends TUser +{ + private $_emailAddress; + + /** + * @param string user email address + */ + public function setEmailAddress($value) + { + $this->_emailAddress = $value; + } + + /** + * @return string user email address + */ + public function getEmailAddress() + { + return $this->_emailAddress; + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/TrackerAuthManager.php b/demos/time-tracker/protected/App_Code/TrackerAuthManager.php index 989fcc54..ea6b5aab 100644 --- a/demos/time-tracker/protected/App_Code/TrackerAuthManager.php +++ b/demos/time-tracker/protected/App_Code/TrackerAuthManager.php @@ -1,85 +1,85 @@ - - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class TrackerAuthManager extends TAuthManager -{ - /** - * @const string signon token cookie name. - */ - const SignonCookieName = 'time-tracker-signon'; - - /** - * Performs the real authentication work. Overrides and calls parent - * implementation. Trys to authenticate using token saved in cookie. - * @param mixed parameter to be passed to OnAuthenticate event - */ - public function onAuthenticate($param) - { - parent::onAuthenticate($param); - $currentUser = $this->Application->User; - if(!$currentUser || $currentUser->IsGuest) - $this->authenticateFromCookie($param); - } - - /** - * If the user is not set or is still a guest, try to authenticate the user - * using a string token saved in the cookie if any. - * @param mixed parameter to be passed to OnAuthenticate event - */ - protected function authenticateFromCookie($param) - { - $cookie = $this->Request->Cookies[self::SignonCookieName]; - if(!is_null($cookie)) - { - $daos = $this->getApplication()->getModule('daos'); - $userDao = $daos->getDao('UserDao'); - $user = $userDao->validateSignon($cookie->Value); - if($user instanceof TimeTrackerUser) - $this->updateCredential($user); - } - } - - /** - * Changes the user credentials. - * @param TUser new user details. - */ - public function updateCredential($user) - { - $user->IsGuest = false; - $this->updateSessionUser($user); - $this->Application->User = $user; - } - - /** - * Generate a token to be saved in the cookie for later authentication. - * @param TimeTrackerUser user details. - */ - public function rememberSignon($user) - { - $daos = $this->getApplication()->getModule('daos'); - $userDao = $daos->getDao('UserDao'); - $token = $userDao->createSignonToken($user); - $cookie = new THttpCookie(self::SignonCookieName, $token); - $cookie->Expire = strtotime('+1 month'); - $this->Response->Cookies[] = $cookie; - } - - /** - * Logs out the user and delete the token from cookie. - */ - public function logout() - { - parent::logout(); - $cookie = new THttpCookie(self::SignonCookieName,''); - $this->Response->Cookies[] = $cookie; - } -} - + + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class TrackerAuthManager extends TAuthManager +{ + /** + * @const string signon token cookie name. + */ + const SignonCookieName = 'time-tracker-signon'; + + /** + * Performs the real authentication work. Overrides and calls parent + * implementation. Trys to authenticate using token saved in cookie. + * @param mixed parameter to be passed to OnAuthenticate event + */ + public function onAuthenticate($param) + { + parent::onAuthenticate($param); + $currentUser = $this->Application->User; + if(!$currentUser || $currentUser->IsGuest) + $this->authenticateFromCookie($param); + } + + /** + * If the user is not set or is still a guest, try to authenticate the user + * using a string token saved in the cookie if any. + * @param mixed parameter to be passed to OnAuthenticate event + */ + protected function authenticateFromCookie($param) + { + $cookie = $this->Request->Cookies[self::SignonCookieName]; + if(!is_null($cookie)) + { + $daos = $this->getApplication()->getModule('daos'); + $userDao = $daos->getDao('UserDao'); + $user = $userDao->validateSignon($cookie->Value); + if($user instanceof TimeTrackerUser) + $this->updateCredential($user); + } + } + + /** + * Changes the user credentials. + * @param TUser new user details. + */ + public function updateCredential($user) + { + $user->IsGuest = false; + $this->updateSessionUser($user); + $this->Application->User = $user; + } + + /** + * Generate a token to be saved in the cookie for later authentication. + * @param TimeTrackerUser user details. + */ + public function rememberSignon($user) + { + $daos = $this->getApplication()->getModule('daos'); + $userDao = $daos->getDao('UserDao'); + $token = $userDao->createSignonToken($user); + $cookie = new THttpCookie(self::SignonCookieName, $token); + $cookie->Expire = strtotime('+1 month'); + $this->Response->Cookies[] = $cookie; + } + + /** + * Logs out the user and delete the token from cookie. + */ + public function logout() + { + parent::logout(); + $cookie = new THttpCookie(self::SignonCookieName,''); + $this->Response->Cookies[] = $cookie; + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Code/UserManager.php b/demos/time-tracker/protected/App_Code/UserManager.php index 66eecb95..fd6eeb8e 100644 --- a/demos/time-tracker/protected/App_Code/UserManager.php +++ b/demos/time-tracker/protected/App_Code/UserManager.php @@ -1,90 +1,90 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * User manager module class for time tracker application. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class UserManager extends TModule implements IUserManager -{ - /** - * @return string name for a guest user. - */ - public function getGuestName() - { - return 'Guest'; - } - - /** - * 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 - { - $daos = $this->getApplication()->getModule('daos'); - $userDao = $daos->getDao('UserDao'); - $user = $userDao->getUserByName($username); - $user->setIsGuest(false); - return $user; - } - } - - /** - * 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) - { - $daos = $this->getApplication()->getModule('daos'); - $userDao = $daos->getDao('UserDao'); - return $userDao->validateUser($username, $password); - } - - /** - * 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) - { - // do nothing since we don't support cookie-based auth in this example - } - - /** - * 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) - { - // do nothing since we don't support cookie-based auth in this example - return null; - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * User manager module class for time tracker application. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class UserManager extends TModule implements IUserManager +{ + /** + * @return string name for a guest user. + */ + public function getGuestName() + { + return 'Guest'; + } + + /** + * 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 + { + $daos = $this->getApplication()->getModule('daos'); + $userDao = $daos->getDao('UserDao'); + $user = $userDao->getUserByName($username); + $user->setIsGuest(false); + return $user; + } + } + + /** + * 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) + { + $daos = $this->getApplication()->getModule('daos'); + $userDao = $daos->getDao('UserDao'); + return $userDao->validateUser($username, $password); + } + + /** + * 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) + { + // do nothing since we don't support cookie-based auth in this example + } + + /** + * 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) + { + // do nothing since we don't support cookie-based auth in this example + return null; + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Data/DateTimeTypeHandler.php b/demos/time-tracker/protected/App_Data/DateTimeTypeHandler.php index 03af3d36..b7a76e3d 100644 --- a/demos/time-tracker/protected/App_Data/DateTimeTypeHandler.php +++ b/demos/time-tracker/protected/App_Data/DateTimeTypeHandler.php @@ -1,35 +1,35 @@ - 10000) //strtotime doesn't like unix epoc time. - return intval($string); - return strtotime($string); - } - - /** - * Creates a new instance of TimeTrackerUser - * @param array result data - * @return TimeTrackerUser new user instance - */ - public function createNewInstance($row=null) - { - throw new TimeTrackerException('Not implemented'); - } - -} - + 10000) //strtotime doesn't like unix epoc time. + return intval($string); + return strtotime($string); + } + + /** + * Creates a new instance of TimeTrackerUser + * @param array result data + * @return TimeTrackerUser new user instance + */ + public function createNewInstance($row=null) + { + throw new TimeTrackerException('Not implemented'); + } + +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/App_Data/TimeTrackerUserTypeHandler.php b/demos/time-tracker/protected/App_Data/TimeTrackerUserTypeHandler.php index 54aba438..d9e28ae5 100644 --- a/demos/time-tracker/protected/App_Data/TimeTrackerUserTypeHandler.php +++ b/demos/time-tracker/protected/App_Data/TimeTrackerUserTypeHandler.php @@ -1,54 +1,54 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * SQLMap type handler for TimeTrackerUser. - * The TimeTrackerUser requires an instance of IUserManager in constructor. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class TimeTrackerUserTypeHandler extends TSqlMapTypeHandler -{ - /** - * Not implemented. - */ - public function getParameter($object) - { - throw new TimeTrackerException('Not implemented'); - } - - /** - * Not implemented. - */ - public function getResult($string) - { - throw new TimeTrackerException('Not implemented'); - } - - /** - * Creates a new instance of TimeTrackerUser - * @param array result data - * @return TimeTrackerUser new user instance - */ - public function createNewInstance($row=null) - { - $manager = Prado::getApplication()->getModule('users'); - if(is_null($manager)) - $manager = new UserManager(); - return new TimeTrackerUser($manager); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * SQLMap type handler for TimeTrackerUser. + * The TimeTrackerUser requires an instance of IUserManager in constructor. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class TimeTrackerUserTypeHandler extends TSqlMapTypeHandler +{ + /** + * Not implemented. + */ + public function getParameter($object) + { + throw new TimeTrackerException('Not implemented'); + } + + /** + * Not implemented. + */ + public function getResult($string) + { + throw new TimeTrackerException('Not implemented'); + } + + /** + * Creates a new instance of TimeTrackerUser + * @param array result data + * @return TimeTrackerUser new user instance + */ + public function createNewInstance($row=null) + { + $manager = Prado::getApplication()->getModule('users'); + if(is_null($manager)) + $manager = new UserManager(); + return new TimeTrackerUser($manager); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/CategoryDataList.php b/demos/time-tracker/protected/pages/TimeTracker/CategoryDataList.php index dd04dbf3..cc21a486 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/CategoryDataList.php +++ b/demos/time-tracker/protected/pages/TimeTracker/CategoryDataList.php @@ -1,94 +1,94 @@ -setViewState('ProjectID', $value, ''); - } - - public function getProjectID() - { - return $this->getViewState('ProjectID', ''); - } - - public function getCategories() - { - $this->ensureChildControls(); - return $this->getRegisteredObject('categories'); - } - - protected function getCategoryDao() - { - return $this->Application->Modules['daos']->getDao('CategoryDao'); - } - - public function showCategories() - { - $categoryDao = $this->getCategoryDao(); - $list = $categoryDao->getCategoriesByProjectID($this->getProjectID()); - $this->categories->DataSource = $list; - $this->categories->dataBind(); - } - - public function deleteCategoryItem($sender, $param) - { - $id = $this->categories->DataKeys[$param->Item->ItemIndex]; - $this->getCategoryDao()->deleteCategory($id); - $this->refreshCategoryList($sender, $param); - } - - public function editCategoryItem($sender, $param) - { - $this->categories->EditItemIndex=$param->Item->ItemIndex; - $this->showCategories(); - } - - public function refreshCategoryList($sender, $param) - { - $this->categories->EditItemIndex=-1; - $this->showCategories(); - } - - public function updateCategoryItem($sender, $param) - { - if(!$this->Page->IsValid) - return; - - $item = $param->Item; - - $id = $this->categories->DataKeys[$param->Item->ItemIndex]; - $category = new CategoryRecord; - $category->ID = $id; - $category->Name = $item->name->Text; - $category->Abbreviation = $item->abbrev->Text; - $category->EstimateDuration = floatval($item->duration->Text); - $category->ProjectID = $this->getProjectID(); - - $this->getCategoryDao()->updateCategory($category); - - $this->refreshCategoryList($sender, $param); - } - - public function addCategory_clicked($sender, $param) - { - if(!$this->Page->IsValid) - return; - - $newCategory = new CategoryRecord; - $newCategory->Name = $this->categoryName->Text; - $newCategory->Abbreviation = $this->abbrev->Text; - $newCategory->EstimateDuration = floatval($this->duration->Text); - $newCategory->ProjectID = $this->getProjectID(); - - $this->getCategoryDao()->addNewCategory($newCategory); - - $this->categoryName->Text = ''; - $this->abbrev->Text = ''; - $this->duration->Text = ''; - - $this->showCategories(); - } -} - +setViewState('ProjectID', $value, ''); + } + + public function getProjectID() + { + return $this->getViewState('ProjectID', ''); + } + + public function getCategories() + { + $this->ensureChildControls(); + return $this->getRegisteredObject('categories'); + } + + protected function getCategoryDao() + { + return $this->Application->Modules['daos']->getDao('CategoryDao'); + } + + public function showCategories() + { + $categoryDao = $this->getCategoryDao(); + $list = $categoryDao->getCategoriesByProjectID($this->getProjectID()); + $this->categories->DataSource = $list; + $this->categories->dataBind(); + } + + public function deleteCategoryItem($sender, $param) + { + $id = $this->categories->DataKeys[$param->Item->ItemIndex]; + $this->getCategoryDao()->deleteCategory($id); + $this->refreshCategoryList($sender, $param); + } + + public function editCategoryItem($sender, $param) + { + $this->categories->EditItemIndex=$param->Item->ItemIndex; + $this->showCategories(); + } + + public function refreshCategoryList($sender, $param) + { + $this->categories->EditItemIndex=-1; + $this->showCategories(); + } + + public function updateCategoryItem($sender, $param) + { + if(!$this->Page->IsValid) + return; + + $item = $param->Item; + + $id = $this->categories->DataKeys[$param->Item->ItemIndex]; + $category = new CategoryRecord; + $category->ID = $id; + $category->Name = $item->name->Text; + $category->Abbreviation = $item->abbrev->Text; + $category->EstimateDuration = floatval($item->duration->Text); + $category->ProjectID = $this->getProjectID(); + + $this->getCategoryDao()->updateCategory($category); + + $this->refreshCategoryList($sender, $param); + } + + public function addCategory_clicked($sender, $param) + { + if(!$this->Page->IsValid) + return; + + $newCategory = new CategoryRecord; + $newCategory->Name = $this->categoryName->Text; + $newCategory->Abbreviation = $this->abbrev->Text; + $newCategory->EstimateDuration = floatval($this->duration->Text); + $newCategory->ProjectID = $this->getProjectID(); + + $this->getCategoryDao()->addNewCategory($newCategory); + + $this->categoryName->Text = ''; + $this->abbrev->Text = ''; + $this->duration->Text = ''; + + $this->showCategories(); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/LogTimeEntry.php b/demos/time-tracker/protected/pages/TimeTracker/LogTimeEntry.php index 2c8f0f3b..71d29b78 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/LogTimeEntry.php +++ b/demos/time-tracker/protected/pages/TimeTracker/LogTimeEntry.php @@ -1,112 +1,112 @@ -Application->Modules['daos']->getDao('ProjectDao'); - } - - protected function getCategoryDao() - { - return $this->Application->Modules['daos']->getDao('CategoryDao'); - } - - protected function getTimeEntryDao() - { - return $this->Application->Modules['daos']->getDao('TimeEntryDao'); - } - - public function onLoad($param) - { - if(!$this->IsPostBack) - { - $projects = $this->getProjects(); - $this->projects->DataSource = $projects; - $this->projects->dataBind(); - $this->showCategories(key($projects)); - } - } - - protected function showCategories($projectID) - { - $categories = array(); - foreach($this->getCategoryDao()->getCategoriesByProjectID($projectID) as $cat) - { - $categories[$cat->ID] = $cat->Name; - } - $this->category->DataSource = $categories; - $this->category->dataBind(); - $this->showProjectUsers($projectID); - } - - protected function showProjectUsers($projectID) - { - if($this->User->isInRole('manager')) - $users = $this->getProjectDao()->getProjectMembers($projectID); - else - $users = array($this->User->Name); - $this->projectMembers->DataSource = $users; - $this->projectMembers->dataBind(); - if(is_int($index = array_search($this->User->Name, $users))) - { - $this->projectMembers->SelectedIndex = $index; - $this->showTimeSheet(); - } - } - - public function showTimeSheet() - { - $user = $this->projectMembers->SelectedItem->Text; - $project = $this->projects->SelectedValue; - $this->entryList->setProjectEntry($user,$project); - $this->entryList->refreshEntryList(); - } - - protected function getProjects() - { - $projects = array(); - if($this->User->isInRole('admin')) - $list = $this->getProjectDao()->getAllProjects(); - else if($this->User->isInRole('manager')) - $list = $this->getProjectDao()->getProjectsByManagerName($this->User->Name); - else - $list = $this->getProjectDao()->getProjectsByUserName($this->User->Name); - foreach($list as $project) - $projects[$project->ID] = $project->Name; - return $projects; - } - - public function projects_Changed($sender, $param) - { - $this->showCategories($sender->SelectedValue); - } - - public function AddNewEntry($sender, $param) - { - if(!$this->IsValid) - return; - - if($this->projectMembers->SelectedItem) - { - $entry = new TimeEntryRecord; - $entry->CreatorUserName = $this->User->Name; - $category = new CategoryRecord; - $category->ID = $this->category->SelectedValue; - $entry->Category = $category; - $entry->Description = $this->description->Text; - $entry->Duration = floatval($this->hours->Text); - $entry->ReportDate = $this->day->TimeStamp; - $entry->Username = $this->projectMembers->SelectedItem->Text; - - $this->hours->Text = ''; - $this->description->Text = ''; - - $this->getTimeEntryDao()->addNewTimeEntry($entry); - $this->showTimeSheet(); - } - } -} - +Application->Modules['daos']->getDao('ProjectDao'); + } + + protected function getCategoryDao() + { + return $this->Application->Modules['daos']->getDao('CategoryDao'); + } + + protected function getTimeEntryDao() + { + return $this->Application->Modules['daos']->getDao('TimeEntryDao'); + } + + public function onLoad($param) + { + if(!$this->IsPostBack) + { + $projects = $this->getProjects(); + $this->projects->DataSource = $projects; + $this->projects->dataBind(); + $this->showCategories(key($projects)); + } + } + + protected function showCategories($projectID) + { + $categories = array(); + foreach($this->getCategoryDao()->getCategoriesByProjectID($projectID) as $cat) + { + $categories[$cat->ID] = $cat->Name; + } + $this->category->DataSource = $categories; + $this->category->dataBind(); + $this->showProjectUsers($projectID); + } + + protected function showProjectUsers($projectID) + { + if($this->User->isInRole('manager')) + $users = $this->getProjectDao()->getProjectMembers($projectID); + else + $users = array($this->User->Name); + $this->projectMembers->DataSource = $users; + $this->projectMembers->dataBind(); + if(is_int($index = array_search($this->User->Name, $users))) + { + $this->projectMembers->SelectedIndex = $index; + $this->showTimeSheet(); + } + } + + public function showTimeSheet() + { + $user = $this->projectMembers->SelectedItem->Text; + $project = $this->projects->SelectedValue; + $this->entryList->setProjectEntry($user,$project); + $this->entryList->refreshEntryList(); + } + + protected function getProjects() + { + $projects = array(); + if($this->User->isInRole('admin')) + $list = $this->getProjectDao()->getAllProjects(); + else if($this->User->isInRole('manager')) + $list = $this->getProjectDao()->getProjectsByManagerName($this->User->Name); + else + $list = $this->getProjectDao()->getProjectsByUserName($this->User->Name); + foreach($list as $project) + $projects[$project->ID] = $project->Name; + return $projects; + } + + public function projects_Changed($sender, $param) + { + $this->showCategories($sender->SelectedValue); + } + + public function AddNewEntry($sender, $param) + { + if(!$this->IsValid) + return; + + if($this->projectMembers->SelectedItem) + { + $entry = new TimeEntryRecord; + $entry->CreatorUserName = $this->User->Name; + $category = new CategoryRecord; + $category->ID = $this->category->SelectedValue; + $entry->Category = $category; + $entry->Description = $this->description->Text; + $entry->Duration = floatval($this->hours->Text); + $entry->ReportDate = $this->day->TimeStamp; + $entry->Username = $this->projectMembers->SelectedItem->Text; + + $this->hours->Text = ''; + $this->description->Text = ''; + + $this->getTimeEntryDao()->addNewTimeEntry($entry); + $this->showTimeSheet(); + } + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/Login.php b/demos/time-tracker/protected/pages/TimeTracker/Login.php index 2bd02cc1..d306cf63 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/Login.php +++ b/demos/time-tracker/protected/pages/TimeTracker/Login.php @@ -1,55 +1,55 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * Login page class. - * - * Validate the user credentials and redirect to requested page - * if successful. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class Login extends TPage -{ - /** - * Validates the username and password. - * @param TControl custom validator that created the event. - * @param TServerValidateEventParameter validation parameters. - */ - public function validateUser($sender, $param) - { - $authManager=$this->Application->getModule('auth'); - if(!$authManager->login($this->username->Text,$this->password->Text)) - $param->IsValid=false;; - } - - /** - * Redirect to the requested page if login is successful. - * @param TControl button control that created the event. - * @param TEventParameter event parameters. - */ - public function doLogin($sender, $param) - { - if($this->Page->IsValid) - { - $auth = $this->Application->getModule('auth'); - if($this->remember->Checked) - $auth->rememberSignon($this->User); - $this->Response->redirect($auth->getReturnUrl()); - } - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * Login page class. + * + * Validate the user credentials and redirect to requested page + * if successful. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class Login extends TPage +{ + /** + * Validates the username and password. + * @param TControl custom validator that created the event. + * @param TServerValidateEventParameter validation parameters. + */ + public function validateUser($sender, $param) + { + $authManager=$this->Application->getModule('auth'); + if(!$authManager->login($this->username->Text,$this->password->Text)) + $param->IsValid=false;; + } + + /** + * Redirect to the requested page if login is successful. + * @param TControl button control that created the event. + * @param TEventParameter event parameters. + */ + public function doLogin($sender, $param) + { + if($this->Page->IsValid) + { + $auth = $this->Application->getModule('auth'); + if($this->remember->Checked) + $auth->rememberSignon($this->User); + $this->Response->redirect($auth->getReturnUrl()); + } + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/Logout.php b/demos/time-tracker/protected/pages/TimeTracker/Logout.php index 2e3d3ccc..f82f137c 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/Logout.php +++ b/demos/time-tracker/protected/pages/TimeTracker/Logout.php @@ -1,34 +1,34 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * Logout page class. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class Logout extends TPage -{ - /** - * Logs out the current user and redirect to default page. - */ - function onLoad($param) - { - $this->Application->getModule('auth')->logout(); - $url = $this->Service->constructUrl($this->Service->DefaultPage); - $this->Response->redirect($url); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * Logout page class. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class Logout extends TPage +{ + /** + * Logs out the current user and redirect to default page. + */ + function onLoad($param) + { + $this->Application->getModule('auth')->logout(); + $url = $this->Service->constructUrl($this->Service->DefaultPage); + $this->Response->redirect($url); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/MainLayout.php b/demos/time-tracker/protected/pages/TimeTracker/MainLayout.php index 253d6c03..c966ba85 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/MainLayout.php +++ b/demos/time-tracker/protected/pages/TimeTracker/MainLayout.php @@ -1,7 +1,7 @@ - \ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/ProjectDetails.php b/demos/time-tracker/protected/pages/TimeTracker/ProjectDetails.php index 98a93148..f4fb9718 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/ProjectDetails.php +++ b/demos/time-tracker/protected/pages/TimeTracker/ProjectDetails.php @@ -1,191 +1,191 @@ -currentProject) - { - $id = intval($this->Request['ProjectID']); - if($id > 0) - $this->currentProject = $this->getProjectDao()->getProjectByID($id); - } - return $this->currentProject; - } - - protected function getProjectDao() - { - return $this->Application->Modules['daos']->getDao('ProjectDao'); - } - - protected function getCategoryDao() - { - return $this->Application->Modules['daos']->getDao('CategoryDao'); - } - - public function onLoad($param) - { - if(!$this->IsPostBack) - { - $this->manager->DataSource = $this->getUsersWithRole('manager'); - $this->manager->dataBind(); - $this->members->DataSource = $this->getUsersWithRole('consultant'); - $this->members->dataBind(); - - $project = $this->getCurrentProject(); - - if($project !== null) - { - $this->projectName->Text = $project->Name; - $this->completionDate->TimeStamp = $project->CompletionDate; - $this->description->Text = $project->Description; - $this->estimateHours->Text = $project->EstimateDuration; - $this->manager->SelectedValue = $project->ManagerUserName; - - $this->selectProjectMembers($project->ID); - - $this->projectCategoryColumn->Visible = true; - $this->categories->ProjectID = $project->ID; - $this->categories->showCategories(); - - $this->deleteButton->Visible = true; - - $this->projectList->DataSource = $this->getProjects(); - $this->projectList->dataBind(); - - } - else - { - $this->projectCategoryColumn->Visible = false; - $this->deleteButton->Visible = false; - } - - } - } - - protected function getProjects() - { - $projects = array(); - foreach($this->getProjectDao()->getAllProjects() as $project) - { - if($project->Name != $this->currentProject->Name) - $projects[$project->ID] = $project->Name; - } - return $projects; - } - - protected function selectProjectMembers($projectID) - { - $members = $this->getProjectDao()->getProjectMembers($projectID); - $this->members->SelectedValues = $members; - } - - protected function getUsersWithRole($role) - { - if(is_null($this->allUsers)) - { - $dao = $this->Application->Modules['daos']->getDao('UserDao'); - $this->allUsers = $dao->getAllUsers(); - } - $users = array(); - foreach($this->allUsers as $user) - { - if($user->isInRole($role)) - $users[$user->Name] = $user->Name; - } - return $users; - } - - public function onPreRender($param) - { - $ids = array(); - foreach($this->members->Items as $item) - { - if($item->Selected) - $ids[] = $item->Value; - } - $this->setViewState('ActiveConsultants', $ids); - } - - public function saveButton_clicked($sender, $param) - { - if(!$this->Page->IsValid) - return; - - $newProject = new ProjectRecord; - - $projectDao = $this->getProjectDao(); - - if($project = $this->getCurrentProject()) - $newProject = $projectDao->getProjectByID($project->ID); - else - $newProject->CreatorUserName = $this->User->Name; - - $newProject->Name = $this->projectName->Text; - $newProject->CompletionDate = $this->completionDate->TimeStamp; - $newProject->Description = $this->description->Text; - $newProject->EstimateDuration = floatval($this->estimateHours->Text); - $newProject->ManagerUserName = $this->manager->SelectedValue; - - if($this->currentProject) - $projectDao->updateProject($newProject); - else - $projectDao->addNewProject($newProject); - - $this->updateProjectMembers($newProject->ID); - - $url = $this->Service->constructUrl('TimeTracker.ProjectDetails', - array('ProjectID'=> $newProject->ID)); - - $this->Response->redirect($url); - } - - protected function updateProjectMembers($projectID) - { - $active = $this->getViewState('ActiveConsultants'); - $projectDao = $this->getProjectDao(); - foreach($this->members->Items as $item) - { - if($item->Selected) - { - if(!in_array($item->Value, $active)) - $projectDao->addUserToProject($projectID, $item->Value); - } - else - { - if(in_array($item->Value, $active)) - $projectDao->removeUserFromProject($projectID, $item->Value); - } - } - } - - public function deleteButton_clicked($sender, $param) - { - if($project = $this->getCurrentProject()) - { - $this->getProjectDao()->deleteProject($project->ID); - $url = $this->Service->constructUrl('TimeTracker.ProjectList'); - $this->Response->redirect($url); - } - } - - public function copyButton_clicked($sender, $param) - { - $project = $this->projectList->SelectedValue; - $categoryDao = $this->getCategoryDao(); - $categories = $categoryDao->getCategoriesByProjectID($project); - $currentProject = $this->getCurrentProject(); - foreach($categories as $cat) - { - $cat->ProjectID = $currentProject->ID; - $categoryDao->addNewCategory($cat); - } - $this->categories->showCategories(); - } -} - +currentProject) + { + $id = intval($this->Request['ProjectID']); + if($id > 0) + $this->currentProject = $this->getProjectDao()->getProjectByID($id); + } + return $this->currentProject; + } + + protected function getProjectDao() + { + return $this->Application->Modules['daos']->getDao('ProjectDao'); + } + + protected function getCategoryDao() + { + return $this->Application->Modules['daos']->getDao('CategoryDao'); + } + + public function onLoad($param) + { + if(!$this->IsPostBack) + { + $this->manager->DataSource = $this->getUsersWithRole('manager'); + $this->manager->dataBind(); + $this->members->DataSource = $this->getUsersWithRole('consultant'); + $this->members->dataBind(); + + $project = $this->getCurrentProject(); + + if($project !== null) + { + $this->projectName->Text = $project->Name; + $this->completionDate->TimeStamp = $project->CompletionDate; + $this->description->Text = $project->Description; + $this->estimateHours->Text = $project->EstimateDuration; + $this->manager->SelectedValue = $project->ManagerUserName; + + $this->selectProjectMembers($project->ID); + + $this->projectCategoryColumn->Visible = true; + $this->categories->ProjectID = $project->ID; + $this->categories->showCategories(); + + $this->deleteButton->Visible = true; + + $this->projectList->DataSource = $this->getProjects(); + $this->projectList->dataBind(); + + } + else + { + $this->projectCategoryColumn->Visible = false; + $this->deleteButton->Visible = false; + } + + } + } + + protected function getProjects() + { + $projects = array(); + foreach($this->getProjectDao()->getAllProjects() as $project) + { + if($project->Name != $this->currentProject->Name) + $projects[$project->ID] = $project->Name; + } + return $projects; + } + + protected function selectProjectMembers($projectID) + { + $members = $this->getProjectDao()->getProjectMembers($projectID); + $this->members->SelectedValues = $members; + } + + protected function getUsersWithRole($role) + { + if(is_null($this->allUsers)) + { + $dao = $this->Application->Modules['daos']->getDao('UserDao'); + $this->allUsers = $dao->getAllUsers(); + } + $users = array(); + foreach($this->allUsers as $user) + { + if($user->isInRole($role)) + $users[$user->Name] = $user->Name; + } + return $users; + } + + public function onPreRender($param) + { + $ids = array(); + foreach($this->members->Items as $item) + { + if($item->Selected) + $ids[] = $item->Value; + } + $this->setViewState('ActiveConsultants', $ids); + } + + public function saveButton_clicked($sender, $param) + { + if(!$this->Page->IsValid) + return; + + $newProject = new ProjectRecord; + + $projectDao = $this->getProjectDao(); + + if($project = $this->getCurrentProject()) + $newProject = $projectDao->getProjectByID($project->ID); + else + $newProject->CreatorUserName = $this->User->Name; + + $newProject->Name = $this->projectName->Text; + $newProject->CompletionDate = $this->completionDate->TimeStamp; + $newProject->Description = $this->description->Text; + $newProject->EstimateDuration = floatval($this->estimateHours->Text); + $newProject->ManagerUserName = $this->manager->SelectedValue; + + if($this->currentProject) + $projectDao->updateProject($newProject); + else + $projectDao->addNewProject($newProject); + + $this->updateProjectMembers($newProject->ID); + + $url = $this->Service->constructUrl('TimeTracker.ProjectDetails', + array('ProjectID'=> $newProject->ID)); + + $this->Response->redirect($url); + } + + protected function updateProjectMembers($projectID) + { + $active = $this->getViewState('ActiveConsultants'); + $projectDao = $this->getProjectDao(); + foreach($this->members->Items as $item) + { + if($item->Selected) + { + if(!in_array($item->Value, $active)) + $projectDao->addUserToProject($projectID, $item->Value); + } + else + { + if(in_array($item->Value, $active)) + $projectDao->removeUserFromProject($projectID, $item->Value); + } + } + } + + public function deleteButton_clicked($sender, $param) + { + if($project = $this->getCurrentProject()) + { + $this->getProjectDao()->deleteProject($project->ID); + $url = $this->Service->constructUrl('TimeTracker.ProjectList'); + $this->Response->redirect($url); + } + } + + public function copyButton_clicked($sender, $param) + { + $project = $this->projectList->SelectedValue; + $categoryDao = $this->getCategoryDao(); + $categories = $categoryDao->getCategoriesByProjectID($project); + $currentProject = $this->getCurrentProject(); + foreach($categories as $cat) + { + $cat->ProjectID = $currentProject->ID; + $categoryDao->addNewCategory($cat); + } + $this->categories->showCategories(); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/ProjectList.php b/demos/time-tracker/protected/pages/TimeTracker/ProjectList.php index 4e3ac485..6ea6afe1 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/ProjectList.php +++ b/demos/time-tracker/protected/pages/TimeTracker/ProjectList.php @@ -1,34 +1,34 @@ -Application->Modules['daos']->getDao('ProjectDao'); - $this->projectList->DataSource = $dao->getAllProjects($sort, $order); - $this->projectList->dataBind(); - } - - protected function getSortOrdering($sort) - { - $ordering = $this->getViewState('SortOrder', array()); - $order = isset($ordering[$sort]) ? $ordering[$sort] : 'DESC'; - $ordering[$sort] = $order == 'DESC' ? 'ASC' : 'DESC'; - $this->setViewState('SortOrder', $ordering); - return $ordering[$sort]; - } - - protected function sortProjects($sender, $param) - { - $sort = $param->SortExpression; - $this->showProjects($sort, $this->getSortOrdering($sort)); - } - - public function onLoad($param) - { - if(!$this->IsPostBack) - $this->showProjects(); - } -} - +Application->Modules['daos']->getDao('ProjectDao'); + $this->projectList->DataSource = $dao->getAllProjects($sort, $order); + $this->projectList->dataBind(); + } + + protected function getSortOrdering($sort) + { + $ordering = $this->getViewState('SortOrder', array()); + $order = isset($ordering[$sort]) ? $ordering[$sort] : 'DESC'; + $ordering[$sort] = $order == 'DESC' ? 'ASC' : 'DESC'; + $this->setViewState('SortOrder', $ordering); + return $ordering[$sort]; + } + + protected function sortProjects($sender, $param) + { + $sort = $param->SortExpression; + $this->showProjects($sort, $this->getSortOrdering($sort)); + } + + public function onLoad($param) + { + if(!$this->IsPostBack) + $this->showProjects(); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/ReportProject.php b/demos/time-tracker/protected/pages/TimeTracker/ReportProject.php index fcb1c865..6ce849b9 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/ReportProject.php +++ b/demos/time-tracker/protected/pages/TimeTracker/ReportProject.php @@ -1,53 +1,53 @@ -Application->Modules['daos']->getDao('ProjectDao'); - $projects = array(); - foreach($projectDao->getAllProjects() as $project) - $projects[$project->ID] = $project->Name; - return $projects; - } - - public function onLoad($param) - { - if(!$this->IsPostBack) - { - $this->projectList->DataSource = $this->getProjects(); - $this->dataBind(); - } - } - - public function generateReport_Clicked($sender, $param) - { - if(count($this->projectList->SelectedValues) > 0) - $this->showReport(); - } - - protected function showReport() - { - $reportDao = $this->Application->Modules['daos']->getDao('ReportDao'); - $reports = $reportDao->getTimeReportsByProjectIDs($this->projectList->SelectedValues); - $this->views->ActiveViewIndex = 1; - $this->projects->DataSource = $reports; - $this->projects->dataBind(); - } - - public function project_itemCreated($sender, $param) - { - $item = $param->Item; - if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem') - $item->category->DataSource = $item->DataItem->Categories; - } - - public function category_itemCreated($sender, $param) - { - $item = $param->Item; - if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem') - $item->members->DataSource = $item->DataItem->members; - } -} - +Application->Modules['daos']->getDao('ProjectDao'); + $projects = array(); + foreach($projectDao->getAllProjects() as $project) + $projects[$project->ID] = $project->Name; + return $projects; + } + + public function onLoad($param) + { + if(!$this->IsPostBack) + { + $this->projectList->DataSource = $this->getProjects(); + $this->dataBind(); + } + } + + public function generateReport_Clicked($sender, $param) + { + if(count($this->projectList->SelectedValues) > 0) + $this->showReport(); + } + + protected function showReport() + { + $reportDao = $this->Application->Modules['daos']->getDao('ReportDao'); + $reports = $reportDao->getTimeReportsByProjectIDs($this->projectList->SelectedValues); + $this->views->ActiveViewIndex = 1; + $this->projects->DataSource = $reports; + $this->projects->dataBind(); + } + + public function project_itemCreated($sender, $param) + { + $item = $param->Item; + if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem') + $item->category->DataSource = $item->DataItem->Categories; + } + + public function category_itemCreated($sender, $param) + { + $item = $param->Item; + if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem') + $item->members->DataSource = $item->DataItem->members; + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/ReportResource.php b/demos/time-tracker/protected/pages/TimeTracker/ReportResource.php index 65283417..26644bc9 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/ReportResource.php +++ b/demos/time-tracker/protected/pages/TimeTracker/ReportResource.php @@ -1,71 +1,71 @@ -Application->Modules['daos']->getDao('ProjectDao'); - $projects = array(); - foreach($projectDao->getAllProjects() as $project) - $projects[$project->ID] = $project->Name; - return $projects; - } - - protected function getUsers() - { - $dao = $this->Application->Modules['daos']->getDao('UserDao'); - $users = array(); - foreach($dao->getAllUsers() as $user) - { - $users[$user->Name] = $user->Name; - } - return $users; - } - - public function onLoad($param) - { - if(!$this->IsPostBack) - { - $this->projectList->DataSource = $this->getProjects(); - $this->resourceList->DataSource = $this->getUsers(); - $this->dataBind(); - } - } - - public function generateReport_Clicked($sender, $param) - { - if(count($this->projectList->SelectedValues) > 0 - && count($this->resourceList->SelectedValues) >0) - { - $this->showReport(); - } - } - - protected function showReport() - { - $this->views->ActiveViewIndex = 1; - $reportDao = $this->Application->Modules['daos']->getDao('ReportDao'); - $projects = $this->projectList->SelectedValues; - $users = $this->resourceList->SelectedValues; - $start = $this->dateFrom->TimeStamp; - $end = $this->dateTo->TimeStamp; - - $report = $reportDao->getUserProjectTimeReports($users, $projects, $start, $end); - - $this->resource_report->DataSource = $report; - $this->resource_report->dataBind(); - } - - public function resource_report_itemCreated($sender, $param) - { - $item = $param->Item; - if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem') - { - if(count($item->DataItem->Projects) > 0 && - $item->DataItem->Projects[0]->ProjectName !== null) - $item->time_entries->DataSource = $item->DataItem->Projects; - } - } -} - +Application->Modules['daos']->getDao('ProjectDao'); + $projects = array(); + foreach($projectDao->getAllProjects() as $project) + $projects[$project->ID] = $project->Name; + return $projects; + } + + protected function getUsers() + { + $dao = $this->Application->Modules['daos']->getDao('UserDao'); + $users = array(); + foreach($dao->getAllUsers() as $user) + { + $users[$user->Name] = $user->Name; + } + return $users; + } + + public function onLoad($param) + { + if(!$this->IsPostBack) + { + $this->projectList->DataSource = $this->getProjects(); + $this->resourceList->DataSource = $this->getUsers(); + $this->dataBind(); + } + } + + public function generateReport_Clicked($sender, $param) + { + if(count($this->projectList->SelectedValues) > 0 + && count($this->resourceList->SelectedValues) >0) + { + $this->showReport(); + } + } + + protected function showReport() + { + $this->views->ActiveViewIndex = 1; + $reportDao = $this->Application->Modules['daos']->getDao('ReportDao'); + $projects = $this->projectList->SelectedValues; + $users = $this->resourceList->SelectedValues; + $start = $this->dateFrom->TimeStamp; + $end = $this->dateTo->TimeStamp; + + $report = $reportDao->getUserProjectTimeReports($users, $projects, $start, $end); + + $this->resource_report->DataSource = $report; + $this->resource_report->dataBind(); + } + + public function resource_report_itemCreated($sender, $param) + { + $item = $param->Item; + if($item->ItemType==='Item' || $item->ItemType==='AlternatingItem') + { + if(count($item->DataItem->Projects) > 0 && + $item->DataItem->Projects[0]->ProjectName !== null) + $item->time_entries->DataSource = $item->DataItem->Projects; + } + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php b/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php index dde4b44d..cb923178 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php +++ b/demos/time-tracker/protected/pages/TimeTracker/SiteMap.php @@ -1,57 +1,57 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * SiteMap menu is rendered depending on user roles. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class SiteMap extends TTemplateControl -{ - /** - * Sets the active menu item using css class. - */ - public function onPreRender($param) - { - parent::onPreRender($param); - - $page = explode('.',$this->Request->ServiceParameter); - $active = null; - switch($page[count($page)-1]) - { - case 'ProjectList': - case 'ProjectDetails': - $active = $this->ProjectMenu; - break; - case 'UserList': - case 'UserCreate': - $active = $this->AdminMenu; - break; - case 'ReportProject': - case 'ReportResource': - $active = $this->ReportMenu; - break; - default: - $active = $this->LogMenu; - break; - } - - //add 'active' string to place holder body. - if(!is_null($active)) - $active->Controls[] = 'active'; - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * SiteMap menu is rendered depending on user roles. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class SiteMap extends TTemplateControl +{ + /** + * Sets the active menu item using css class. + */ + public function onPreRender($param) + { + parent::onPreRender($param); + + $page = explode('.',$this->Request->ServiceParameter); + $active = null; + switch($page[count($page)-1]) + { + case 'ProjectList': + case 'ProjectDetails': + $active = $this->ProjectMenu; + break; + case 'UserList': + case 'UserCreate': + $active = $this->AdminMenu; + break; + case 'ReportProject': + case 'ReportResource': + $active = $this->ReportMenu; + break; + default: + $active = $this->LogMenu; + break; + } + + //add 'active' string to place holder body. + if(!is_null($active)) + $active->Controls[] = 'active'; + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/TimeEntryList.php b/demos/time-tracker/protected/pages/TimeTracker/TimeEntryList.php index ee3f4bb2..0730505f 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/TimeEntryList.php +++ b/demos/time-tracker/protected/pages/TimeTracker/TimeEntryList.php @@ -1,89 +1,89 @@ -Application->Modules['daos']->getDao('TimeEntryDao'); - } - - protected function getCategoryDao() - { - return $this->Application->Modules['daos']->getDao('CategoryDao'); - } - - public function setProjectEntry($userID,$projectID) - { - $this->setViewState('ProjectEntry', array($userID,$projectID)); - } - - protected function getCategories() - { - $project = $this->getViewState('ProjectEntry'); - foreach($this->getCategoryDao()->getCategoriesByProjectID($project[1]) as $cat) - { - $categories[$cat->ID] = $cat->Name; - } - return $categories; - } - - protected function showEntryList() - { - $project = $this->getViewState('ProjectEntry'); - $list = $this->getTimeEntryDao()->getTimeEntriesInProject($project[0], $project[1]); - $this->entries->DataSource = $list; - $this->entries->dataBind(); - } - - public function refreshEntryList() - { - $this->entries->EditItemIndex=-1; - $this->showEntryList(); - } - - public function editEntryItem($sender, $param) - { - $this->entries->EditItemIndex=$param->Item->ItemIndex; - $this->showEntryList(); - } - - public function deleteEntryItem($sender, $param) - { - $id = $this->entries->DataKeys[$param->Item->ItemIndex]; - $this->getTimeEntryDao()->deleteTimeEntry($id); - $this->refreshEntryList(); - } - - public function updateEntryItem($sender, $param) - { - if(!$this->Page->IsValid) - return; - - $item = $param->Item; - - $id = $this->entries->DataKeys[$param->Item->ItemIndex]; - - $entry = $this->getTimeEntryDao()->getTimeEntryByID($id); - $category = new CategoryRecord; - $category->ID = $param->Item->category->SelectedValue; - $entry->Category = $category; - $entry->Description = $param->Item->description->Text; - $entry->Duration = floatval($param->Item->hours->Text); - $entry->ReportDate = $param->Item->day->TimeStamp; - - $this->getTimeEntryDao()->updateTimeEntry($entry); - $this->refreshEntryList(); - } - - public function EntryItemCreated($sender, $param) - { - if($param->Item->ItemType == 'EditItem' && $param->Item->DataItem) - { - $param->Item->category->DataSource = $this->getCategories(); - $param->Item->category->dataBind(); - $param->Item->category->SelectedValue = $param->Item->DataItem->Category->ID; - } - } -} - +Application->Modules['daos']->getDao('TimeEntryDao'); + } + + protected function getCategoryDao() + { + return $this->Application->Modules['daos']->getDao('CategoryDao'); + } + + public function setProjectEntry($userID,$projectID) + { + $this->setViewState('ProjectEntry', array($userID,$projectID)); + } + + protected function getCategories() + { + $project = $this->getViewState('ProjectEntry'); + foreach($this->getCategoryDao()->getCategoriesByProjectID($project[1]) as $cat) + { + $categories[$cat->ID] = $cat->Name; + } + return $categories; + } + + protected function showEntryList() + { + $project = $this->getViewState('ProjectEntry'); + $list = $this->getTimeEntryDao()->getTimeEntriesInProject($project[0], $project[1]); + $this->entries->DataSource = $list; + $this->entries->dataBind(); + } + + public function refreshEntryList() + { + $this->entries->EditItemIndex=-1; + $this->showEntryList(); + } + + public function editEntryItem($sender, $param) + { + $this->entries->EditItemIndex=$param->Item->ItemIndex; + $this->showEntryList(); + } + + public function deleteEntryItem($sender, $param) + { + $id = $this->entries->DataKeys[$param->Item->ItemIndex]; + $this->getTimeEntryDao()->deleteTimeEntry($id); + $this->refreshEntryList(); + } + + public function updateEntryItem($sender, $param) + { + if(!$this->Page->IsValid) + return; + + $item = $param->Item; + + $id = $this->entries->DataKeys[$param->Item->ItemIndex]; + + $entry = $this->getTimeEntryDao()->getTimeEntryByID($id); + $category = new CategoryRecord; + $category->ID = $param->Item->category->SelectedValue; + $entry->Category = $category; + $entry->Description = $param->Item->description->Text; + $entry->Duration = floatval($param->Item->hours->Text); + $entry->ReportDate = $param->Item->day->TimeStamp; + + $this->getTimeEntryDao()->updateTimeEntry($entry); + $this->refreshEntryList(); + } + + public function EntryItemCreated($sender, $param) + { + if($param->Item->ItemType == 'EditItem' && $param->Item->DataItem) + { + $param->Item->category->DataSource = $this->getCategories(); + $param->Item->category->dataBind(); + $param->Item->category->SelectedValue = $param->Item->DataItem->Category->ID; + } + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/UserCreate.php b/demos/time-tracker/protected/pages/TimeTracker/UserCreate.php index 8ee077ac..eddb87cb 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/UserCreate.php +++ b/demos/time-tracker/protected/pages/TimeTracker/UserCreate.php @@ -1,112 +1,112 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * Create new user wizard page class. Validate that the usernames are unique and - * set the new user credentials as the current application credentials. - * - * If logged in as admin, the user role can be change during creation. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class UserCreate extends TPage -{ - /** - * Sets the default new user roles, default role is set in config.xml - */ - public function onLoad($param) - { - if(!$this->IsPostBack) - { - $this->role->SelectedValue = - $this->Application->Parameters['NewUserRoles']; - } - } - - /** - * Verify that the username is not taken. - * @param TControl custom validator that created the event. - * @param TServerValidateEventParameter validation parameters. - */ - public function checkUsername($sender, $param) - { - $userDao = $this->Application->Modules['daos']->getDao('UserDao'); - if($userDao->usernameExists($this->username->Text)) - { - $param->IsValid = false; - $sender->ErrorMessage = - "The user name is already taken, try '{$this->username->Text}01'"; - } - } - - /** - * Skip the role assignment step if not admin. - */ - public function userWizardNextStep($sender, $param) - { - if($param->CurrentStepIndex == 0) - { - //create user with admin credentials - if(!$this->User->isInRole('admin')) - { - $this->createNewUser($sender, $param); - $param->NextStepIndex = 2; - } - } - } - - /** - * Create a new user if all data entered are valid. - * The default user roles are obtained from "config.xml". The new user - * details is saved to the database and the new credentials are used as the - * application user. The user is redirected to the requested page. - * @param TControl button control that created the event. - * @param TEventParameter event parameters. - */ - public function createNewUser($sender, $param) - { - if($this->IsValid) - { - $newUser = new TimeTrackerUser($this->User->Manager); - $newUser->EmailAddress = $this->email->Text; - $newUser->Name = $this->username->Text; - $newUser->IsGuest = false; - $newUser->Roles = $this->role->SelectedValue; - - //save the user - $userDao = $this->Application->Modules['daos']->getDao('UserDao'); - $userDao->addNewUser($newUser, $this->password->Text); - - //update the user credentials if not admin - if(!$this->User->isInRole('admin')) - { - $auth = $this->Application->getModule('auth'); - $auth->updateCredential($newUser); - } - } - } - - /** - * Continue with requested page. - */ - public function wizardCompleted($sender, $param) - { - //return to requested page - $auth = $this->Application->getModule('auth'); - $this->Response->redirect($auth->getReturnUrl()); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * Create new user wizard page class. Validate that the usernames are unique and + * set the new user credentials as the current application credentials. + * + * If logged in as admin, the user role can be change during creation. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class UserCreate extends TPage +{ + /** + * Sets the default new user roles, default role is set in config.xml + */ + public function onLoad($param) + { + if(!$this->IsPostBack) + { + $this->role->SelectedValue = + $this->Application->Parameters['NewUserRoles']; + } + } + + /** + * Verify that the username is not taken. + * @param TControl custom validator that created the event. + * @param TServerValidateEventParameter validation parameters. + */ + public function checkUsername($sender, $param) + { + $userDao = $this->Application->Modules['daos']->getDao('UserDao'); + if($userDao->usernameExists($this->username->Text)) + { + $param->IsValid = false; + $sender->ErrorMessage = + "The user name is already taken, try '{$this->username->Text}01'"; + } + } + + /** + * Skip the role assignment step if not admin. + */ + public function userWizardNextStep($sender, $param) + { + if($param->CurrentStepIndex == 0) + { + //create user with admin credentials + if(!$this->User->isInRole('admin')) + { + $this->createNewUser($sender, $param); + $param->NextStepIndex = 2; + } + } + } + + /** + * Create a new user if all data entered are valid. + * The default user roles are obtained from "config.xml". The new user + * details is saved to the database and the new credentials are used as the + * application user. The user is redirected to the requested page. + * @param TControl button control that created the event. + * @param TEventParameter event parameters. + */ + public function createNewUser($sender, $param) + { + if($this->IsValid) + { + $newUser = new TimeTrackerUser($this->User->Manager); + $newUser->EmailAddress = $this->email->Text; + $newUser->Name = $this->username->Text; + $newUser->IsGuest = false; + $newUser->Roles = $this->role->SelectedValue; + + //save the user + $userDao = $this->Application->Modules['daos']->getDao('UserDao'); + $userDao->addNewUser($newUser, $this->password->Text); + + //update the user credentials if not admin + if(!$this->User->isInRole('admin')) + { + $auth = $this->Application->getModule('auth'); + $auth->updateCredential($newUser); + } + } + } + + /** + * Continue with requested page. + */ + public function wizardCompleted($sender, $param) + { + //return to requested page + $auth = $this->Application->getModule('auth'); + $this->Response->redirect($auth->getReturnUrl()); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/protected/pages/TimeTracker/UserList.php b/demos/time-tracker/protected/pages/TimeTracker/UserList.php index 22974d29..ad35a758 100644 --- a/demos/time-tracker/protected/pages/TimeTracker/UserList.php +++ b/demos/time-tracker/protected/pages/TimeTracker/UserList.php @@ -1,34 +1,34 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2006 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package Demos - */ - -/** - * List all users in a repeater. - * - * @author Wei Zhuo - * @version $Id$ - * @package Demos - * @since 3.1 - */ -class UserList extends TPage -{ - /** - * Load all the users and display them in a repeater. - */ - function onLoad($param) - { - $userDao = $this->Application->Modules['daos']->getDao('UserDao'); - $this->list->DataSource = $userDao->getAllUsers(); - $this->list->dataBind(); - } -} - + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package Demos + */ + +/** + * List all users in a repeater. + * + * @author Wei Zhuo + * @version $Id$ + * @package Demos + * @since 3.1 + */ +class UserList extends TPage +{ + /** + * Load all the users and display them in a repeater. + */ + function onLoad($param) + { + $userDao = $this->Application->Modules['daos']->getDao('UserDao'); + $this->list->DataSource = $userDao->getAllUsers(); + $this->list->dataBind(); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/tests/functional.php b/demos/time-tracker/tests/functional.php index 888b29db..00790199 100644 --- a/demos/time-tracker/tests/functional.php +++ b/demos/time-tracker/tests/functional.php @@ -1,10 +1,10 @@ -run(new SimpleReporter()); - +run(new SimpleReporter()); + ?> \ No newline at end of file diff --git a/demos/time-tracker/tests/functional/HelloPradoTestCase.php b/demos/time-tracker/tests/functional/HelloPradoTestCase.php index b9e4f1e3..13ee9343 100644 --- a/demos/time-tracker/tests/functional/HelloPradoTestCase.php +++ b/demos/time-tracker/tests/functional/HelloPradoTestCase.php @@ -1,14 +1,14 @@ -open('../index.php'); - $this->assertTextPresent('Welcome to Prado!'); - //add more test assertions... - } -} - +open('../index.php'); + $this->assertTextPresent('Welcome to Prado!'); + //add more test assertions... + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/tests/unit.php b/demos/time-tracker/tests/unit.php index 20d56432..7961d4f2 100644 --- a/demos/time-tracker/tests/unit.php +++ b/demos/time-tracker/tests/unit.php @@ -1,11 +1,11 @@ -run(new HtmlReporter()); - +run(new HtmlReporter()); + ?> \ No newline at end of file diff --git a/demos/time-tracker/tests/unit/BaseTestCase.php b/demos/time-tracker/tests/unit/BaseTestCase.php index d72cbc5c..10df400f 100644 --- a/demos/time-tracker/tests/unit/BaseTestCase.php +++ b/demos/time-tracker/tests/unit/BaseTestCase.php @@ -1,64 +1,64 @@ -sqlmap = $app->getModule('daos')->getClient(); - } - - - function flushDatabase() - { - $conn = $this->sqlmap->getDbConnection(); - $find = 'sqlite:protected'; - if(is_int(strpos($conn->getConnectionString(),$find))) - $conn->ConnectionString = str_replace($find, 'sqlite:../protected', $conn->ConnectionString); - $conn->setActive(false); - $conn->setActive(true); - switch(strtolower($conn->getDriverName())) - { - case 'mysql': - return $this->flushMySQLDatabase(); - case 'sqlite': - return $this->flushSQLiteDatabase(); - } - } - - function flushSQLiteDatabase() - { - $conn = $this->sqlmap->getDbConnection(); - $file = str_replace('sqlite:','',$conn->getConnectionString()); - $backup = $file.'.bak'; - copy($backup, $file); - } - - function flushMySQLDatabase() - { - $conn = $this->sqlmap->getDbConnection(); - $file = Prado::getPathOfNamespace('Application.App_Data.MySQL4.mysql-reset','.sql'); - if(is_file($file)) - $this->runScript($conn, $file); - else - throw new Exception('unable to find script file '.$file); - } - - protected function runScript($connection, $script) - { - $sql = file_get_contents($script); - $lines = explode(';', $sql); - foreach($lines as $line) - { - $line = trim($line); - if(strlen($line) > 0) - $connection->createCommand($line)->execute(); - } - } -} +sqlmap = $app->getModule('daos')->getClient(); + } + + + function flushDatabase() + { + $conn = $this->sqlmap->getDbConnection(); + $find = 'sqlite:protected'; + if(is_int(strpos($conn->getConnectionString(),$find))) + $conn->ConnectionString = str_replace($find, 'sqlite:../protected', $conn->ConnectionString); + $conn->setActive(false); + $conn->setActive(true); + switch(strtolower($conn->getDriverName())) + { + case 'mysql': + return $this->flushMySQLDatabase(); + case 'sqlite': + return $this->flushSQLiteDatabase(); + } + } + + function flushSQLiteDatabase() + { + $conn = $this->sqlmap->getDbConnection(); + $file = str_replace('sqlite:','',$conn->getConnectionString()); + $backup = $file.'.bak'; + copy($backup, $file); + } + + function flushMySQLDatabase() + { + $conn = $this->sqlmap->getDbConnection(); + $file = Prado::getPathOfNamespace('Application.App_Data.MySQL4.mysql-reset','.sql'); + if(is_file($file)) + $this->runScript($conn, $file); + else + throw new Exception('unable to find script file '.$file); + } + + protected function runScript($connection, $script) + { + $sql = file_get_contents($script); + $lines = explode(';', $sql); + foreach($lines as $line) + { + $line = trim($line); + if(strlen($line) > 0) + $connection->createCommand($line)->execute(); + } + } +} ?> \ No newline at end of file diff --git a/demos/time-tracker/tests/unit/CategoryDaoTestCase.php b/demos/time-tracker/tests/unit/CategoryDaoTestCase.php index d47fa7ce..e018b0b0 100644 --- a/demos/time-tracker/tests/unit/CategoryDaoTestCase.php +++ b/demos/time-tracker/tests/unit/CategoryDaoTestCase.php @@ -1,201 +1,201 @@ -categoryDao = $app->getModule('daos')->getDao('CategoryDao'); - $this->projectDao = $app->getModule('daos')->getDao('ProjectDao'); - $this->flushDatabase(); - } - - function createNewProject() - { - $project = new ProjectRecord; - $project->CreatorUserName = "admin"; - $project->DateCreated = time(); - $project->CompletionDate = strtotime('+1 month'); - $project->Description = 'Test project 1'; - $project->EstimateDuration = 100.5; - $project->ManagerUserName = 'manager'; - $project->Name = 'Project 1'; - - return $project; - } - - function createNewProject2() - { - $project = new ProjectRecord; - $project->CreatorUserName = "manager"; - $project->DateCreated = time(); - $project->CompletionDate = strtotime('+1 week'); - $project->Description = 'Test project 2'; - $project->EstimateDuration = 30.5; - $project->ManagerUserName = 'manager'; - $project->Name = 'Project 2'; - - return $project; - } - - function createNewCategory() - { - $category = new CategoryRecord; - $category->Name = 'Category 1'; - $category->EstimateDuration = 5.5; - $category->Abbreviation = 'CAT 1'; - - return $category; - } - - function createNewCategory2() - { - $category = new CategoryRecord; - $category->Name = 'Category 2'; - $category->EstimateDuration = 1.5; - $category->Abbreviation = 'CAT2'; - - return $category; - } - - function createNewCategory3() - { - $category = new CategoryRecord; - $category->Name = 'Category 3'; - $category->EstimateDuration = 2.5; - $category->Abbreviation = 'CAT3'; - - return $category; - } - - function create3Categories() - { - $project1 = $this->createNewProject(); - $this->projectDao->addNewProject($project1); - - $project2 = $this->createNewProject2(); - $this->projectDao->addNewProject($project2); - - $category1 = $this->createNewCategory(); - $category1->ProjectID = $project1->ID; - - $category2 = $this->createNewCategory2(); - $category2->ProjectID = $project2->ID; - - $category3 = $this->createNewCategory3(); - $category3->ProjectID = $project1->ID; - - $this->categoryDao->addNewCategory($category1); - $this->categoryDao->addNewCategory($category2); - $this->categoryDao->addNewCategory($category3); - - return array($category1, $category2, $category3); - } - - function testCreateNewCategory() - { - $project = $this->createNewProject(); - $this->projectDao->addNewProject($project); - - $category = $this->createNewCategory(); - $category->ProjectID = $project->ID; - - $this->categoryDao->addNewCategory($category); - - $check = $this->categoryDao->getCategoryByID(1); - - $this->assertEqual($category, $check); - } - - function testCreateDuplicateCategory() - { - $project = $this->createNewProject(); - $this->projectDao->addNewProject($project); - - $category = $this->createNewCategory(); - $category->ProjectID = $project->ID; - - $this->categoryDao->addNewCategory($category); - - try - { - $this->categoryDao->addNewCategory($category); - $this->pass(); - } - catch(TSqlMapQueryExecutionException $e) - { - $this->fail(); - } - $check = $this->categoryDao->getCategoryByID(1); - $this->assertEqual($category, $check); - } - - function testGetAllCategories() - { - $added = $this->create3Categories(); - - $list = $this->categoryDao->getAllCategories(); - $this->assertEqual(count($list), 3); - $this->assertEqual($added[0], $list[0]); - $this->assertEqual($added[1], $list[1]); - $this->assertEqual($added[2], $list[2]); - } - - function testDeleteCategory() - { - $added = $this->create3Categories(); - - $this->categoryDao->deleteCategory(1); - - $list = $this->categoryDao->getAllCategories(); - - $this->assertEqual(count($list), 2); - $this->assertEqual($added[1], $list[0]); - $this->assertEqual($added[2], $list[1]); - } - - function testCategoriesInProject() - { - $added = $this->create3Categories(); - - $list = $this->categoryDao->getCategoriesByProjectID(1); - - $this->assertEqual(count($list), 2); - $this->assertEqual($added[0], $list[0]); - $this->assertEqual($added[2], $list[1]); - } - - function testGetCategoryByCategoryNameandProjectId() - { - $added = $this->create3Categories(); - $cat = $this->categoryDao->getCategoryByNameInProject('Category 1', 1); - - $this->assertEqual($cat, $added[0]); - } - - function testUpdateCategory() - { - $project = $this->createNewProject(); - $this->projectDao->addNewProject($project); - - $category = $this->createNewCategory(); - $category->ProjectID = $project->ID; - - $this->categoryDao->addNewCategory($category); - - $category->Name = "Test 2"; - $this->categoryDao->updateCategory($category); - - $check = $this->categoryDao->getCategoryByID($category->ID); - - $this->assertEqual($category, $check); - } -} - +categoryDao = $app->getModule('daos')->getDao('CategoryDao'); + $this->projectDao = $app->getModule('daos')->getDao('ProjectDao'); + $this->flushDatabase(); + } + + function createNewProject() + { + $project = new ProjectRecord; + $project->CreatorUserName = "admin"; + $project->DateCreated = time(); + $project->CompletionDate = strtotime('+1 month'); + $project->Description = 'Test project 1'; + $project->EstimateDuration = 100.5; + $project->ManagerUserName = 'manager'; + $project->Name = 'Project 1'; + + return $project; + } + + function createNewProject2() + { + $project = new ProjectRecord; + $project->CreatorUserName = "manager"; + $project->DateCreated = time(); + $project->CompletionDate = strtotime('+1 week'); + $project->Description = 'Test project 2'; + $project->EstimateDuration = 30.5; + $project->ManagerUserName = 'manager'; + $project->Name = 'Project 2'; + + return $project; + } + + function createNewCategory() + { + $category = new CategoryRecord; + $category->Name = 'Category 1'; + $category->EstimateDuration = 5.5; + $category->Abbreviation = 'CAT 1'; + + return $category; + } + + function createNewCategory2() + { + $category = new CategoryRecord; + $category->Name = 'Category 2'; + $category->EstimateDuration = 1.5; + $category->Abbreviation = 'CAT2'; + + return $category; + } + + function createNewCategory3() + { + $category = new CategoryRecord; + $category->Name = 'Category 3'; + $category->EstimateDuration = 2.5; + $category->Abbreviation = 'CAT3'; + + return $category; + } + + function create3Categories() + { + $project1 = $this->createNewProject(); + $this->projectDao->addNewProject($project1); + + $project2 = $this->createNewProject2(); + $this->projectDao->addNewProject($project2); + + $category1 = $this->createNewCategory(); + $category1->ProjectID = $project1->ID; + + $category2 = $this->createNewCategory2(); + $category2->ProjectID = $project2->ID; + + $category3 = $this->createNewCategory3(); + $category3->ProjectID = $project1->ID; + + $this->categoryDao->addNewCategory($category1); + $this->categoryDao->addNewCategory($category2); + $this->categoryDao->addNewCategory($category3); + + return array($category1, $category2, $category3); + } + + function testCreateNewCategory() + { + $project = $this->createNewProject(); + $this->projectDao->addNewProject($project); + + $category = $this->createNewCategory(); + $category->ProjectID = $project->ID; + + $this->categoryDao->addNewCategory($category); + + $check = $this->categoryDao->getCategoryByID(1); + + $this->assertEqual($category, $check); + } + + function testCreateDuplicateCategory() + { + $project = $this->createNewProject(); + $this->projectDao->addNewProject($project); + + $category = $this->createNewCategory(); + $category->ProjectID = $project->ID; + + $this->categoryDao->addNewCategory($category); + + try + { + $this->categoryDao->addNewCategory($category); + $this->pass(); + } + catch(TSqlMapQueryExecutionException $e) + { + $this->fail(); + } + $check = $this->categoryDao->getCategoryByID(1); + $this->assertEqual($category, $check); + } + + function testGetAllCategories() + { + $added = $this->create3Categories(); + + $list = $this->categoryDao->getAllCategories(); + $this->assertEqual(count($list), 3); + $this->assertEqual($added[0], $list[0]); + $this->assertEqual($added[1], $list[1]); + $this->assertEqual($added[2], $list[2]); + } + + function testDeleteCategory() + { + $added = $this->create3Categories(); + + $this->categoryDao->deleteCategory(1); + + $list = $this->categoryDao->getAllCategories(); + + $this->assertEqual(count($list), 2); + $this->assertEqual($added[1], $list[0]); + $this->assertEqual($added[2], $list[1]); + } + + function testCategoriesInProject() + { + $added = $this->create3Categories(); + + $list = $this->categoryDao->getCategoriesByProjectID(1); + + $this->assertEqual(count($list), 2); + $this->assertEqual($added[0], $list[0]); + $this->assertEqual($added[2], $list[1]); + } + + function testGetCategoryByCategoryNameandProjectId() + { + $added = $this->create3Categories(); + $cat = $this->categoryDao->getCategoryByNameInProject('Category 1', 1); + + $this->assertEqual($cat, $added[0]); + } + + function testUpdateCategory() + { + $project = $this->createNewProject(); + $this->projectDao->addNewProject($project); + + $category = $this->createNewCategory(); + $category->ProjectID = $project->ID; + + $this->categoryDao->addNewCategory($category); + + $category->Name = "Test 2"; + $this->categoryDao->updateCategory($category); + + $check = $this->categoryDao->getCategoryByID($category->ID); + + $this->assertEqual($category, $check); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/tests/unit/ProjectDaoTestCase.php b/demos/time-tracker/tests/unit/ProjectDaoTestCase.php index 22a01fca..1790f4d0 100644 --- a/demos/time-tracker/tests/unit/ProjectDaoTestCase.php +++ b/demos/time-tracker/tests/unit/ProjectDaoTestCase.php @@ -1,200 +1,200 @@ -projectDao = $app->getModule('daos')->getDao('ProjectDao'); - $this->flushDatabase(); - } - - - function createNewProject() - { - $project = new ProjectRecord; - $project->CreatorUserName = "admin"; - $project->DateCreated = time(); - $project->CompletionDate = strtotime('+1 month'); - $project->Description = 'Test project 1'; - $project->EstimateDuration = 100.5; - $project->ManagerUserName = 'manager'; - $project->Name = 'Project 1'; - - return $project; - } - - function createNewProject2() - { - $project = new ProjectRecord; - $project->CreatorUserName = "manager"; - $project->DateCreated = time(); - $project->CompletionDate = strtotime('+1 week'); - $project->Description = 'Test project 2'; - $project->EstimateDuration = 30.5; - $project->ManagerUserName = 'manager'; - $project->Name = 'Project 2'; - - return $project; - } - - function createNewProject3() - { - $project = new ProjectRecord; - $project->CreatorUserName = "manager"; - $project->DateCreated = time(); - $project->CompletionDate = strtotime('+1 day'); - $project->Description = 'Test project 3'; - $project->EstimateDuration = 5.0; - $project->ManagerUserName = 'admin'; - $project->Name = 'Project 3'; - - return $project; - } - - function add3Projects() - { - $project1 = $this->createNewProject(); - $project2 = $this->createNewProject2(); - $project3 = $this->createNewProject3(); - - $this->projectDao->addNewProject($project1); - $this->projectDao->addNewProject($project2); - $this->projectDao->addNewProject($project3); - return array($project1,$project2,$project3); - } - - function testCreateNewProject() - { - $newProject = $this->createNewProject(); - $this->projectDao->addNewProject($newProject); - - $check = $this->projectDao->getProjectByID(1); - $this->assertEqual($newProject, $check); - } - - function testDeleteProject() - { - $newProject = $this->createNewProject(); - $this->projectDao->addNewProject($newProject); - - $check = $this->projectDao->getProjectByID(1); - $this->assertEqual($newProject, $check); - - $this->projectDao->deleteProject(1); - $verify = $this->projectDao->getProjectByID(1); - $this->assertNull($verify); - } - - function testAddUserToProject() - { - $project = $this->createNewProject(); - $this->projectDao->addNewProject($project); - - $this->projectDao->addUserToProject($project->ID, 'admin'); - $this->projectDao->addUserToProject($project->ID, 'manager'); - - $members = $this->projectDao->getProjectMembers($project->ID); - - $this->assertEqual(count($members), 2); - $this->assertEqual($members[0], 'admin'); - $this->assertEqual($members[1], 'manager'); - } - - function testAddNullUserToProject() - { - $project = $this->createNewProject(); - $this->projectDao->addNewProject($project); - try - { - $this->projectDao->addUserToProject($project->ID, 'asd'); - $this->fail(); - } - catch(TDbException $e) - { - $this->pass(); - } - } - - function testGetAllProjects() - { - $added = $this->add3Projects(); - - $projects = $this->projectDao->getAllProjects(); - - $this->assertEqual(count($projects),3); - $this->assertEqual($added[0],$projects[0]); - $this->assertEqual($added[1],$projects[1]); - $this->assertEqual($added[2],$projects[2]); - } - - function testGetProjectsByManagerName() - { - $added = $this->add3Projects(); - - $projects = $this->projectDao->getProjectsByManagerName('manager'); - - $this->assertEqual(count($projects),2); - $this->assertEqual($added[0],$projects[0]); - $this->assertEqual($added[1],$projects[1]); - } - - function testGetProjectsByUserName() - { - $added = $this->add3Projects(); - - $username = 'consultant'; - - $this->projectDao->addUserToProject(1, $username); - $this->projectDao->addUserToProject(3, $username); - - $projects = $this->projectDao->getProjectsByUserName($username); - - $this->assertEqual(count($projects),2); - $this->assertEqual($added[0],$projects[0]); - $this->assertEqual($added[2],$projects[1]); - } - - function testRemoveUserFromProject() - { - $added = $this->add3Projects(); - $this->projectDao->addUserToProject(1, 'admin'); - $this->projectDao->addUserToProject(1, 'manager'); - $this->projectDao->addUserToProject(1, 'consultant'); - - $members = $this->projectDao->getProjectMembers(1); - - $this->assertEqual(count($members), 3); - $this->assertEqual($members[0], 'admin'); - $this->assertEqual($members[2], 'manager'); - $this->assertEqual($members[1], 'consultant'); - - $this->projectDao->removeUserFromProject(1,'admin'); - - $list = $this->projectDao->getProjectMembers(1); - - $this->assertEqual(count($list), 2); - $this->assertEqual($list[1], 'manager'); - $this->assertEqual($list[0], 'consultant'); - } - - function testUpdateProject() - { - $project = $this->createNewProject(); - $this->projectDao->addNewProject($project); - - $project->Description = "Project Testing 123"; - - $this->projectDao->updateProject($project); - - $check = $this->projectDao->getProjectByID(1); - $this->assertEqual($check, $project); - } -} - +projectDao = $app->getModule('daos')->getDao('ProjectDao'); + $this->flushDatabase(); + } + + + function createNewProject() + { + $project = new ProjectRecord; + $project->CreatorUserName = "admin"; + $project->DateCreated = time(); + $project->CompletionDate = strtotime('+1 month'); + $project->Description = 'Test project 1'; + $project->EstimateDuration = 100.5; + $project->ManagerUserName = 'manager'; + $project->Name = 'Project 1'; + + return $project; + } + + function createNewProject2() + { + $project = new ProjectRecord; + $project->CreatorUserName = "manager"; + $project->DateCreated = time(); + $project->CompletionDate = strtotime('+1 week'); + $project->Description = 'Test project 2'; + $project->EstimateDuration = 30.5; + $project->ManagerUserName = 'manager'; + $project->Name = 'Project 2'; + + return $project; + } + + function createNewProject3() + { + $project = new ProjectRecord; + $project->CreatorUserName = "manager"; + $project->DateCreated = time(); + $project->CompletionDate = strtotime('+1 day'); + $project->Description = 'Test project 3'; + $project->EstimateDuration = 5.0; + $project->ManagerUserName = 'admin'; + $project->Name = 'Project 3'; + + return $project; + } + + function add3Projects() + { + $project1 = $this->createNewProject(); + $project2 = $this->createNewProject2(); + $project3 = $this->createNewProject3(); + + $this->projectDao->addNewProject($project1); + $this->projectDao->addNewProject($project2); + $this->projectDao->addNewProject($project3); + return array($project1,$project2,$project3); + } + + function testCreateNewProject() + { + $newProject = $this->createNewProject(); + $this->projectDao->addNewProject($newProject); + + $check = $this->projectDao->getProjectByID(1); + $this->assertEqual($newProject, $check); + } + + function testDeleteProject() + { + $newProject = $this->createNewProject(); + $this->projectDao->addNewProject($newProject); + + $check = $this->projectDao->getProjectByID(1); + $this->assertEqual($newProject, $check); + + $this->projectDao->deleteProject(1); + $verify = $this->projectDao->getProjectByID(1); + $this->assertNull($verify); + } + + function testAddUserToProject() + { + $project = $this->createNewProject(); + $this->projectDao->addNewProject($project); + + $this->projectDao->addUserToProject($project->ID, 'admin'); + $this->projectDao->addUserToProject($project->ID, 'manager'); + + $members = $this->projectDao->getProjectMembers($project->ID); + + $this->assertEqual(count($members), 2); + $this->assertEqual($members[0], 'admin'); + $this->assertEqual($members[1], 'manager'); + } + + function testAddNullUserToProject() + { + $project = $this->createNewProject(); + $this->projectDao->addNewProject($project); + try + { + $this->projectDao->addUserToProject($project->ID, 'asd'); + $this->fail(); + } + catch(TDbException $e) + { + $this->pass(); + } + } + + function testGetAllProjects() + { + $added = $this->add3Projects(); + + $projects = $this->projectDao->getAllProjects(); + + $this->assertEqual(count($projects),3); + $this->assertEqual($added[0],$projects[0]); + $this->assertEqual($added[1],$projects[1]); + $this->assertEqual($added[2],$projects[2]); + } + + function testGetProjectsByManagerName() + { + $added = $this->add3Projects(); + + $projects = $this->projectDao->getProjectsByManagerName('manager'); + + $this->assertEqual(count($projects),2); + $this->assertEqual($added[0],$projects[0]); + $this->assertEqual($added[1],$projects[1]); + } + + function testGetProjectsByUserName() + { + $added = $this->add3Projects(); + + $username = 'consultant'; + + $this->projectDao->addUserToProject(1, $username); + $this->projectDao->addUserToProject(3, $username); + + $projects = $this->projectDao->getProjectsByUserName($username); + + $this->assertEqual(count($projects),2); + $this->assertEqual($added[0],$projects[0]); + $this->assertEqual($added[2],$projects[1]); + } + + function testRemoveUserFromProject() + { + $added = $this->add3Projects(); + $this->projectDao->addUserToProject(1, 'admin'); + $this->projectDao->addUserToProject(1, 'manager'); + $this->projectDao->addUserToProject(1, 'consultant'); + + $members = $this->projectDao->getProjectMembers(1); + + $this->assertEqual(count($members), 3); + $this->assertEqual($members[0], 'admin'); + $this->assertEqual($members[2], 'manager'); + $this->assertEqual($members[1], 'consultant'); + + $this->projectDao->removeUserFromProject(1,'admin'); + + $list = $this->projectDao->getProjectMembers(1); + + $this->assertEqual(count($list), 2); + $this->assertEqual($list[1], 'manager'); + $this->assertEqual($list[0], 'consultant'); + } + + function testUpdateProject() + { + $project = $this->createNewProject(); + $this->projectDao->addNewProject($project); + + $project->Description = "Project Testing 123"; + + $this->projectDao->updateProject($project); + + $check = $this->projectDao->getProjectByID(1); + $this->assertEqual($check, $project); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php b/demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php index 1ce97b3a..cead9fba 100644 --- a/demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php +++ b/demos/time-tracker/tests/unit/TimeEntryDaoTestCase.php @@ -1,214 +1,214 @@ -entryDao = $app->getModule('daos')->getDao('TimeEntryDao'); - $this->projectDao = $app->getModule('daos')->getDao('ProjectDao'); - $this->userDao = $app->getModule('daos')->getDao('UserDao'); - $this->categoryDao = $app->getModule('daos')->getDao('CategoryDao'); - $this->reportDao = $app->getModule('daos')->getDao('ReportDao'); - $this->flushDatabase(); - } - - function createNewProject() - { - $project = new ProjectRecord; - $project->CreatorUserName = "admin"; - $project->DateCreated = time(); - $project->CompletionDate = strtotime('+1 month'); - $project->Description = 'Test project 1'; - $project->EstimateDuration = 100.5; - $project->ManagerUserName = 'manager'; - $project->Name = 'Project 1'; - - return $project; - } - - function createNewProject2() - { - $project = new ProjectRecord; - $project->CreatorUserName = "manager"; - $project->DateCreated = time(); - $project->CompletionDate = strtotime('+1 week'); - $project->Description = 'Test project 2'; - $project->EstimateDuration = 30.5; - $project->ManagerUserName = 'manager'; - $project->Name = 'Project 2'; - - return $project; - } - - function createNewCategory() - { - $category = new CategoryRecord; - $category->Name = 'Category 1'; - $category->EstimateDuration = 5.5; - $category->Abbreviation = 'CAT 1'; - - return $category; - } - - function createNewCategory2() - { - $category = new CategoryRecord; - $category->Name = 'Category 2'; - $category->EstimateDuration = 1.5; - $category->Abbreviation = 'CAT2'; - - return $category; - } - - function createNewCategory3() - { - $category = new CategoryRecord; - $category->Name = 'Category 3'; - $category->EstimateDuration = 2.5; - $category->Abbreviation = 'CAT3'; - - return $category; - } - - function createProjectsAndCategories() - { - $project1 = $this->createNewProject(); - $this->projectDao->addNewProject($project1); - - $project2 = $this->createNewProject2(); - $this->projectDao->addNewProject($project2); - - $category1 = $this->createNewCategory(); - $category1->ProjectID = $project1->ID; - - $category2 = $this->createNewCategory2(); - $category2->ProjectID = $project2->ID; - - $category3 = $this->createNewCategory3(); - $category3->ProjectID = $project1->ID; - - $this->categoryDao->addNewCategory($category1); - $this->categoryDao->addNewCategory($category2); - $this->categoryDao->addNewCategory($category3); - - return array($project1, $project2, $category1, $category2, $category3); - } - - function assertSameEntry($entry1, $entry2) - { - $this->assertEqual($entry1->CreatorUserName, $entry2->CreatorUserName); - $this->assertEqual($entry1->Description, $entry2->Description); - $this->assertEqual($entry1->Duration, $entry2->Duration); - $this->assertEqual($entry1->ID, $entry2->ID); - $this->assertEqual($entry1->ReportDate, $entry2->ReportDate); - $this->assertEqual($entry1->Username, $entry2->Username); - } - - - function createTimeEntry1() - { - $added = $this->createProjectsAndCategories(); - - $entry = new TimeEntryRecord; - $entry->CreatorUserName = "admin"; - $entry->Category = $added[2]; - $entry->Description = "New work"; - $entry->Duration = 1.5; - $entry->Project = $added[0]; - $entry->ReportDate = strtotime('-1 day'); - $entry->Username = 'consultant'; - - return array($entry, $added); - } - - function createTimeEntries2() - { - $added = $this->createProjectsAndCategories(); - - $entry = new TimeEntryRecord; - $entry->CreatorUserName = "admin"; - $entry->Category = $added[2]; - $entry->Description = "New work"; - $entry->Duration = 1.2; - $entry->Project = $added[0]; - $entry->ReportDate = strtotime('-10 day'); - $entry->Username = 'consultant'; - - $entry2 = new TimeEntryRecord; - $entry2->CreatorUserName = "admin"; - $entry2->Category = $added[4]; - $entry2->Description = "New work 2"; - $entry2->Duration = 5.5; - $entry2->Project = $added[0]; - $entry2->ReportDate = strtotime('-4 day'); - $entry2->Username = 'consultant'; - - return array($entry, $entry2, $added); - } - - function testCreateNewTimeEntry() - { - $added = $this->createTimeEntry1(); - $entry = $added[0]; - $this->entryDao->addNewTimeEntry($entry); - - $check = $this->entryDao->getTimeEntryByID(1); - - $this->assertSameEntry($entry, $check); - } - - function testDeleteTimeEntry() - { - $this->testCreateNewTimeEntry(); - $this->entryDao->deleteTimeEntry(1); - - $check = $this->entryDao->getTimeEntryByID(1); - $this->assertNull($check); - } - - function testGetEntriesInProject() - { - $added = $this->createTimeEntries2(); - $this->entryDao->addNewTimeEntry($added[0]); - $this->entryDao->addNewTimeEntry($added[1]); - - $list = $this->entryDao->getTimeEntriesInProject('consultant', 1); - - $this->assertEqual(count($list), 2); - - $this->assertSameEntry($list[0], $added[0]); - $this->assertSameEntry($list[1], $added[1]); - } - - function testUpdateEntry() - { - $added = $this->createTimeEntry1(); - $entry = $added[0]; - $this->entryDao->addNewTimeEntry($entry); - - $check = $this->entryDao->getTimeEntryByID(1); - - $this->assertSameEntry($entry, $check); - - $entry->Description = "asdasd"; - $entry->Duration = 200; - - $this->entryDao->updateTimeEntry($entry); - - $verify = $this->entryDao->getTimeEntryByID(1); - - $this->assertSameEntry($entry, $verify); - } -} - +entryDao = $app->getModule('daos')->getDao('TimeEntryDao'); + $this->projectDao = $app->getModule('daos')->getDao('ProjectDao'); + $this->userDao = $app->getModule('daos')->getDao('UserDao'); + $this->categoryDao = $app->getModule('daos')->getDao('CategoryDao'); + $this->reportDao = $app->getModule('daos')->getDao('ReportDao'); + $this->flushDatabase(); + } + + function createNewProject() + { + $project = new ProjectRecord; + $project->CreatorUserName = "admin"; + $project->DateCreated = time(); + $project->CompletionDate = strtotime('+1 month'); + $project->Description = 'Test project 1'; + $project->EstimateDuration = 100.5; + $project->ManagerUserName = 'manager'; + $project->Name = 'Project 1'; + + return $project; + } + + function createNewProject2() + { + $project = new ProjectRecord; + $project->CreatorUserName = "manager"; + $project->DateCreated = time(); + $project->CompletionDate = strtotime('+1 week'); + $project->Description = 'Test project 2'; + $project->EstimateDuration = 30.5; + $project->ManagerUserName = 'manager'; + $project->Name = 'Project 2'; + + return $project; + } + + function createNewCategory() + { + $category = new CategoryRecord; + $category->Name = 'Category 1'; + $category->EstimateDuration = 5.5; + $category->Abbreviation = 'CAT 1'; + + return $category; + } + + function createNewCategory2() + { + $category = new CategoryRecord; + $category->Name = 'Category 2'; + $category->EstimateDuration = 1.5; + $category->Abbreviation = 'CAT2'; + + return $category; + } + + function createNewCategory3() + { + $category = new CategoryRecord; + $category->Name = 'Category 3'; + $category->EstimateDuration = 2.5; + $category->Abbreviation = 'CAT3'; + + return $category; + } + + function createProjectsAndCategories() + { + $project1 = $this->createNewProject(); + $this->projectDao->addNewProject($project1); + + $project2 = $this->createNewProject2(); + $this->projectDao->addNewProject($project2); + + $category1 = $this->createNewCategory(); + $category1->ProjectID = $project1->ID; + + $category2 = $this->createNewCategory2(); + $category2->ProjectID = $project2->ID; + + $category3 = $this->createNewCategory3(); + $category3->ProjectID = $project1->ID; + + $this->categoryDao->addNewCategory($category1); + $this->categoryDao->addNewCategory($category2); + $this->categoryDao->addNewCategory($category3); + + return array($project1, $project2, $category1, $category2, $category3); + } + + function assertSameEntry($entry1, $entry2) + { + $this->assertEqual($entry1->CreatorUserName, $entry2->CreatorUserName); + $this->assertEqual($entry1->Description, $entry2->Description); + $this->assertEqual($entry1->Duration, $entry2->Duration); + $this->assertEqual($entry1->ID, $entry2->ID); + $this->assertEqual($entry1->ReportDate, $entry2->ReportDate); + $this->assertEqual($entry1->Username, $entry2->Username); + } + + + function createTimeEntry1() + { + $added = $this->createProjectsAndCategories(); + + $entry = new TimeEntryRecord; + $entry->CreatorUserName = "admin"; + $entry->Category = $added[2]; + $entry->Description = "New work"; + $entry->Duration = 1.5; + $entry->Project = $added[0]; + $entry->ReportDate = strtotime('-1 day'); + $entry->Username = 'consultant'; + + return array($entry, $added); + } + + function createTimeEntries2() + { + $added = $this->createProjectsAndCategories(); + + $entry = new TimeEntryRecord; + $entry->CreatorUserName = "admin"; + $entry->Category = $added[2]; + $entry->Description = "New work"; + $entry->Duration = 1.2; + $entry->Project = $added[0]; + $entry->ReportDate = strtotime('-10 day'); + $entry->Username = 'consultant'; + + $entry2 = new TimeEntryRecord; + $entry2->CreatorUserName = "admin"; + $entry2->Category = $added[4]; + $entry2->Description = "New work 2"; + $entry2->Duration = 5.5; + $entry2->Project = $added[0]; + $entry2->ReportDate = strtotime('-4 day'); + $entry2->Username = 'consultant'; + + return array($entry, $entry2, $added); + } + + function testCreateNewTimeEntry() + { + $added = $this->createTimeEntry1(); + $entry = $added[0]; + $this->entryDao->addNewTimeEntry($entry); + + $check = $this->entryDao->getTimeEntryByID(1); + + $this->assertSameEntry($entry, $check); + } + + function testDeleteTimeEntry() + { + $this->testCreateNewTimeEntry(); + $this->entryDao->deleteTimeEntry(1); + + $check = $this->entryDao->getTimeEntryByID(1); + $this->assertNull($check); + } + + function testGetEntriesInProject() + { + $added = $this->createTimeEntries2(); + $this->entryDao->addNewTimeEntry($added[0]); + $this->entryDao->addNewTimeEntry($added[1]); + + $list = $this->entryDao->getTimeEntriesInProject('consultant', 1); + + $this->assertEqual(count($list), 2); + + $this->assertSameEntry($list[0], $added[0]); + $this->assertSameEntry($list[1], $added[1]); + } + + function testUpdateEntry() + { + $added = $this->createTimeEntry1(); + $entry = $added[0]; + $this->entryDao->addNewTimeEntry($entry); + + $check = $this->entryDao->getTimeEntryByID(1); + + $this->assertSameEntry($entry, $check); + + $entry->Description = "asdasd"; + $entry->Duration = 200; + + $this->entryDao->updateTimeEntry($entry); + + $verify = $this->entryDao->getTimeEntryByID(1); + + $this->assertSameEntry($entry, $verify); + } +} + ?> \ No newline at end of file diff --git a/demos/time-tracker/tests/unit/UserDaoTestCase.php b/demos/time-tracker/tests/unit/UserDaoTestCase.php index d216dbe6..ce40092e 100644 --- a/demos/time-tracker/tests/unit/UserDaoTestCase.php +++ b/demos/time-tracker/tests/unit/UserDaoTestCase.php @@ -1,271 +1,271 @@ -userDao = $app->getModule('daos')->getDao('UserDao'); - $this->flushDatabase(); - } - - function assertIsAdmin($user) - { - if(!$user) - return $this->fail(); - $this->assertEqual($user->getName(), 'admin'); - $this->assertEqual($user->getEmailAddress(), 'admin@pradosoft.com'); - } - - function assertSameUser($user1, $user2) - { - if(is_null($user1) || is_null($user2)) - return $this->fail(); - - $this->assertEqual($user1->getName(), $user2->getName()); - $this->assertEqual($user1->getEmailAddress(), $user2->getEmailAddress()); - } - - function assertIsAdminRole($user) - { - if(is_null($user)) - return $this->fail(); - - $this->assertTrue($user->isInRole('admin')); - } - - function assertIsManagerRole($user) - { - if(is_null($user)) - return $this->fail(); - - $this->assertTrue($user->isInRole('manager')); - } - - function assertIsConsultantRole($user) - { - if(is_null($user)) - return $this->fail(); - - $this->assertTrue($user->isInRole('consultant')); - } - - function assertNotConsultantRole($user) - { - if(is_null($user)) - return $this->fail(); - - $this->assertFalse($user->isInRole('consultant')); - } - - function testGetUserByName() - { - $user = $this->userDao->getUserByName('admin'); - $this->assertNotNull($user); - $this->assertIsAdmin($user); - } - - function testGetNonExistentUser() - { - $user = $this->userDao->getUserByName('none'); - $this->assertNull($user); - } - - function testGetUsers() - { - $users = $this->userDao->getAllUsers(); - $this->assertEqual(count($users), 3); - } - - function testUserLogon() - { - $success = $this->userDao->validateUser('admin', 'admin'); - $this->assertTrue($success); - } - - function testBadLogin() - { - $success = $this->userDao->validateUser('admin', 'hahah'); - $this->assertFalse($success); - } - - - function testAddNewUser() - { - $user = new TimeTrackerUser(new UserManager()); - $user->Name = "user1"; - $user->EmailAddress = 'user1@pradosoft.com'; - - $this->userDao->addNewUser($user, 'password'); - - $check = $this->userDao->getUserByName($user->Name); - - $this->assertSameUser($check, $user); - } - - function testDeleteUserByName() - { - $this->userDao->deleteUserByName('admin'); - - $admin = $this->userDao->getUserByName('admin'); - $this->assertNull($admin); - - $users = $this->userDao->getAllUsers(); - $this->assertEqual(count($users), 2); - } - - function testAutoSignon() - { - $user = new TimeTrackerUser(new UserManager()); - $user->Name = "admin"; - - $token = $this->userDao->createSignonToken($user); - - $check = $this->userDao->validateSignon($token); - - $this->assertIsAdmin($check); - } - - - function testBadAutoSignon() - { - $user = new TimeTrackerUser(new UserManager()); - $user->Name = "admin"; - - $token = $this->userDao->createSignonToken($user); - - $check = $this->userDao->validateSignon('adasd'); - $this->assertNull($check); - } - - function testAdminRoles() - { - $user = $this->userDao->getUserByName('admin'); - $this->assertIsAdminRole($user); - $this->assertIsManagerRole($user); - $this->assertIsConsultantRole($user); - } - - function testSetUserRoles() - { - $user = new TimeTrackerUser(new UserManager()); - $user->Name = "user1"; - $user->EmailAddress = 'user1@pradosoft.com'; - $user->Roles = array("manager", "consultant"); - - $this->userDao->addNewUser($user, 'password'); - $check = $this->userDao->getUserByName('user1'); - - $this->assertIsManagerRole($check); - $this->assertIsConsultantRole($check); - } - - function testSetUserRoleNoNullUser() - { - $user = new TimeTrackerUser(new UserManager()); - $user->Name = "user1"; - $user->EmailAddress = 'user1@pradosoft.com'; - $user->Roles = array("manager", "consultant"); - - try - { - $this->userDao->updateUserRoles($user); - $this->fail(); - } - catch(TDbException $e) - { - $this->pass(); - } - - $check = $this->sqlmap->queryForObject('GetUserByName', 'user1'); - $this->assertNull($check); - } - - function testUpdateUser() - { - $user = $this->userDao->getUserByName('admin'); - $user->EmailAddress = 'something@pradosoft.com'; - $user->Roles = array('manager', 'admin'); - - $this->userDao->updateUser($user); - - $check = $this->userDao->getUserByName('admin'); - $this->assertIsAdminRole($check); - $this->assertIsManagerRole($check); - $this->assertNotConsultantRole($check); - } - - function testUpdateUserPassword() - { - $user = $this->userDao->getUserByName('admin'); - $user->EmailAddress = 'something@pradosoft.com'; - $user->Roles = array('manager', 'admin'); - - $pass = 'newpasword'; - - $this->userDao->updateUser($user, $pass); - - $success = $this->userDao->validateUser('admin', $pass); - - $this->assertTrue($success); - } - - function testClearSignonTokens() - { - $user = new TimeTrackerUser(new UserManager()); - $user->Name = "admin"; - - $token1 = $this->userDao->createSignonToken($user); - sleep(1); - $token2 = $this->userDao->createSignonToken($user); - $this->assertNotEqual($token1, $token2); - - $check1 = $this->userDao->validateSignon($token1); - $check2 = $this->userDao->validateSignon($token2); - - $this->assertIsAdmin($check1); - $this->assertIsAdmin($check2); - - $this->userDao->clearSignonTokens($user); - - $check3 = $this->userDao->validateSignon($token1); - $check4 = $this->userDao->validateSignon($token2); - - $this->assertNull($check3); - $this->assertNull($check4); - } - - function testClearAllSigonTokens() - { - $user1 = new TimeTrackerUser(new UserManager()); - $user1->Name = "admin"; - - $user2 = new TimeTrackerUser(new UserManager()); - $user2->Name = "manager"; - - $token1 = $this->userDao->createSignonToken($user1); - $token2 = $this->userDao->createSignonToken($user2); - - $check1 = $this->userDao->validateSignon($token1); - $check2 = $this->userDao->validateSignon($token2); - - $this->assertIsAdmin($check1); - $this->assertNotNull($check2); - $this->assertEqual($check2->Name, $user2->Name); - - $this->userDao->clearSignonTokens(); - - $check3 = $this->userDao->validateSignon($token1); - $check4 = $this->userDao->validateSignon($token2); - - $this->assertNull($check3); - $this->assertNull($check4); - } -} - +userDao = $app->getModule('daos')->getDao('UserDao'); + $this->flushDatabase(); + } + + function assertIsAdmin($user) + { + if(!$user) + return $this->fail(); + $this->assertEqual($user->getName(), 'admin'); + $this->assertEqual($user->getEmailAddress(), 'admin@pradosoft.com'); + } + + function assertSameUser($user1, $user2) + { + if(is_null($user1) || is_null($user2)) + return $this->fail(); + + $this->assertEqual($user1->getName(), $user2->getName()); + $this->assertEqual($user1->getEmailAddress(), $user2->getEmailAddress()); + } + + function assertIsAdminRole($user) + { + if(is_null($user)) + return $this->fail(); + + $this->assertTrue($user->isInRole('admin')); + } + + function assertIsManagerRole($user) + { + if(is_null($user)) + return $this->fail(); + + $this->assertTrue($user->isInRole('manager')); + } + + function assertIsConsultantRole($user) + { + if(is_null($user)) + return $this->fail(); + + $this->assertTrue($user->isInRole('consultant')); + } + + function assertNotConsultantRole($user) + { + if(is_null($user)) + return $this->fail(); + + $this->assertFalse($user->isInRole('consultant')); + } + + function testGetUserByName() + { + $user = $this->userDao->getUserByName('admin'); + $this->assertNotNull($user); + $this->assertIsAdmin($user); + } + + function testGetNonExistentUser() + { + $user = $this->userDao->getUserByName('none'); + $this->assertNull($user); + } + + function testGetUsers() + { + $users = $this->userDao->getAllUsers(); + $this->assertEqual(count($users), 3); + } + + function testUserLogon() + { + $success = $this->userDao->validateUser('admin', 'admin'); + $this->assertTrue($success); + } + + function testBadLogin() + { + $success = $this->userDao->validateUser('admin', 'hahah'); + $this->assertFalse($success); + } + + + function testAddNewUser() + { + $user = new TimeTrackerUser(new UserManager()); + $user->Name = "user1"; + $user->EmailAddress = 'user1@pradosoft.com'; + + $this->userDao->addNewUser($user, 'password'); + + $check = $this->userDao->getUserByName($user->Name); + + $this->assertSameUser($check, $user); + } + + function testDeleteUserByName() + { + $this->userDao->deleteUserByName('admin'); + + $admin = $this->userDao->getUserByName('admin'); + $this->assertNull($admin); + + $users = $this->userDao->getAllUsers(); + $this->assertEqual(count($users), 2); + } + + function testAutoSignon() + { + $user = new TimeTrackerUser(new UserManager()); + $user->Name = "admin"; + + $token = $this->userDao->createSignonToken($user); + + $check = $this->userDao->validateSignon($token); + + $this->assertIsAdmin($check); + } + + + function testBadAutoSignon() + { + $user = new TimeTrackerUser(new UserManager()); + $user->Name = "admin"; + + $token = $this->userDao->createSignonToken($user); + + $check = $this->userDao->validateSignon('adasd'); + $this->assertNull($check); + } + + function testAdminRoles() + { + $user = $this->userDao->getUserByName('admin'); + $this->assertIsAdminRole($user); + $this->assertIsManagerRole($user); + $this->assertIsConsultantRole($user); + } + + function testSetUserRoles() + { + $user = new TimeTrackerUser(new UserManager()); + $user->Name = "user1"; + $user->EmailAddress = 'user1@pradosoft.com'; + $user->Roles = array("manager", "consultant"); + + $this->userDao->addNewUser($user, 'password'); + $check = $this->userDao->getUserByName('user1'); + + $this->assertIsManagerRole($check); + $this->assertIsConsultantRole($check); + } + + function testSetUserRoleNoNullUser() + { + $user = new TimeTrackerUser(new UserManager()); + $user->Name = "user1"; + $user->EmailAddress = 'user1@pradosoft.com'; + $user->Roles = array("manager", "consultant"); + + try + { + $this->userDao->updateUserRoles($user); + $this->fail(); + } + catch(TDbException $e) + { + $this->pass(); + } + + $check = $this->sqlmap->queryForObject('GetUserByName', 'user1'); + $this->assertNull($check); + } + + function testUpdateUser() + { + $user = $this->userDao->getUserByName('admin'); + $user->EmailAddress = 'something@pradosoft.com'; + $user->Roles = array('manager', 'admin'); + + $this->userDao->updateUser($user); + + $check = $this->userDao->getUserByName('admin'); + $this->assertIsAdminRole($check); + $this->assertIsManagerRole($check); + $this->assertNotConsultantRole($check); + } + + function testUpdateUserPassword() + { + $user = $this->userDao->getUserByName('admin'); + $user->EmailAddress = 'something@pradosoft.com'; + $user->Roles = array('manager', 'admin'); + + $pass = 'newpasword'; + + $this->userDao->updateUser($user, $pass); + + $success = $this->userDao->validateUser('admin', $pass); + + $this->assertTrue($success); + } + + function testClearSignonTokens() + { + $user = new TimeTrackerUser(new UserManager()); + $user->Name = "admin"; + + $token1 = $this->userDao->createSignonToken($user); + sleep(1); + $token2 = $this->userDao->createSignonToken($user); + $this->assertNotEqual($token1, $token2); + + $check1 = $this->userDao->validateSignon($token1); + $check2 = $this->userDao->validateSignon($token2); + + $this->assertIsAdmin($check1); + $this->assertIsAdmin($check2); + + $this->userDao->clearSignonTokens($user); + + $check3 = $this->userDao->validateSignon($token1); + $check4 = $this->userDao->validateSignon($token2); + + $this->assertNull($check3); + $this->assertNull($check4); + } + + function testClearAllSigonTokens() + { + $user1 = new TimeTrackerUser(new UserManager()); + $user1->Name = "admin"; + + $user2 = new TimeTrackerUser(new UserManager()); + $user2->Name = "manager"; + + $token1 = $this->userDao->createSignonToken($user1); + $token2 = $this->userDao->createSignonToken($user2); + + $check1 = $this->userDao->validateSignon($token1); + $check2 = $this->userDao->validateSignon($token2); + + $this->assertIsAdmin($check1); + $this->assertNotNull($check2); + $this->assertEqual($check2->Name, $user2->Name); + + $this->userDao->clearSignonTokens(); + + $check3 = $this->userDao->validateSignon($token1); + $check4 = $this->userDao->validateSignon($token2); + + $this->assertNull($check3); + $this->assertNull($check4); + } +} + ?> \ No newline at end of file -- cgit v1.2.3