Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Problem- małe przekształcenie modułu joomla 1.5
Forum PHP.pl > Forum > PHP
dawidryba
Witam serdecznie, chciałbym przekształcić pewien moduł, którego używam na mojej stronie w CMS Joomla.

A mianowicie, wyświetla on liczbę plików z największą ilością pobrań. Chciałbym, aby wyświetlał pliki o najnowszym/największym ID. Trochę się bawiłem, myślałem, jednak na php nie potrafię to przełożyć i przerobić. Niestety jestem amatorem w tej dziedzinie, choć bardzo chcę się tego nauczyć, bardziej ogarniam C lub Pascala.

Jak domyśliłem się można byłoby przerobić na takiej zasadzie, że najpierw sprawdza ile jest pozycji w bazie, a następnie wyświetla daną licze pozycji od końca (liczbę ustawia się w panelu administracyjnym modułu).

Wy będziecie wiedzieli najlepiej jak zrobić, żeby chodziło.

Bardzo proszę o pomoc!!!

Oto kod:

  1. <?php
  2. /*
  3.  * @package Joomla 1.5
  4.  * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved.
  5.  * @license <a href="http://www.gnu.org/copyleft/gpl.html" target="_blank">http://www.gnu.org/copyleft/gpl.html</a> GNU/GPL, see LICENSE.php
  6.  *
  7.  * @module Phoca - Phoca Module
  8.  * @copyright Copyright (C) Jan Pavelka www.phoca.cz
  9.  * @license <a href="http://www.gnu.org/copyleft/gpl.html" target="_blank">http://www.gnu.org/copyleft/gpl.html</a> GNU/GPL
  10.  */
  11.  
  12. defined('_JEXEC') or die('Restricted access');// no direct access
  13. if (!JComponentHelper::isEnabled('com_phocadownload', true)) {
  14. return JError::raiseError(JText::_('Phoca Download Error'), JText::_('Phoca Download is not installed on your system'));
  15. }
  16. require_once( JPATH_BASE.DS.'components'.DS.'com_phocadownload'.DS.'helpers'.DS.'phocadownload.php' );
  17. require_once( JPATH_BASE.DS.'components'.DS.'com_phocadownload'.DS.'helpers'.DS.'route.php' );
  18. require_once( JPATH_ADMINISTRATOR.DS.'components'.DS.'com_phocadownload'.DS.'helpers'.DS.'phocadownload.php' );
  19.  
  20. $user =& JFactory::getUser();
  21. $aid = $user->get('aid', 0);
  22. $db =& JFactory::getDBO();
  23. $menu =& JSite::getMenu();
  24. $document =& JFactory::getDocument();
  25.  
  26.  
  27. // PARAMS
  28. $module_width = $params->get( 'module_width', 400 );
  29. $font_size = $params->get( 'font_size', 10 );
  30. $display_downloads = $params->get( 'display_downloads', 1 );
  31. $display_cat_sec = $params->get( 'display_cat_sec', 1 );
  32. $display_title = $params->get( 'display_title', 1 );
  33. $display_filename = $params->get( 'display_filename', 1 );
  34. $number_item = $params->get( 'number_item',6 );
  35. $displayS = $params->get( 'section_id','' );
  36.  
  37.  
  38. // Max Hit
  39. $wheres = array();
  40. $wheres[] = ' a.published = 1';
  41. $wheres[] = ' s.published = 1';
  42. $wheres[] = ' cc.published = 1';
  43. $wheres[] = ' a.textonly = 0';
  44.  
  45. // Active
  46. $jnow =& JFactory::getDate();
  47. $now = $jnow->toMySQL();
  48. $nullDate = $db->getNullDate();
  49. $wheres[] = ' ( a.publish_up = '.$db->Quote($nullDate).' OR a.publish_up <= '.$db->Quote($now).' )';
  50. $wheres[] = ' ( a.publish_down = '.$db->Quote($nullDate).' OR a.publish_down >= '.$db->Quote($now).' )';
  51.  
  52. // SQL, QUERY
  53. if (count($displayS) > 1) {
  54. JArrayHelper::toInteger($displayS);
  55. $displaySString = implode(',', $displayS);
  56. $wheres[] = ' a.id IN ( '.$displaySString.' ) ';
  57. } else if ((int)$displayS > 0) {
  58. $wheres[] = ' a.id IN ( '.$displayS.' ) ';
  59. }
  60.  
  61. $where = ( count( $wheres ) ? ' WHERE '. implode( ' AND ', $wheres ) : '' );
  62. $query = ' SELECT MAX(a.hits) AS maxhit '
  63. . ' FROM #__phocadownload AS a '
  64. . ' LEFT JOIN #__phocadownload_categories AS cc ON cc.id = a.catid '
  65. . ' LEFT JOIN #__phocadownload_sections AS s ON s.id = a.sectionid '
  66. . ' LEFT JOIN #__groups AS g ON g.id = a.access '
  67. . $where;
  68. $db->setQuery( $query );
  69. $maxHit = $db->loadObjectList();
  70.  
  71.  
  72. // Items
  73. $wheres = array();
  74. $wheres[] = ' a.published = 1';
  75. $wheres[] = ' s.published = 1';
  76. $wheres[] = ' cc.published = 1';
  77. $wheres[] = ' a.textonly = 0';
  78.  
  79. // Active
  80. $jnow =& JFactory::getDate();
  81. $now = $jnow->toMySQL();
  82. $nullDate = $db->getNullDate();
  83. $wheres[] = ' ( a.publish_up = '.$db->Quote($nullDate).' OR a.publish_up <= '.$db->Quote($now).' )';
  84. $wheres[] = ' ( a.publish_down = '.$db->Quote($nullDate).' OR a.publish_down >= '.$db->Quote($now).' )';
  85.  
  86. if (count($displayS) > 1) {
  87. JArrayHelper::toInteger($displayS);
  88. $displaySString = implode(',', $displayS);
  89. $wheres[] = ' s.id IN ( '.$displaySString.' ) ';
  90. } else if ((int)$displayS > 0) {
  91. $wheres[] = ' s.id IN ( '.$displayS.' ) ';
  92. }
  93.  
  94. $where = ( count( $wheres ) ? ' WHERE '. implode( ' AND ', $wheres ) : '' );
  95. $orderby = ' ORDER by a.hits DESC';
  96. $limit = ' LIMIT 0,'.(int)$number_item;
  97. $query = ' SELECT a.*, cc.id as categoryid, cc.title AS categorytitle, cc.alias as categoryalias, s.id as sectionid, s.title AS sectiontitle, cc.access as cataccess, cc.accessuserid as cataccessuserid '
  98. . ' FROM #__phocadownload AS a '
  99. . ' LEFT JOIN #__phocadownload_categories AS cc ON cc.id = a.catid '
  100. . ' LEFT JOIN #__phocadownload_sections AS s ON s.id = a.sectionid '
  101. . ' LEFT JOIN #__groups AS g ON g.id = a.access '
  102. . ' LEFT JOIN #__users AS u ON u.id = a.checked_out '
  103. . $where
  104. . ' GROUP by a.id'
  105. . $orderby
  106. . $limit;
  107.  
  108. $db->setQuery( $query );
  109. $items = $db->loadObjectList();
  110.  
  111. // DISPLAY
  112. $module_width_div = (int)$module_width - 10;
  113. $output = '<div class="phoca-dl-statistics-box-module">';
  114. $output .= '<table width="'.$module_width.'">';
  115.  
  116. if (!empty($items)) {
  117. $color = 0;
  118. $i = 1;
  119. foreach ($items as $value) {
  120.  
  121. // USER RIGHT - Access of categories (if file is included in some not accessed category) - - - - -
  122. // ACCESS is handled in SQL query, ACCESS USER ID is handled here (specific users)
  123. $rightDisplay = 0;
  124. if (!empty($value)) {
  125. $rightDisplay = PhocaDownloadHelper::getUserRight('accessuserid', $value->cataccessuserid, $value->cataccess, $user->get('aid', 0), $user->get('id', 0), 0);
  126. }
  127. // - - - - - - - - - - - - - - - - - - - - - -
  128.  
  129. if ($rightDisplay == 1) {
  130.  
  131.  
  132. $colors = array('#FFE6BF', '#FFECBF', '#FFF2BF', '#FFF9BF', '#FFFFBF', '#F2FFBF', '#E6FFBF', '#CCFFBF', '#BFFFBF', '#BFFFE4', '#BFFFFF', '#BFE4FF', '#BFCFFF', '#C8C8FF', '#D5BFFF', '#DABFFF', '#EABFFF', '#FFBFFF', '#FFBFEF', '#FFBFDC', '#FFBFBF', '#FFCCBF', '#FFD9BF', '#FFDFBF');
  133.  
  134. // if ((int)$maxHit[0]->maxhit == 0) {
  135. // $per = 0;
  136. // } else {
  137. // $per = round((int)$value->hits / (int)$maxHit[0]->maxhit * (int)$module_width);
  138. // }
  139.  
  140. // Only text (description - no file)
  141. if ($value->textonly == 0) {
  142.  
  143. $link = JRoute::_(PhocaDownloadHelperRoute::getCategoryRoute($value->categoryid, $value->categoryalias, $value->sectionid));
  144.  
  145. $output .= '<tr>';
  146. $output .= '<td align="right"><span style="font-size:'.$font_size.'">'. $i .'. </span></td>';
  147. $output .= '<td>';
  148. $output .= '<div style="background:'.$colors[$color].' url(\''. JURI::base(true).'/components/com_phocadownload/assets/images/white-space.png'.'\') '.$per.'px 0px no-repeat;width:'.$module_width_div.'px;padding:5px 5px;margin:5px 0px;font-size:'.$font_size.'px">';
  149. //echo '<small style="color:#666666">['. $value->id .']</small>';
  150.  
  151. if ((int)$display_title == 1) {
  152. $output .= '<strong style="color:#666666;"><a href="'.$link.'">'.$value->title .'</a></strong>';
  153. }
  154.  
  155. if ((int)$display_filename == 1) {
  156. if ((int)$display_title == 1) {
  157. $output .= ' - ';
  158. }
  159.  
  160.  
  161. $output .= '<em><a href="'.$link.'">'. $value->filename .'</a></em>';
  162. }
  163.  
  164. if ((int)$display_cat_sec == 1) {
  165. $output .= ' <small style="color:#666666">('. $value->sectiontitle .'/'. $value->categorytitle .')</small>';
  166. }
  167. $output .= '</div>';
  168. $output .= '</td>';
  169.  
  170. if ((int)$display_downloads == 1) {
  171. $output .= '<td align="center">'. $value->hits .'</td>';
  172. }
  173. $output .= '</tr>';
  174.  
  175. $color++;
  176. $i++;
  177. if ($color > 23) {
  178. $color = 0;
  179. }
  180. }
  181. }
  182. }
  183. }
  184.  
  185. $output .= '</table></div>';
  186.  
  187. require(JModuleHelper::getLayoutPath('mod_phocadownload_statistics'));
  188. ?>
YaQzi
Linia 95 :
  1. $orderby = ' ORDER by a.hits DESC';

chyba sam wiesz co z tym zrobić smile.gif
dawidryba
Jak napisałem, znam nie pełne podstawy php;/ Mogłbyś mi powiedzieć co i jak? Byłbym wdzięczny.
YaQzi
tu nie idzie o PHP tylko o MySQL

linia 63:
  1. . ' FROM #__phocadownload AS a '


tu ustawiasz alias na tabelę phocadownload jako 'a'



linia 95:
  1. $orderby = ' ORDER by a.hits DESC';


tu ustawiasz sortowanie wg kolumny 'hits' malejąco. Podmień sobie hits na którą tam kolumnę chcesz, pewnie 'id' się zwie i już.
dawidryba
O ja... tylko coś zmienić i chodzi! Jesteś wielki. Dziękuje:P

------------------------ TEMAT DO ZAMKNIĘCIA -----------------------------
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.