繁体   English   中英

如此具体,将艺术家的图像添加到joomla组件的最新歌曲的表格视图中

[英]So specific, adding a image of the artist to the table view of recent songs in a joomla component

我希望在观看最近的歌曲时可以使用歌手(歌手)的图像。 这是我想您在回答时可能需要的php文件和数据库表:(如果有人能这么快地教我如何使用查询命令在表的交叉使用中选择这样的数据,我会很高兴,只是表格的一行。如果没有,请更改代码,以便查看艺术家图片)

这是助手PHP代码

<?php

// no direct access
defined('_JEXEC') or die('Restricted access');

class modMusColRecentlyAddedSongsHelper
{


function getSongs(&$params)
{
    global $mainframe;
    $_db    = & JFactory::getDBO();
    $model      = modMusColRecentlyAddedSongsHelper::getModel();

        $limit = $params->get( 'n_songs', 5 );

        if($params->get( 'artist_id' )) $where_clause[] = " s.artist_id = " . $params->get( 'artist_id' ) . " " ;

        if ($params->get( 'genre_id' )) {
            $genre_id = $params->get( 'genre_id' );
            $model->getDescendantsId($genre_id); 
            $descendants = $model->descendantsId;
            $descendants[] = $genre_id ;
            $genre_clause = ' ( s.genre_id = ' . implode(' OR s.genre_id = ',$descendants) . ' ) ';
            $where_clause[] = $genre_clause;
        }


            //$where_clause[] = ' ra.type = "song" ';
            $where_clause = (count($where_clause) ? ' WHERE '.implode(' AND ', $where_clause) : '');

            $query =    ' SELECT s.*, ar.artist_name,al.name as album_name, AVG(ra.points) as points FROM #__muscol_songs as s '.
                        ' LEFT JOIN #__muscol_albums as al ON al.id = s.album_id '.
                        ' LEFT JOIN #__muscol_artists as ar ON ar.id = s.artist_id '.
                        ' LEFT JOIN #__muscol_ratings as ra ON ra.album_id = s.id AND ra.type = "song" '.
                        $where_clause .
                        ' GROUP BY s.id ' .
                        ' ORDER BY s.added DESC '.
                        ' LIMIT '. $limit;

                        //echo $query;die;


        $_db->setQuery( $query );
        $recent_songs = $_db->loadObjectList();

        //print_r($query);die;

        return $recent_songs;

}

function getModel()
{
    if (!class_exists( 'ArtistsModelSearch' ))
    {
        // Build the path to the model based upon a supplied base path
        $path = JPATH_SITE.DS.'components'.DS.'com_muscol'.DS.'models'.DS.'search.php';
        $false = false;

        // If the model file exists include it and try to instantiate the object
        if (file_exists( $path )) {
            require_once( $path );
            if (!class_exists( 'ArtistsModelSearch' )) {
                JError::raiseWarning( 0, 'Model class ArtistsModelSearch not found in file.' );
                return $false;
            }
        } else {
            JError::raiseWarning( 0, 'Model ArtistsModelSearch not supported. File not found.' );
            return $false;
        }
    }

    $model = new ArtistsModelSearch();

    return $model;
}

}

这是default.php代码

<?php // no direct access
defined('_JEXEC') or die('Restricted access'); ?>
<?php
if($params->get( 'Itemid' )) $itemid = "&Itemid=".$params->get( 'Itemid' );
   else $itemid = "";
   $document =& JFactory::getDocument();
   $document->addStyleSheet(JURI::base(true).'/modules/mod_muscol_recently_added_songs/tmpl/recently_added_songs.css');
?>

 <div class='recently_added_songs'>
 <table border='0' cellpadding='0' cellspacing='0' width="100%">
 <thead>
 <tr>
  <th> <?php echo JText::_( 'آهنگ' ); ?> </th>
   <? if($params->get('show_album')){ ?><th> <?php echo JText::_( 'آلبوم' ); ?> </th><? } ?>
  <? if($params->get('show_artist')){ ?><th> <?php echo JText::_( 'خواننده' ); ?> </th><? } ?>
  <? if($params->get('show_rating')){ ?><th> <?php echo JText::_( 'امتياز' ); ?> </th><? } ?>
</tr>
</thead>
<?php
 $n = 0;
  for ($j=0, $m=count( $songs ); $j < $m; $j++) {
 $song = $songs[$j];
$link= JRoute::_( 'index.php?option=com_muscol&view=song&id='. $song->id . $itemid);
$link_album= JRoute::_( 'index.php?option=com_muscol&view=album&id='. $song->album_id . $itemid);
$link_artist= JRoute::_( 'index.php?option=com_muscol&view=artist&id='. $song->artist_id . $itemid);

//$image = MusColHelper::createThumbnail($album->image, $album->name, $params->get('default_width'), $image_attr);
?>
 <tr class="tr_recent_songs <?php echo "row$n"; ?>">
  <td><a href="<?php echo $link; ?>"><?php echo $song->name; ?></a></td>
  <? if($params->get('show_album')){ ?><td><a href="<?php echo $link_album; ?>"><?php echo $song->album_name; ?></a></td><? } ?>
  <? if($params->get('show_artist')){ ?><td><a href="<?php echo $link_artist; ?>"><?php echo $song->artist_name; ?></a></td><? } ?>
  <? if($params->get('show_rating')){ ?><td><?php echo MusColHelper::show_stars($song->points,false,false,false,true);?></td><? } ?>
</tr>
<?php
$n = 1 - $n ;
}
?>
 </table>
</div>

数据库中的歌曲表(该表的名称为歌曲)

id  album_id  num  disc_num  length  name  lyrics  artist_id  composer_id  filename  extension  review  songwriters  chords  genre_id  hits  buy_link  video  position  downloaded  user_id

在数据库表中的艺术家 (画家油画应该从图片列读取)

id artist_name  image  review  letter  class_name  related  keywords  added  hits  country  picture  user_id  metakeywords  metadescription  city  years_active  url  genre_id

您已经在帮助器中查询了正确的表,因此-只要您显示的代码已经起作用-所有您需要的是返回额外的字段:

  $query =    ' SELECT s.*, ar.artist_name,al.name

  $query =    ' SELECT s.*, ar.artist_name,ar.image as artistimage, al.name

然后在视图中:

<?php echo $song->artist_name; ?>

<?php echo  $song->artist_name;
echo sprintf('<img src="%s" class="artistpic" />',$song->artistimage);
 ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM