Create Module for Joomla!1.5 - Investigation on JS Match Result

62 篇文章 0 订阅
44 篇文章 0 订阅

The XML of JoomSport Match Result is:


<?xml version="1.0" encoding="utf-8"?>
<extension
	type="module"
	version="1.6.0"
	client="site"
	method="upgrade">
	<name>JoomSport match results</name>
	<author>BearDev</author>
	<creationDate>April 2011</creationDate>
	<copyright>Copyright (C)2010 BearDev. All rights reserved.</copyright>
	<license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
	<authorEmail>beardev@beardev.com</authorEmail>
	<authorUrl>www.beardev.com</authorUrl>
	<version>1.6</version>
	<description>Match Results</description>
	<languages folder="language">
		<language tag="en-GB">en-GB/en-GB.mod_js_results.ini</language>
		<language tag="en-GB">en-GB/en-GB.mod_js_results.sys.ini</language>
	</languages>
	<files>
		<filename module="mod_js_results">mod_js_results.php</filename>
		<filename module="mod_js_results">helper.php</filename>
		<filename module="mod_js_results">tmpl/default.php</filename>
		<filename module="mod_js_results">css/mod_js_results.css</filename>
		<folder>language</folder>
	</files>
	<config>
		<fields name="params">
		<fieldset name="basic" addfieldpath="/administrator/components/com_joomsport/fields">
				<field name="season_id" type="modseas" default="0" label="Select Season" description="Season" />
				<field name="team_id" type="modteam" default="0" label="Set team" description="If you set wrong team id module will display nothing" />
			<field name="match_count" type="text" default="5" label="Match count" description="Match count" />
			<field name="moduleclass_sfx" type="text" default="" label="COM_MODULES_FIELD_MODULECLASS_SFX_LABEL" description="COM_MODULES_FIELD_MODULECLASS_SFX_DESC" />
<field name="embl_is" type="radio" default="0" label="Emblems" description="Display emblems?">
				<option value="0">No</option>
				<option value="1">Yes</option>
			</field>
			<field name="customitemid" type="text" default="0" label="Set Itemid" description="Set custom Itemid, if set 0 used current Itemid" />
		</fieldset>
		</fields>
	</config>
	<params addpath="/administrator/components/com_joomsport/elements">
			<param name="season_id" type="modseas" default="0" label="Select Season" description="Season" />
			<param name="team_id" type="modteam" default="0" label="Set team" description="If you set wrong team id module will display nothing" />
		<param name="match_count" type="text" default="5" label="Match count" description="Match count" />
		<param name="moduleclass_sfx" type="text" default="" label="Module Class Suffix" description="PARAMMODULECLASSSUFFIX" />

		<param name="customitemid" type="text" default="0" label="Set Itemid" description="Set custom Itemid, if set 0 used current Itemid" />
	</params>

</extension>


According to the chapter 5 of <Learning Joomla!1.5 Extension Development> and <Mastering Joomla!1.5 Extension and Framework Development>, there is no field node in the description XML about parameter. It should be applied in Joomla!1.6, and that node here is for compatibility.


The parameter values are stored in table jos_modules:

module-para


So, now we do is to remove the useless para from both XML file and database.


Since this topic is so simple, I just directly put on my final code, with a little bit explanation.


The module core PHP: /modules/mod_js_results/mod_js_results.php:


<?php

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

// Include the syndicate functions only once
require_once (dirname(__FILE__).DS.'helper.php');

$tourMatches = modBlResHelper::getResults($params);

require(JModuleHelper::getLayoutPath('mod_js_results'));

It is the main entrance of the module, when this module be loaded, this file run firstly, and it generally only has control logic, not logic of handling data, that is helper's job. And its the linkage between the helper class and the layout PHP script, they can not pass data directly without this linkage. So my /modules/mod_js_results/helper.php is:

<?php

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

class modBlResHelper
{
	function &getResults(&$params)
	{
		// global var, used later for grouping
		$current_season_id = $params->get( 'season_id' );
		$match_count = $params->get( 'match_count' );

		//get all the tourments
		$db =& JFactory::getDBO();
		$query = "SELECT id, name as tname, t_type FROM #__bl_tournament WHERE published ='1'";
		$db->setQuery($query);

		$tours = $db->loadObjectList();

		foreach($tours as $t)
		{
			//get current seasons of all these tourments
			$query = "SELECT MAX(s_id) from #__bl_seasons WHERE published ='1' AND t_id = ".$t->id;
			$db->setQuery($query);
			$sea_id = $db->loadResult();
			if(!empty($sea_id))
			{
				$t->sea_id = $sea_id;
			}
			else
			{
				// there may be no published current season for the tourment yet
				$t->sea_id = '0';
			}
		}

		$matchResultsByTour = array();

		foreach($tours as $tx)
		{
			if($tx->sea_id != '0')
			{	//if this tourment has current season

				if($tx->t_type == '1')
				{
					//$current_season_id = $tx->sea_id;
					//聯賽盃, should classify the matches into different groups
					$query = "SELECT id, group_name FROM #__bl_groups WHERE s_id = ".$tx->sea_id;
					$db->setQuery($query);
					$groups = $db->loadObjectList();

					$query = "SELECT id FROM #__bl_matchday WHERE s_id = ".$tx->sea_id;
					$db->setQuery($query);
					$md_ids = $db->loadResultArray();

					if(!empty($md_ids))
					{
						$mdid_str = implode(",", $md_ids);

						foreach($groups as $g)
						{
							// get the 4 latest matches infomation
							$query = "SELECT STR_TO_DATE( m.m_date, '%Y-%m-%d' ) AS d, m.score1, m.score2, m.bonus1, m.bonus2, t1.t_name AS name1, t2.t_name AS name2 ".
										"FROM #__bl_match AS m, #__bl_grteams AS gt, #__bl_teams AS t1, #__bl_teams AS t2
										WHERE m.m_played = '1' AND m.team1_id = gt.t_id AND m.team1_id=t1.id AND m.team2_id = t2.id AND gt.g_id = ". $g->id ."  AND m.m_id IN ( ". $mdid_str ." )".
										" ORDER BY d DESC LIMIT 0 , ".$match_count;
							$db->setQuery($query);
							$matches = $db->loadObjectList();
							if(!empty($matches))
							{
								$gr_matches['name'] = $g->group_name . $tx->tname;	// combine group name and tourment name
								$gr_matches['matchres'] = $matches;

								$matchResultsByTour[] = $gr_matches;
							}
						}

					}

				}
				else
				{
					//淘汰盃主席盃碟盾
					$query = "SELECT id FROM #__bl_matchday WHERE s_id = ".$tx->sea_id;
					$db->setQuery($query);
					$md_ids = $db->loadResultArray();

					if(!empty($md_ids))
					{
						$mdid_str = implode(",", $md_ids);
						$query = "SELECT STR_TO_DATE( m.m_date, '%Y-%m-%d' ) AS d, m.score1, m.score2, m.bonus1, m.bonus2, " .
								"t1.t_name AS name1, t2.t_name AS name2, g1.group_name AS gname1, g2.group_name AS gname2 ".
								"FROM #__bl_match AS m, #__bl_teams AS t1, #__bl_teams AS t2, #__bl_grteams AS gt1, #__bl_groups AS g1, #__bl_groups AS g2, #__bl_grteams AS gt2 ".
								"WHERE m.m_played='1' AND m.team1_id=t1.id AND m.team2_id = t2.id ".
								"AND m.team1_id=gt1.t_id AND g1.id=gt1.g_id AND g1.s_id = ".$current_season_id.
								" AND m.team2_id=gt2.t_id AND g2.id=gt2.g_id AND g2.s_id = ".$current_season_id.
								" AND m.m_id IN (". $mdid_str .") ORDER BY d DESC LIMIT 0 , ".$match_count;
						$db->setQuery($query);
						$matches = $db->loadObjectList();
						if(!empty($matches))
						{
							$gr_matches['name'] = $tx->tname;
							$gr_matches['matchres'] = $matches;

							$matchResultsByTour[] = $gr_matches;
						}
					}
				}

			}
		}
		//dump($matchResultsByTour, 'matchesarray');

		return $matchResultsByTour;
	}
}

and the default layout file, /modules/mod_js_results/tmpl/default.phpdefault.php:


<?php // no direct access
defined('_JEXEC') or die('Restricted access');
$document =& JFactory::getDocument();
$document->addStyleSheet(JURI::root() . 'modules/mod_js_results/css/mod_js_results.css');
$cItemId = $params->get('customitemid');
global $Itemid;
if(!$cItemId){
	$cItemId = $Itemid;
}
$old_date = '';

?>

<table align="center" cellpadding="3" border="0" class="jsm_restable">
<?php
if(count($tourMatches))
{

?>

<tr>

	<td>
		<marquee direction="left" id="cool" scrollamount="3" onMouseOver="cool.stop()" OnMouseOut="cool.start()">
		<?php
			foreach($tourMatches as $tou)
			{
				echo '<font color="#009">'.$tou['name'].'</font>  ';
				foreach($tou['matchres'] as $mat)
				{
					if($mat->gname1)
					{
						echo '('. mb_substr($mat->gname1, 0, 1, "UTF-8").')'.$mat->name1.' vs '
							.'('.mb_substr($mat->gname2, 0, 1, "UTF-8").')'.$mat->name2 . ' ' .$mat->score1 . ':' . $mat->score2.'   ';
					}
					else
					{
						echo $mat->name1.' vs '.$mat->name2 . ' ' .$mat->score1 . ':' . $mat->score2.'   ';
					}

				}
			}

		?>
		</marquee>
	<td>

</tr>
<?php
}
?>
</table>


Please note that the function to add style script to the front end page:


$document->addStyleSheet(JURI::root() . 'modules/mod_js_results/css/mod_js_results.css')

 

By the way, the HTML element marquee is used to create a rolling text content, but is may be a dated solution, because I found that if I include a span tag inside it, I would get error saying that HTML collection had no method start() or stop(). What it can do is limited.


And without specifying its width, it works fine now, in a small table.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值