[pLog-svn] r6607 - plog/branches/lifetype-1.2/class/action/admin
mark at devel.lifetype.net
mark at devel.lifetype.net
Fri Jun 20 15:16:40 EDT 2008
Author: mark
Date: 2008-06-20 15:16:40 -0400 (Fri, 20 Jun 2008)
New Revision: 6607
Modified:
plog/branches/lifetype-1.2/class/action/admin/adminaddarticlecategoryajaxaction.class.php
Log:
Validate the input values with registerFieldValidator()
Modified: plog/branches/lifetype-1.2/class/action/admin/adminaddarticlecategoryajaxaction.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/action/admin/adminaddarticlecategoryajaxaction.class.php 2008-06-20 19:15:45 UTC (rev 6606)
+++ plog/branches/lifetype-1.2/class/action/admin/adminaddarticlecategoryajaxaction.class.php 2008-06-20 19:16:40 UTC (rev 6607)
@@ -2,7 +2,9 @@
lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
- lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
+ lt_include( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
lt_include( PLOG_CLASS_PATH."class/view/admin/adminxmlview.class.php" );
/**
@@ -15,9 +17,8 @@
{
var $_categoryName;
- var $_categoryUrl;
- var $_properties;
- var $_categoryDescription;
+ var $_categoryDescription;
+ var $_categoryInMainPage;
/**
* Constructor. If nothing else, it also has to call the constructor of the parent
@@ -25,52 +26,42 @@
*/
function AdminAddArticleCategoryAjaxAction( $actionInfo, $request )
{
- $this->AdminAction( $actionInfo, $request );
+ $this->AdminAction( $actionInfo, $request );
+
+ // register two validators
+ $this->registerFieldValidator( "categoryName", new StringValidator());
+ $this->registerFieldValidator( "categoryDescription", new StringValidator());
+ $this->registerFieldValidator( "categoryInMainPage", new IntegerValidator(), true );
+
+ $view = new AdminXmlView( $this->_blogInfo, "response" );
+ $view->setValue( "method", "addCategoryAjax" );
+ $view->setValue( "success", "0" );
+ $view->setValue( "message", $this->_locale->tr("error_adding_article_category") );
+
+ $this->setValidationErrorView( $view );
+
+ $this->requirePermission( "add_category" );
}
- function validate()
- {
- // check if the user has the add_category permission
- if( !$this->userHasPermission( "add_category" ) ) {
- $this->_view = new AdminXmlView( $this->_blogInfo, "response" );
- $this->_view->setValue( "method", "addCategoryAjax" );
- $this->_view->setValue( "success", "0" );
- $this->_view->setValue( "message", $this->_locale->tr("error_permission_required") );
- return false;
- }
-
- // check if category name is empty
- $this->_categoryName = Textfilter::filterAllHTML($this->_request->getValue( "categoryName" ));
- $this->_categoryUrl = "";
- $this->_categoryInMainPage = 1;
- $this->_categoryDescription = $this->_categoryName;
- $this->_properties = "";
-
- if( empty($this->_categoryName) || $this->_categoryName == "" ) {
- $this->_view = new AdminXmlView( $this->_blogInfo, "response" );
- $this->_view->setValue( "method", "addCategoryAjax" );
- $this->_view->setValue( "success", "0" );
- $this->_view->setValue( "message", $this->_locale->tr("error_adding_article_category") );
- return false;
- }
-
- return true;
- }
-
/**
* Carries out the specified action
*/
function perform()
{
- // create the object...
+ // fetch the input values
+ $this->_categoryName = Textfilter::filterAllHTML($this->_request->getValue( "categoryName" ));
+ $this->_categoryInMainPage = 1;
+ $this->_categoryDescription = $this->_categoryName;
+
+ // create the object...
$categories = new ArticleCategories();
$category = new ArticleCategory( $this->_categoryName,
- $this->_categoryUrl,
+ "",
$this->_blogInfo->getId(),
$this->_categoryInMainPage,
$this->_categoryDescription,
0,
- $this->_properties );
+ Array() );
// fire the pre event...
$this->notifyEvent( EVENT_PRE_CATEGORY_ADD, Array( "category" => &$category ));
More information about the pLog-svn
mailing list