Custom Module Joomla 3.9

By | January 2nd 2019 11:33:16 AM | viewed 475 times

create a folder with component name and prefix like:mod_onlinetraning

create mod_onlinetraning.xml in the location:mod_onlinetraning/ and add the following code

 <?xml version="1.0" encoding="utf-8"?>
<extension type="module" version="3.1.0" client="site" method="upgrade">
  <name>onlinetraning</name>

  <creationDate>17-12-2018</creationDate>
  <author>UKmodak</author>
  <authorEmail>uzzalmodak@yahoo.com</authorEmail>
  <authorUrl>www.ukmodak.com</authorUrl>
  <copyright>Copyright ukmodak 2018</copyright>
  <license>GPL V3 or later</license>
  <version>0.4</version>
  <description>onlinetraning </description>

  <files>
    <filename module="mod_onlinetraning">mod_onlinetraning.php</filename>
    <filename>index.html</filename>
    <filename>helper.php</filename>
    <filename>mod_onlinetraning.xml</filename>
    <filename>tmpl/default.php</filename>
    <filename>tmpl/index.html</filename>
    <filename>css/training.css</filename>
    
  </files>
  <params>
    <param name="moduleclass_sfx" type="text" default="" label="Module Class Suffix" description="PARAMMODULECLASSSUFFIX" />
    <param name="@spacer" type="spacer" default="" label="" description="" />
    <param name="albumcount" type="text" default="3" label="LABEL ALBUM COUNT" description="DESC ALBUM COUNT" />
  </params>
</extension>

create a file index.html in the location:mod_onlinetraning/ and add the following code

<html><body bgcolor="#FFFFFF"></body></html>

create a file mod_onlinetraning.php in the location:mod_onlinetraning/ which call helper class and add the following code

<?php
//no direct access
defined('_JEXEC') or die('Direct Access to this location is not allowed.');

// include the helper file

require_once(dirname(__FILE__).'/helper.php');
$document =& JFactory::getDocument();
$document->addStyleSheet(JURI::base() . 'modules/mod_onlinetraning/css/training.css');


// get a parameter from the module's configuration
$albumCount = $params->get('albumcount');

// get the items to display from the helper
$items = ModOnlinetraningHelper::getCourse($albumCount);

// include the template for display
require(JModuleHelper::getLayoutPath('mod_onlinetraning'));

create a file helper.php in the location:mod_onlinetraning/ which call helper class and add the following code

<?php
defined('_JEXEC') or die('Direct Access to this location is not allowed.');

class ModOnlinetraningHelper {
  /**
   * Returns a list of albums
   */
  public function getCourse($albumCount) {
  
    $db = JFactory::getDbo();
	$items =null;

    // get course data from jos_course
	
    //$query = "SELECT * FROM jos_cousre where course_status='online' ORDER BY ASC LIMIT 0," . $albumCount;
    //$query = "SELECT * FROM rwm_ukmpartandclient where course_status='online'";
    //$db->setQuery($query);
	

	$query = $db->getQuery(true);
	$query->select('*');
	$query->from($db->quoteName('#__ukmpartandclient'));
	//$query->where($db->quoteName('course_status')." = ".$db->quote('online'));
	$db->setQuery($query);
	
	if($db->loadAssocList()){
	   $items = $db->loadAssocList();   
	}

    return $items;
   }
}

create a file default.php in the location:mod_onlinetraning/tmpl/ which render html and add the following code


<?php defined('_JEXEC') or die('Restricted access'); // no direct access ?>
<table class="onlinetraning" cellspacing="0" cellpadding="0" >
    <tr>
        <td class="heading" width="65%" align="center">COURSE NAME</td>
        <td class="heading" width="5%" align="center">DURATION</td>
        <td class="heading" width="5%" align="center">PRICE</td>
        <td class="heading" width="10%" align="center">No. of Days</td>
        <td class="heading" width="15%" align="center">REGISTER</td>
    </tr>
<?php foreach ($items as $item) { ?>
 <tr>
     <td align="left">
       <?php echo $item['course_name']; ?>
    </td>
    <td align="center">
       <?php echo $item['duration']; ?>
    </td>

    <td align="center">
       <?php echo $item['price']; ?>
    </td>

    <td align="center">
       <?php echo $item['noofdays']; ?>
    </td>

     <td align="center">
       <a href="<?php $base_url;?>index.php?option=com_contact&view=contact&id=1&Itemid=48&cid=<?php echo $item['course_id']; ?>">enroll now</a>
    </td>
 </tr>
<?php } ?>
</table>

create a file index.html in the location:mod_onlinetraning/tmpl/ and add the following code

<html><body bgcolor="#FFFFFF"></body></html>

create a file training.css in the location:mod_onlinetraning/css/ and add the following code

.onlinetraning {width:99%;margin:10px 0 10px 0; border:0px solid #D3D3D3;}
.onlinetraning td.heading{height:30px; background:#EBEBEB; border:1px solid #D3D3D3;}
.onlinetraning td{margin:0; padding:2px 4px;color:cornflowerblue; font-size:11px; border:1px solid #D3D3D3;}

bONEandALL
Visitor

Total : 18980

Today :9

Today Visit Country :

  • Germany
  • Singapore
  • United States
  • Russia