Shika: Lesson Type Plugins

Decide which type of format plugin you have to create

As you know Shika allows to create few lesson types already. Scorm, Video, Document, HTML zips are these of the types. Except Video, there is only one way to upload other lesson formats. All these are plugin types in Shika. In case of Video, tjvideo is type of plugin and jwlayer, vimeo or kpoint are the plugins. So if you want to create plugin of Video format, you just have to give ‘tjvideo’ as its group in XML file. Similarly if you want to create a new plugin to upload documents, you just have to give ‘tjdocument’ as its group in XML file.

These lesson formats are declared in 'administrator/components/com_tjlms/view/modules/tmpl/default_format.php' as array.

$lesson_formats_array = array('scorm','htmlzips','tincanlrs','video','document','textmedia','externaltool'); 

 

if you want to add new lesson format then you have to add the same in above array and then you can link this through the plugin.

Suppose you are creating a new “Flowplayer” plugin of video types, so Plugin will have following main files in “flowplayer” subfolder under “tjvideo”

  • a) flowplayer.xml: So now you have ‘tjvideo’ as its group in XML file flowplayer.xml
  • b) flowplayer.php: mainly used to identify the plugin
  • c) Creator.php: in flowplayer/tmpl folder, mainly used to perform the user inputs get stored in correct database tables

Following functions are mandatory in entry file of plugin(flowplayer.php)

A. public function GetSubFormat_tjvideoContentInfo($config = array(‘flowplayer’))
      {
      if (!in_array($this->_name, $config))
      {
          return;
      }

      $obj             = array();
      $obj['name']    = $this->params->get('plugin_name', '‘flowplayer’');
      $obj['id']        = $this->_name;

      return $obj;
      }

This function is used to check if the plugin is configured correctly and is ready to use. The default value for the config parameter is the name of the plugin.

     B. public function GetSubFormat_flowplayerContentHTML($mod_id , $lesson_id, $lesson, $comp_params)
  {
      $result = array();
      $plugin_name = $plg = $this->_name;

    // Load the layout & push variables
      ob_start();
      $layout = $this->buildLayoutPath('creator');
      include $layout;
      $html = ob_get_contents();
      ob_end_clean();

      return $html;
  }

This function to get HTML when creating / editing lesson format The name of function should follow standard getSubFormat_ContentHTML

Params $mod_id id of the module to which lesson belongs $lesson_id id of the lesson $lesson Object of lesson $comp_params Params of component

You will note that we have included a creator.php file here. This file resides in plugins/tjvideo/flowplayer/flowplayer/tmpl folder. The code written in creator.php is basically the HTML which you want to render while adding lesson format in backend.

 3. public function renderPluginHTML($config)
  {
   }

Function to render the video in the frontend when user launched the lesson. You can have JS mixed HTML here which will help to track the lesson. Whatever echoed in this function will be shown in lesson in frontend.

3. Code in creator.php

Earlier, I have said that you need to create a cretor.php file inside plugins/tjvideo/flowplayer/flowplayer/tmpl folder. But there are steps to be followed to write the code in this file, so that the user inputs get stored in correct Shika tables.

Firstly decide, if you want to allow user to write a link of a video or to upload a video.

A. Upload video:

Code to select file

<div class="control-label">
	<?php echo JText::_("COM_TJLMS_UPLOAD_FORMAT") ?>
</div>

<div  class="controls">
  <!--<input type="hidden"
	  id="lesson_format<?php echo $plugin_name?>document_source"
	  name="lesson_format[<?php echo $plugin_name?>][document_source]"
	  value="upload"/>-->
  <div class="document_upload">
	  <div class="fileupload fileupload-new pull-left" data-provides="fileupload">
		  <div class="input-append">
			  <div class="uneditable-input span4">
				  <span class="fileupload-preview">
					  <?php echo JText::sprintf('COM_TJLMS_UPLOAD_FILE_WITH_EXTENSION', 'pdf, doc, docx, ppt, pptx', $comp_params->get('lesson_upload_size', '0', 'INT'));?>
				  </span>
			  </div>
			  <span class="btn btn-file">
				  <span class="fileupload-new"><?php echo JText::_("COM_TJLMS_BROWSE");?></span>
				  <input type="file"
						  id="document_upload"
						  name="lesson_format[<?php echo $plugin_name?>][document]"
						  onchange="validate_file(this,'<?php echo $mod_id?>','<?php echo $plugin_name;?>')">
			  </span>
		  </div>
	  </div>
	  <div style="clear:both"></div>
	  <div class="format_upload_error alert alert-error" style="display:none" ></div>
	  <div class="format_upload_success alert alert-info" style="display:none"></div>
  </div>

 

Code to restrict which extensions are allowed

<input type="hidden" class="valid_extensions" value="pdf,doc,docx,ppt,pptx"/>

          <input type="hidden" id="uploded_lesson_file" name="uploded_lesson_file" value=""/>

 

Code to tell LMS you are have given upload option

<input type="hidden" id="subformatoption name="lesson_format[boxapi][subformatoption]" value="upload"/>

 

B. Enter URL Code to show textarea where user will write his URL

 <div class="control-label"><?php echo JText::_("COM_TJLMS_VIDEO_FORMAT_URL_OPTIONS");?></div>

      <div  class="controls">
            <div id="video_textarea" >
              <textarea     id="video_url"
                  class="input-block-level"
                  placeholder="<?php echo JText::_("PLG_TJVIDEO_VIMEO_VIDEO_PLACEHOLDER")?>"
                  cols="50" rows="2"
                  name="lesson_format[vimeo][url]" ></textarea>
          </div>
      </div>

 

Code to tell LMS you are have given URL option

<input type="hidden" id="subformatoption" name="lesson_format[<?php echo plug_name ?>][subformatoption]" value="url"/>

 

Code to track the lesson time:

public function updateData()
    {
        $db = JFactory::getDBO();
        $input = JFactory::getApplication()->input;

        $mode = $input->get('mode', '', 'STRING');
        $trackingid = '';

        // Here we write code for tracking the current video status and then we can either resume the video for user or complete the lesson for him.


            require_once JPATH_SITE . '/components/com_tjlms/helpers/tracking.php';
            $comtjlmstrackingHelper = new comtjlmstrackingHelper;
            $trackingid = $comtjlmstrackingHelper->update_lesson_track($lesson_id, $oluser_id, $trackObj);
        }

        return $trackingid;
    }