[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/view/admin/admintemplatedview.class.php" ); 4 lt_include( PLOG_CLASS_PATH."class/locale/locales.class.php" ); 5 lt_include( PLOG_CLASS_PATH."class/dao/articles.class.php" ); 6 lt_include( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" ); 7 lt_include( PLOG_CLASS_PATH."class/dao/articlestatus.class.php" ); 8 lt_include( PLOG_CLASS_PATH."class/data/pager/pager.class.php" ); 9 lt_include( PLOG_CLASS_PATH.'class/data/timestamp.class.php' ); 10 lt_include( PLOG_CLASS_PATH."class/dao/users.class.php" ); 11 lt_include( PLOG_CLASS_PATH."class/config/siteconfig.class.php" ); 12 13 /** 14 * \ingroup View 15 * @private 16 * 17 * shows a list of posts 18 */ 19 class AdminPostsListView extends AdminTemplatedView 20 { 21 22 var $_showCategory = -1; 23 var $_showStatus = 1; 24 var $_showUser = 0; 25 var $_showMonth; 26 var $_searchTerms; 27 var $_page; 28 29 function AdminPostsListView( $blogInfo, $params = Array()) 30 { 31 $this->AdminTemplatedView( $blogInfo, "editposts" ); 32 33 // we're going to need a locale... 34 $this->_locale =& $blogInfo->getLocale(); 35 36 // prepare the parameters that the view is going to use 37 $this->_setViewParameters( $params ); 38 39 $this->_page = $this->getCurrentPageFromRequest(); 40 41 $blogSettings = $blogInfo->getSettings(); 42 43 $this->_itemsPerPage = $blogSettings->getValue( "show_posts_max" ); 44 if( $this->_itemsPerPage > SiteConfig::getHardShowPostsMax()) 45 $this->_itemsPerPage = SiteConfig::getHardShowPostsMax(); 46 } 47 48 49 50 /** 51 * calculates the array to display with the months 52 * 53 * @private 54 */ 55 function _getMonths() 56 { 57 $articles = new Articles(); 58 $archiveStats = $articles->getNumberPostsPerMonthAdmin( $this->_blogInfo->getId()); 59 60 if( !$archiveStats ) 61 return Array(); 62 63 $result = Array(); 64 65 $t = new Timestamp(); 66 $curyear = (int)$t->getYear(); 67 $curmonth = (int)$t->getMonth(); 68 69 $archiveDateFormat = $this->_locale->tr( "archive_date_format" ); 70 if( $archiveDateFormat == "archive_date_format" ) $archiveDateFormat = "%B %Y"; 71 72 // Add current month, even if there aren't any posts in it 73 if( empty( $archiveStats[$curyear][$curmonth] )) { 74 $t = new Timestamp(); 75 $name = $this->_locale->formatDate( $t, $archiveDateFormat ); 76 $monthStr = Array( "name" => $name, 77 "date" => $this->_locale->formatDate($t, "%Y%m")); 78 array_push( $result, $monthStr ); 79 } 80 81 foreach( $archiveStats as $yearName => $year) { 82 foreach( $year as $monthName => $month ) { 83 // we can use the Timestamp class to help us with this... 84 $t = new Timestamp( "" ); 85 $t->setYear( $yearName ); 86 $t->setMonth( $monthName ); 87 $name = $this->_locale->formatDate( $t, $archiveDateFormat ); 88 $monthStr = Array( "name" => $name, 89 "date" => $this->_locale->formatDate($t, "%Y%m")); 90 array_push( $result, $monthStr ); 91 } 92 } 93 94 return $result; 95 } 96 97 /** 98 * gets the value of a parameter 99 * @private 100 */ 101 function _getParameter( $params, $paramId, $defaultValue ) 102 { 103 $value = ""; 104 if( array_key_exists( $paramId, $params ) ) 105 { 106 $value = $params["$paramId"]; 107 } 108 if( $value == "" ) 109 $value = $this->getSessionValue( $paramId, $defaultValue ); 110 111 return $value; 112 } 113 114 function _setViewParameters( $params ) 115 { 116 // fetch the different parameters that we are going to need 117 // to show the view... 118 119 $this->_showCategory = $this->_getParameter( $params, "showCategory", -1 ); 120 $this->_showStatus = $this->_getParameter( $params, "showStatus", POST_STATUS_ALL ); 121 $this->_showUser = $this->_getParameter( $params, "showUser", 0 ); 122 $this->_showMonth = $this->_getParameter( $params, "showMonth", $this->_locale->formatDate( new Timestamp(), "%Y%m" )); 123 $this->_searchTerms = $this->_getParameter( $params, "searchTerms", ""); 124 125 // print("search terms = ".$this->_searchTerms); 126 } 127 128 /** 129 * renders the view 130 */ 131 function render() 132 { 133 134 // fetch all the articles for edition, but we need to know whether we are trying to 135 // search for some of them or simply filter them based on certain criteria 136 $articles = new Articles(); 137 $posts = $articles->getBlogArticles( $this->_blogInfo->getId(), // the blog id 138 $this->_showMonth, // current month 139 $this->_itemsPerPage, 140 $this->_showCategory, // current category 141 $this->_showStatus, // current status 142 $this->_showUser, // current user 143 0, // no maxdate 144 $this->_searchTerms, // current search terms 145 $this->_page // current page 146 ); 147 148 // get the total number of posts 149 $numPosts = $articles->getNumBlogArticles( 150 $this->_blogInfo->getId(), // the blog id 151 $this->_showMonth, // current month 152 $this->_showCategory, // current category 153 $this->_showStatus, // current status 154 $this->_showUser, // current user 155 0, // no maxdate 156 $this->_searchTerms // current search terms 157 ); 158 159 $pager = new Pager( "?op=editPosts&showMonth={$this->_showMonth}&showStatus={$this->_showStatus}&showCategory={$this->_showCategory}&showUser={$this->_showUser}&searchTerms={$this->_searchTerms}&page=", 160 $this->_page, 161 $numPosts, 162 $this->_itemsPerPage ); 163 164 $this->setValue( "posts", $posts ); 165 166 // throw the even in case somebody is listening to it 167 $this->notifyEvent( EVENT_POSTS_LOADED, Array( "posts" => &$posts )); 168 169 // and the categories 170 $categories = new ArticleCategories(); 171 $blogSettings = $this->_blogInfo->getSettings(); 172 $categoriesOrder = $blogSettings->getValue( "categories_order" ); 173 $blogCategories = $categories->getBlogCategories( $this->_blogInfo->getId(), 174 false, $categoriesOrder ); 175 $this->notifyEvent( EVENT_CATEGORIES_LOADED, Array( "categories" => &$blogCategories )); 176 177 // and all the users that belong to this blog 178 $users = new Users(); 179 $blogUsers = $users->getBlogUsers( $this->_blogInfo->getId()); 180 181 // and all the post status available 182 $postStatusList = ArticleStatus::getStatusList( true ); 183 $postStatusListWithoutAll = ArticleStatus::getStatusList( false ); 184 185 $this->setValue( "categories", $blogCategories ); 186 // values for the session, so that we can recover the status 187 // of the filters later on in subsequent requests 188 $this->setSessionValue( "showCategory", $this->_showCategory ); 189 $this->setSessionValue( "showStatus", $this->_showStatus ); 190 $this->setSessionValue( "showUser", $this->_showUser ); 191 $this->setSessionValue( "showMonth", $this->_showMonth ); 192 // values for the view 193 $this->setValue( "currentcategory", $this->_showCategory ); 194 $this->setValue( "currentstatus", $this->_showStatus ); 195 $this->setValue( "currentuser", $this->_showUser ); 196 $this->setValue( "currentmonth", $this->_showMonth ); 197 $this->setValue( "users", $blogUsers ); 198 $this->setValue( "months", $this->_getMonths()); 199 $this->setValue( "poststatus", $postStatusList ); 200 $this->setValue( "poststatusWithoutAll", $postStatusListWithoutAll ); 201 $this->setValue( "searchTerms", $this->_searchTerms ); 202 $this->setValue( "pager", $pager ); 203 204 parent::render(); 205 } 206 } 207 ?>
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 |
![]() |