Forums / Developer / Custom modules

Custom modules

Author Message

Trond Åge Kvalø

Thursday 11 March 2004 2:43:15 am

Ok, the object relation list has been abandoned for the time being. Instead we have created our own database table for our course licenses.

I've managed to create a very primitve create license module that stores our data in the database table.

The problem is that I'm quite uncertain as to what I'm really doing. That's a rather uncomfortable feeling, so if someone could please help me get a grip on this code I'd be most grateful.

First, my directory structure for this extension is:

lisenser
  modules
    lisenser
      module.php
      opprettLisens.php
  settings
    module.ini.append

Am I correct in my assumption that the folders in the modules folder are views?

This is my module.php script:

<?php
//next line need explanation
$Module = array( "name" => "Oprett lisens" ); 

//this create a viewlist that I assume is a list of the 
//folders in the modules folder with underlying scripts
$ViewList = array();
$ViewList["lisenser"] = array( "script" => "opprettLisens.php");
?>

This is the opprettLisens.php script:

<?php
// I recieve data from a form that is posted to the module
$userid = $_POST['userid'];
$courseid = $_POST['courseid'];

// Build module result array
// Taken from hello module in the docs
// what is this used for, and how?
$Result = array();
$Result['userid'] = $userid;
$Result['courseid'] = $courseid;
$Result['path'] = array( array( 'url' => '/lisenser/opprettLisens',
                                'text' => "Opprett lisens") );

//This I understand :-)
include_once( "lib/ezdb/classes/ezdb.php" );
$db =& eZDB::instance();
  // start a new transaction
  $db->begin();
  // send the SQL INSERT command to the database
  $db->query( "INSERT INTO course_licenses (licenseid, userid, courseid, registration_date) VALUES ('NULL', $userid, $courseid, now())");
  // commit the transaction
  $db->commit();
?>

In my admin interface I have the following node based template override:

<h3>Opprette kurslisens for e-kurs</h3>
<form name="create_license" action="http://lms/index.php/kompetanseportalen_admin/lisenser/lisenser/opprettLisens.php" method="post">
<table cellpadding="2" cellspacing="0" width="300">
  <tr>
    <td valign="top">Velg bruker: </td>
	<td valign="top">
	  <select name="userid">
      {section loop=fetch( 'content', 'tree', hash('parent_node_id', 5,
                                               'class_filter_type',  'exclude',
                                               'class_filter_array', array( 'user_group' ) ) ) }    
    <option value="{$:item.contentobject_id}">{$:item.name|wash}</option>
    {/section}
    </select>
    </td>
  </tr>
  <tr>
    <td valign="top">Velg kurs: </td>
	<td valign="top">
	  <select name="courseid">
      {section loop=fetch( content, list, hash(parent_node_id, 98) ) }
      <option value="{$:item.contentobject_id}">{$:item.name|wash}</option>
      {/section}
      </select>
    </td>
  </tr>
</table>

<input name="create_license" type="submit" value="Lag lisens">
</form>

which gives me two dropdown selection boxes. One that contains all users, and one that contain all e-learning courses.

A license is practically just a connection between one user and one course. So when I've chosen the correct user and the correct course. I click the "Lag lisens" button which submits my form to my custom module.

All well so far. But I get no response after clicking the button. What should I do to at least show the user that the data was stored successfully? Is that what the $Result array is for?

The next step will be to show a logged in user which courses she's licensed to run. How would I do this? Create another folder under modules that has the name showmylicenses and create a showmylicenses.php script? Using the same thechniques as in my opprettLisenser.php script?
Or can I use a fetch in a template to show values in a custom database table?

Please help anyone.

best regards
trondåge

trondåge

Trond Åge Kvalø

Thursday 11 March 2004 4:46:20 am

By trial and error, I've found out that the folders under extension/myext/modules is... duh... modules.

So to sum it up a bit, this is how a custom module URL is built:

www.myexample.com/index.php/mySiteAccess/myModule/myView/myscript.php

where myModule is the folder name under extension and extension/myModule/modules,
and myView is an element in the $ViewList array.

Please correct me if I'm wrong here

best regards
trondåge

trondåge

Eirik Alfstad Johansen

Thursday 11 March 2004 5:03:31 am

Hi Trond Åge,

The view fetches the script, so you don't need to specify it in the URL.

Sincerely,

Eirik Johansen

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

eZ debug

Timing: Jan 19 2025 00:28:41
Script start
Timing: Jan 19 2025 00:28:41
Module start 'content'
Timing: Jan 19 2025 00:28:42
Module end 'content'
Timing: Jan 19 2025 00:28:43
Script end

Main resources:

Total runtime1.4965 sec
Peak memory usage4,096.0000 KB
Database Queries194

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0063 587.5781180.8516
Module start 'content' 0.00631.3149 768.4297561.4844
Module end 'content' 1.32120.1752 1,329.9141336.7734
Script end 1.4964  1,666.6875 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00430.2853210.0002
Check MTime0.00150.0994210.0001
Mysql Total
Database connection0.00080.052810.0008
Mysqli_queries1.415594.58801940.0073
Looping result0.00220.14501920.0000
Template Total1.466198.020.7331
Template load0.00200.132920.0010
Template processing1.464197.836420.7321
Template load and register function0.00020.011810.0002
states
state_id_array0.00170.112510.0017
state_identifier_array0.00160.104320.0008
Override
Cache load0.00170.1124380.0000
Sytem overhead
Fetch class attribute can translate value0.00150.100530.0005
Fetch class attribute name0.00090.060440.0002
XML
Image XML parsing0.00100.063730.0003
class_abstraction
Instantiating content class attribute0.00000.000740.0000
General
dbfile0.00320.2165270.0001
String conversion0.00000.000430.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
11content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
4content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 25
 Number of unique templates used: 7

Time used to render debug report: 0.0002 secs