[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/view/view.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/template/templateservice.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/template/menu/menurenderer.class.php" ); 6 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" ); 7 lt_include( PLOG_CLASS_PATH."class/dao/articlecomments.class.php" ); 8 lt_include( PLOG_CLASS_PATH."class/dao/trackbacks.class.php" ); 9 lt_include( PLOG_CLASS_PATH."class/config/config.class.php" ); 10 // lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresources.class.php" ); 11 12 /** 13 * maximum number of recent items that we will show in the statistics 14 */ 15 define( "DASHBOARD_MAX_RECENT_ITEMS", 5 ); 16 17 /** 18 * how many blogs a user can own, by default 19 */ 20 define( "DEFAULT_MAX_BLOGS_PER_USER", 1 ); 21 22 /** 23 * \ingroup View 24 * @private 25 * 26 * Generates the view with the summary 27 */ 28 class AdminDashboardView extends View 29 { 30 31 var $_userInfo; 32 var $_userBlogs; 33 var $_config; 34 35 /** 36 * This initializes the class, but normally we'll only have to initialize the parent 37 * 38 * It gets the BlogSettings object since we need to know a few things about the blog we're 39 * rendering before doing this. 40 */ 41 function AdminDashboardView( $userInfo, $userBlogs ) 42 { 43 $this->View(); 44 45 // keep the paramters for later use 46 $this->_userInfo = $userInfo; 47 $this->_userBlogs = $userBlogs; 48 $this->_config =& Config::getConfig(); 49 50 $this->_loadViewData(); 51 } 52 53 /** 54 * normally views do not meddle with data but in this case moving all 55 * this data fetching here is benefitial from a coding point of view, because it 56 * allows this code to be reused by several action classes... In the worst case 57 * we would have to copy+paste the code or put in a separate class only for this bit 58 * of code. By moving it here, the view itself can handle everything 59 */ 60 function _loadViewData() 61 { 62 // for each blog, load some statistics 63 $articles = new Articles(); 64 $comments = new ArticleComments(); 65 $trackbacks = new Trackbacks(); 66 // $resources = new GalleryResources(); 67 $recentPosts = Array(); 68 $recentComments = Array(); 69 $recentResources = Array(); 70 71 // load some statistics for each one of the blogs 72 $numOwnedBlogs = 0; 73 foreach( $this->_userBlogs as $userBlog ) { 74 $recentPosts[$userBlog->getId()] = $articles->getBlogArticles( $userBlog->getId(), 75 -1, // no date, 76 DASHBOARD_MAX_RECENT_ITEMS, 77 -1, 78 POST_STATUS_PUBLISHED ); 79 $recentComments[$userBlog->getId()] = $comments->getBlogComments ( $userBlog->getId(), 80 COMMENT_ORDER_NEWEST_FIRST, 81 COMMENT_STATUS_ALL, 82 "", // no search terms 83 1, // first page 84 DASHBOARD_MAX_RECENT_ITEMS ); 85 $recentTrackbacks[$userBlog->getId()] = $trackbacks->getBlogTrackbacks( $userBlog->getId(), 86 COMMENT_STATUS_ALL, 87 "", 88 1, 89 DASHBOARD_MAX_RECENT_ITEMS ); 90 if( $userBlog->getOwner() == $this->_userInfo->getId()) 91 $numOwnedBlogs++; 92 } 93 94 $this->_params->setValue( "userblogs", $this->_userBlogs ); 95 $this->_params->setValue( "recentposts", $recentPosts ); 96 $this->_params->setValue( "recentcomments", $recentComments ); 97 $this->_params->setValue( "recenttrackbacks", $recentTrackbacks ); 98 $this->_params->setValue( "user", $this->_userInfo ); 99 100 // check whether the user can create new blogs 101 $maxBlogsPerUser = $this->_config->getValue( "num_blogs_per_user" ); 102 if( !is_numeric( $maxBlogsPerUser )) 103 $maxBlogsPerUser = DEFAULT_MAX_BLOGS_PER_USER; 104 $numOfUserBlogs = count( $this->_userInfo->getOwnBlogs() ); 105 106 if( $numOfUserBlogs < $maxBlogsPerUser ) 107 $userCanCreateBlog = true; 108 else 109 $userCanCreateBlog = false; 110 111 $this->_params->setValue( "userCanCreateBlog", $userCanCreateBlog ); 112 } 113 114 /** 115 * Renders the view. It simply gets all the parameters we've been adding to it 116 * and puts them in the context of the template renderer so that they can be accessed 117 * as normal parameters from within the template 118 */ 119 function render() 120 { 121 // set the view character set based on the default locale 122 if( empty( $this->_userBlogs )) 123 $locale =& Locales::getLocale( $this->_config->getValue( "default_locale" )); 124 else 125 $locale = $this->_userBlogs[0]->getLocale(); 126 127 $this->setCharset( $locale->getCharset()); 128 129 parent::render(); 130 131 // to find the template we need, we can use the TemplateService 132 $ts = new TemplateService(); 133 $template = $ts->AdminTemplate( "dashboard" ); 134 $this->setValue( "locale", $locale ); 135 $this->setValue( "bayesian_filter_enabled", $this->_config->getValue( "bayesian_filter_enabled" )); 136 // assign all the values 137 $template->assign( $this->_params->getAsArray()); 138 139 // and send the results 140 print $template->fetch(); 141 } 142 143 function setUserInfo() 144 { 145 // ... 146 } 147 } 148 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |