lifetype/branches/lifetype-1.0.6/class/action/admin/adminaddblogaction.class.php
Go to the documentation of this file.00001 <?php
00002
00003 include_once( PLOG_CLASS_PATH."class/action/admin/siteadminaction.class.php" );
00004 include_once( PLOG_CLASS_PATH."class/view/admin/admincreateblogview.class.php" );
00005 include_once( PLOG_CLASS_PATH."class/view/admin/adminsiteblogslistview.class.php" );
00006 include_once( PLOG_CLASS_PATH."class/data/validator/stringvalidator.class.php" );
00007 include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
00008 include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
00009
00016 class AdminAddBlogAction extends SiteAdminAction
00017 {
00018
00019 var $_blogName;
00020 var $_ownerId;
00021 var $_blogProperties;
00022
00023 function AdminAddBlogAction( $actionInfo, $request )
00024 {
00025 $this->SiteAdminAction( $actionInfo, $request );
00026
00027
00028 $this->registerFieldValidator( "blogName", new StringValidator());
00029 $this->registerFieldValidator( "blogOwner", new IntegerValidator());
00030 $this->setValidationErrorView( new AdminCreateBlogView( $this->_blogInfo ));
00031 }
00032
00033 function perform()
00034 {
00035
00036 $this->_blogName = Textfilter::filterAllHTML($this->_request->getValue( "blogName" ));
00037 $this->_ownerId = $this->_request->getValue( "blogOwner" );
00038 $this->_blogProperties = $this->_request->getValue( "properties" );
00039
00040
00041 $users = new Users();
00042 $userInfo = $users->getUserInfoFromId( $this->_ownerId );
00043 if( !$userInfo ) {
00044 $this->_view = new AdminCreateBlogView( $this->_blogInfo );
00045 $this->_form->setFieldValidationStatus( "blogOwner", false );
00046 $this->setCommonData( true );
00047 return false;
00048 }
00049
00050
00051
00052 $blogs = new Blogs();
00053 $blog = new BlogInfo( $this->_blogName, $this->_ownerId, "", "" );
00054 $blog->setProperties( $this->_blogProperties );
00055
00056 $this->notifyEvent( EVENT_PRE_BLOG_ADD, Array( "blog" => &$blog ));
00057 $newBlogId = $blogs->addBlog( $blog );
00058 if( !$newBlogId) {
00059 $this->_view = new AdminCreateBlogView( $this->_blogInfo );
00060 $this->_form->setFieldValidationStatus( "blogName", false );
00061 $this->setCommonData();
00062
00063 return false;
00064 }
00065
00066
00067 $config =& Config::getConfig();
00068 $locale =& Locales::getLocale( $config->getValue( "default_locale" ));
00069
00070
00071 $articleCategories = new ArticleCategories();
00072 $articleCategory = new ArticleCategory( $locale->tr( "register_default_category" ), "", $newBlogId, true );
00073 $catId = $articleCategories->addArticleCategory( $articleCategory );
00074 $articleTopic = $locale->tr( "register_default_article_topic" );
00075 $articleText = $locale->tr( "register_default_article_text" );
00076 $article = new Article( $articleTopic,
00077 $articleText,
00078 Array( $catId ),
00079 $this->_ownerId,
00080 $newBlogId,
00081 POST_STATUS_PUBLISHED,
00082 0,
00083 Array(),
00084 "welcome" );
00085 $t = new Timestamp();
00086 $article->setDateObject( $t );
00087 $articles = new Articles();
00088 $articles->addArticle( $article );
00089
00090
00091 $this->notifyEvent( EVENT_POST_BLOG_ADD, Array( "blog" => &$blog ));
00092 $this->_view = new AdminSiteBlogsListView( $this->_blogInfo );
00093 $this->_view->setSuccessMessage($this->_locale->pr("blog_added_ok", $blog->getBlog()));
00094 $this->setCommonData();
00095
00096 return true;
00097 }
00098 }
00099 ?>