PDA

Zobacz pełną wersję : Sobi2 - jak pobrać dane wpisu?



orrafal
13-02-2011, 18:20
Witam,
Potrzebuję dostosować moduł LATEST SOBI2.
Chciałbym wyciągnąć dane dla trzech Zmiennych:
- główna kategoria
- nazwa firmy (pole ustalone w menadżerze pól)
- data początku wpisu (pole określone w menadżerze pól)

I żeby wpisywały się w tym module.
Czy ktoś ma jakiś pomysł?

EkleErs
13-02-2011, 22:07
W
/modules/mod_sobi2latest/mod_sobi2latest.php
zamień

$query = "SELECT `title`, `itemid`, `icon`, `image` FROM `#__sobi2_item` WHERE `published` = 1 AND (`publish_down` > '{$now}' OR `publish_down` = '{$config->nullDate}') ORDER BY `publish_up` DESC LIMIT {$limit}";na


$query = "SELECT ite.publish_up AS data_dod, ite.title , ite.itemid , ite.image , cat_name.name AS kat_name, fild.data_txt as fild_text
FROM #__sobi2_item AS ite
LEFT JOIN #__sobi2_cat_items_relations AS cat_rel ON ite.itemid = cat_rel.itemid
LEFT JOIN #__sobi2_categories AS cat_name ON cat_rel.catid = cat_name.catid
LEFT JOIN #__sobi2_fields_data AS fild ON ite.itemid = fild.itemid
WHERE ite.published = 1
AND (
ite.publish_down > now()
OR ite.publish_down = '0000-00-00 00:00:00'
)
AND cat_rel.ordering = 1
AND fild.fieldid = 1
ORDER BY ite.publish_up DESC LIMIT {$limit}";i wyswietlaj dane gdzies za
foreach($s_results as $s_result) {masz 3 nowe zmienne


$s_result->data_dod //Data dodania nie trzeba pobierac z "menadżerze pól"
$s_result->kat_name //Nazwa głównej kategorii
$s_result->fild_text /* to co masz wpisane w "menadżerze pól" o id = 1
jak chcesz z innego to podaj wlasciwe id do "nazwa firmy" w AND fild.`fieldid` = 1????
*///edit poprawione
//edit2 jos_sobi_item

orrafal
13-02-2011, 22:48
Dzięki za szybką odpowedź ale nie działa. Nic się nie wyświetla w danym module, jak by nic sie nie pobrało z bazy danych do wyświetlenia. Strona chodzi ale w module nic się nie pokazuje.

EkleErs
13-02-2011, 22:51
a pokaz jak dodales wyslij gdzies ten plik
to na co masz zamienic brakuje na poczatkju $query ="
//edit
poprawilem sprawdz teraz

orrafal
13-02-2011, 23:37
Przepraszam, wkradł się mały błąd, To co napisałes to działa bardzo dobrze.
To ja źle wkleiłem zabrakło nawiasu na końcu QUERY}
Ostatnia prośba jak zmienić format daty, bo wyświetla mi się rok-miesiąc-dzień godziny minuty sekundy a ja chciałbym tylko rok-miesiąc-dzień.

To co na grubo zaznaczone to Twój kod. Dzięki


<?php
/**
* @version $Id: mod_sobi2latest.php 4847 2009-01-23 17:42:35Z Sigrid Suski $
* @package: Sigsiu Online Business Index 2 Latest Module
* ================================================== =
* @author
* Name: Sigrid & Radek Suski, Sigsiu.NET
* Email: sobi@sigsiu.net
* Url: http://www.sigsiu.net
* ================================================== =
* @copyright Copyright (C) 2007-2009 Sigsiu.NET (http://www.sigsiu.net). All rights reserved.
* @license see http://www.gnu.org/copyleft/gpl.html GNU/GPL.
* SOBI2 Latest Module is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation.
*/
(defined( '_VALID_MOS' ) || defined( '_JEXEC' ) ) || ( trigger_error( 'Restricted access', E_USER_ERROR ) && exit() );
defined( "DS" ) || define( "DS",DIRECTORY_SEPARATOR);
$add = defined( 'JPATH_SITE' ) ? DS.'mod_sobi2latest' : null;
defined( '_SOBI_CMSROOT' ) || define( '_SOBI_CMSROOT', str_replace( DS.'modules'.$add, null, dirname( __FILE__ ) ) );
class_exists( 'sobi2Config' ) || require_once( _SOBI_CMSROOT.DS.'components'.DS.'com_sobi2'.DS.'c onfig.class.php' );
//error_reporting(E_ALL);
//ini_set("display_errors","on");
//Get the parameters
$class = $params->get('moduleclass_sfx');
$limit = $params->get('count',5);
$table = $params->get('moduletable', 0); //only J1.0
$entryicon = $params->get('entryicon',0);
$entryimage = $params->get('entryimage',0);
$showTitle = $params->get('title',1);
$maxlength = $params->get('item_length', 50);
$direction = $params->get('direction', 1);
$categorydepend = $params->get('categorydepend', 0);
if(!$limit || $limit < 1)
$limit = 5;
$config =& sobi2Config::getInstance();
$database =& $config->getDb();
$S_Itemid = $config->sobi2Itemid;
$catId = sobi2Config::request( $_REQUEST,'catid',0 );
$now = $config->getTimeAndDate();
if (($catId > 1) && ($categorydepend == 1)) {
$query = "SELECT `title`, `itemid`, `icon`, `image` FROM `#__sobi2_item` WHERE (itemid IN (SELECT itemid FROM #__sobi2_cat_items_relations WHERE catid = {$catId})) AND `published` = 1 AND (`publish_down` > '{$now}' OR `publish_down` = '{$config->nullDate}') ORDER BY `publish_up` DESC LIMIT {$limit}";
}
else {
$query = "SELECT ite.publish_up AS data_dod, ite.title , ite.itemid , ite.image , cat_name.name AS cat_name, fild.data_txt as fild_text
FROM jos_sobi2_item AS ite
LEFT JOIN #__sobi2_cat_items_relations AS cat_rel ON ite.itemid = cat_rel.itemid
LEFT JOIN #__sobi2_categories AS cat_name ON cat_rel.catid = cat_name.catid
LEFT JOIN #__sobi2_fields_data AS fild ON ite.itemid = fild.itemid
WHERE ite.published = 1
AND (
ite.publish_down > now()
OR ite.publish_down = '0000-00-00 00:00:00'
)
AND cat_rel.ordering = 1
AND fild.fieldid = 16
ORDER BY ite.publish_up DESC LIMIT {$limit}";
}
$database->setQuery( $query );
$s_results = $database->loadObjectList();
$iso = explode( '=', _ISO );
$encoding = strtoupper($iso[1]);
echo "\n";
echo "<!-- Start of SOBI2 Latest Entries Module -->\n";
if( !( defined( "_JEXEC" ) ) ) {
if ($table)
echo "<table cellpadding=\"0\" cellspacing=\"0\" class=\"moduletable{$class}\"><tr><td>\n";
}
if ($direction == 1)
echo "<ul class=\"sobi2latest{$class}\">\n";
if(count($s_results)) {
foreach($s_results as $s_result) {

$url = "index.php?option=com_sobi2&amp;sobi2Task=sobi2Details&amp; sobi2Id={$s_result->itemid}&amp;Itemid={$S_Itemid}";
$url = sobi2Config::sef($url);
$myTitle = $config->getSobiStr($s_result->title);
$myFullTitle = $myTitle;

$icon = null;
if($entryicon) {
if($s_result->icon && file_exists("{$config->absolutePath}/images/com_sobi2/clients/{$s_result->icon}")) {
$icon = "<a href=\"{$url}\" title=\"{$myFullTitle}\"><img style=\"border-style:none;\" src=\"{$config->liveSite}/images/com_sobi2/clients/{$s_result->icon}\" title=\"{$myFullTitle}\" alt=\"{$myFullTitle}\"/></a>&nbsp;";
}
}
$image = null;
if($entryimage) {
if($s_result->image && file_exists("{$config->absolutePath}/images/com_sobi2/clients/{$s_result->image}")) {
$image = "<a href=\"{$url}\" title=\"{$myFullTitle}\"><img style=\"border-style:none;\" src=\"{$config->liveSite}/images/com_sobi2/clients/{$s_result->image}\" title=\"{$myFullTitle}\" alt=\"{$myFullTitle}\"/></a>&nbsp;";
}
}
$e = null;
if($showTitle) {
if ((function_exists("mb_strlen")) && (substr($encoding,0,3) == "UTF")) {
$len = mb_strlen($myTitle, $encoding);
}
else
$len = strlen($myTitle);

if ($len > $maxlength) {
if ((function_exists("mb_substr")) && (substr($encoding,0,3) == "UTF")) {
$myTitle = mb_substr($myTitle, 0, $maxlength, $encoding);
}
else
$myTitle = substr($myTitle, 0, $maxlength);

$myTitle = $myTitle."...";
}
$e = "<a href=\"{$url}\" title=\"{$myFullTitle}\">{$myTitle}</a>";
}
if ($icon || $image || $e) {
if ($direction == 1)
echo "<li class=\"sobi2latest{$class}\"> {$s_result->cat_name}{$s_result->fild_text}{$icon}{$image}{$e}{$s_result->data_dod}</li>\n";
else {
echo "<div class=\"sobi2latest{$class}\" style=\"float:left; margin: 5px;\">{$icon}{$image}{$e}</div>\n";
}
}
}
}
if ($direction == 1)
echo "</ul>\n";
else
echo "<div style=\"clear:both;\"></div>\n";

if( !( defined( "_JEXEC" ) ) ) {
if ($table)
echo "</td></tr></table>\n";
}
echo "<!--End of SOBI2 Latest Entries Module -->\n";
?>

EkleErs
14-02-2011, 12:36
echo JHTML::_('date', $s_result->data_dod, JText::_('%Y %d %B')) ;
+
Date_format (http://docs.joomla.org/How_do_you_change_the_date_format%3F)
+
zamień
FROM jos_sobi2_item AS ite

na FROM #__sobi2_item AS ite

orrafal
15-02-2011, 11:09
Dzięki wielkie, wszystko działa prawie dobrze poza jedną rzeczą.
Gdy dodam dwa wpisy do różnych kategorii (książki, motoryzacja) - wpisy pojawiają się w tym module
Gdy dodam dwa wpisy do tej samej kategorii (książki) - pojawia się tylko ten drugi. Nie wiem na czym polega błąd. Przesyłam kod pliku Latest. Wszystko jest wypisywane w tabeli class =tablelist.

Za wszelką pomoc dziękuje z góry


<?php
/**
* @version $Id: mod_sobi2latest.php 4847 2009-01-23 17:42:35Z Sigrid Suski $
* @package: Sigsiu Online Business Index 2 Latest Module
* ================================================== =
* @author
* Name: Sigrid & Radek Suski, Sigsiu.NET
* Email: sobi@sigsiu.net
* Url: http://www.sigsiu.net
* ================================================== =
* @copyright Copyright (C) 2007-2009 Sigsiu.NET (http://www.sigsiu.net). All rights reserved.
* @license see http://www.gnu.org/copyleft/gpl.html GNU/GPL.
* SOBI2 Latest Module is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation.
*/

(defined( '_VALID_MOS' ) || defined( '_JEXEC' ) ) || ( trigger_error( 'Restricted access', E_USER_ERROR ) && exit() );

defined( "DS" ) || define( "DS",DIRECTORY_SEPARATOR);

$add = defined( 'JPATH_SITE' ) ? DS.'mod_sobi2latest' : null;
defined( '_SOBI_CMSROOT' ) || define( '_SOBI_CMSROOT', str_replace( DS.'modules'.$add, null, dirname( __FILE__ ) ) );
class_exists( 'sobi2Config' ) || require_once( _SOBI_CMSROOT.DS.'components'.DS.'com_sobi2'.DS.'c onfig.class.php' );

//error_reporting(E_ALL);
//ini_set("display_errors","on");

//Get the parameters
$class = $params->get('moduleclass_sfx');
$limit = $params->get('count',5);
$table = $params->get('moduletable', 0); //only J1.0
$entryicon = $params->get('entryicon',0);
$entryimage = $params->get('entryimage',0);
$showTitle = $params->get('title',1);
$maxlength = $params->get('item_length', 50);
$direction = $params->get('direction', 1);
$categorydepend = $params->get('categorydepend', 0);
if(!$limit || $limit < 1)
$limit = 5;

$config =& sobi2Config::getInstance();
$database =& $config->getDb();
$S_Itemid = $config->sobi2Itemid;
$catId = sobi2Config::request( $_REQUEST,'catid',0 );

$now = $config->getTimeAndDate();

if (($catId > 1) && ($categorydepend == 1)) {
$query = "SELECT `title`, `itemid`, `icon`, `image` FROM `#__sobi2_item` WHERE (itemid IN (SELECT itemid FROM #__sobi2_cat_items_relations WHERE catid = {$catId})) AND `published` = 1 AND (`publish_down` > '{$now}' OR `publish_down` = '{$config->nullDate}') ORDER BY `publish_up` DESC LIMIT {$limit}";
}
else {
$query = "SELECT ite.publish_up AS data_dod, ite.title , ite.itemid , ite.image , cat_name.name AS cat_name, fild.data_txt as fild_text
FROM #__sobi2_item AS ite
LEFT JOIN #__sobi2_cat_items_relations AS cat_rel ON ite.itemid = cat_rel.itemid
LEFT JOIN #__sobi2_categories AS cat_name ON cat_rel.catid = cat_name.catid
LEFT JOIN #__sobi2_fields_data AS fild ON ite.itemid = fild.itemid
WHERE ite.published = 1
AND (
ite.publish_down > now()
OR ite.publish_down = '0000-00-00 00:00:00'
)
AND cat_rel.ordering = 1
AND fild.fieldid = 16
ORDER BY ite.publish_up DESC LIMIT {$limit}";

}

$database->setQuery( $query );
$s_results = $database->loadObjectList();

$iso = explode( '=', _ISO );
$encoding = strtoupper($iso[1]);

echo "\n";
echo "<!-- Start of SOBI2 Latest Entries Module -->\n";
if( !( defined( "_JEXEC" ) ) ) {
if ($table)
echo "<table cellpadding=\"0\" cellspacing=\"0\" class=\"moduletable{$class}\"><tr><td>\n";
}
if ($direction == 1)
echo "<div class=\"dane\">\n";
echo "<table class=\"tablelist\">\n";
echo "<tr>\n";
if(count($s_results)) {
foreach($s_results as $s_result) {


$url = "index.php?option=com_sobi2&amp;sobi2Task=sobi2Details&amp; sobi2Id={$s_result->itemid}&amp;Itemid={$S_Itemid}";
$url = sobi2Config::sef($url);

$myTitle = $config->getSobiStr($s_result->title);
$myFullTitle = $myTitle;

$icon = null;
if($entryicon) {
if($s_result->icon && file_exists("{$config->absolutePath}/images/com_sobi2/clients/{$s_result->icon}")) {
$icon = "<a href=\"{$url}\" title=\"{$myFullTitle}\"><img style=\"border-style:none;\" src=\"{$config->liveSite}/images/com_sobi2/clients/{$s_result->icon}\" title=\"{$myFullTitle}\" alt=\"{$myFullTitle}\"/></a>&nbsp;";
}
}
$image = null;
if($entryimage) {
if($s_result->image && file_exists("{$config->absolutePath}/images/com_sobi2/clients/{$s_result->image}")) {
$image = "<a href=\"{$url}\" title=\"{$myFullTitle}\"><img style=\"border-style:none;\" src=\"{$config->liveSite}/images/com_sobi2/clients/{$s_result->image}\" title=\"{$myFullTitle}\" alt=\"{$myFullTitle}\"/></a>&nbsp;";
}
}
$e = null;
if($showTitle) {
if ((function_exists("mb_strlen")) && (substr($encoding,0,3) == "UTF")) {
$len = mb_strlen($myTitle, $encoding);
}
else
$len = strlen($myTitle);

if ($len > $maxlength) {
if ((function_exists("mb_substr")) && (substr($encoding,0,3) == "UTF")) {
$myTitle = mb_substr($myTitle, 0, $maxlength, $encoding);
}
else
$myTitle = substr($myTitle, 0, $maxlength);

$myTitle = $myTitle."...";
}
$e = "<a href=\"{$url}\" title=\"{$myFullTitle}\">{$myTitle}</a>";
}
if ($icon || $image || $e) {
if ($direction == 1)
echo "<td class=\"tablecategory\">{$s_result->cat_name}</td>\n"."<td class=\"tablemark\">{$s_result->fild_text}</td>\n"."<td class=\"tabletitle\">{$icon}{$image}{$e}</td>\n"."<td class=\"tabledate\">".JHTML::_('date', $s_result->data_dod, JText::_('%Y %d %B'))."</td>\n"."</tr>\n";
else {
echo "<div class=\"sobi2latest{$class}\" style=\"float:left; margin: 5px;\">{$icon}{$image}{$e}</div>\n";
}
}
}
}

if ($direction == 1)
echo "</table>\n"."</div>\n";
else
echo "<div style=\"clear:both;\"></div>\n";

if( !( defined( "_JEXEC" ) ) ) {
if ($table)
echo "</td></tr></table>\n";
}
echo "<!--End of SOBI2 Latest Entries Module -->\n";
?>

EkleErs
15-02-2011, 19:11
Zobacz to

$query = "SELECT ite.publish_up AS data_dod, ite.title, ite.itemid, ite.image, cat_name.name AS kat_name, fild.data_txt AS fild_text\n"
. "FROM #__sobi2_item AS ite\n"
. "LEFT JOIN #__sobi2_cat_items_relations AS cat_rel ON ite.itemid = cat_rel.itemid\n"
. "LEFT JOIN #__sobi2_categories AS cat_name ON cat_rel.catid = cat_name.catid\n"
. "INNER JOIN #__sobi2_cats_relations AS cats_name ON cat_rel.catid = cats_name.catid\n"
. "LEFT JOIN #__sobi2_fields_data AS fild ON ite.itemid = fild.itemid\n"
. "WHERE ite.published =1\n"
. "AND fild.fieldid =16\n"
. "AND (ite.publish_down > now()\n"
. "OR ite.publish_down = '0000-00-00 00:00:00')\n"
. "GROUP BY ite.itemid DESC\n"
. "LIMIT {$limit}";