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/

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 19 2025 03:27:22
Script start
Timing: Jan 19 2025 03:27:22
Module start 'layout'
Timing: Jan 19 2025 03:27:22
Module start 'content'
Timing: Jan 19 2025 03:27:23
Module end 'content'
Timing: Jan 19 2025 03:27:23
Script end

Main resources:

Total runtime1.2913 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0057 589.0313152.6094
Module start 'layout' 0.00570.0039 741.640639.4063
Module start 'content' 0.00961.2799 781.0469556.4219
Module end 'content' 1.28950.0018 1,337.468816.2031
Script end 1.2912  1,353.6719 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00320.2448160.0002
Check MTime0.00130.1038160.0001
Mysql Total
Database connection0.00090.069710.0009
Mysqli_queries1.237895.8591570.0217
Looping result0.00050.0359550.0000
Template Total1.246696.520.6233
Template load0.00180.142620.0009
Template processing1.244896.394420.6224
Template load and register function0.00030.019410.0003
states
state_id_array0.00190.143610.0019
state_identifier_array0.00190.150520.0010
Override
Cache load0.00160.1211380.0000
Sytem overhead
Fetch class attribute can translate value0.00050.042120.0003
Fetch class attribute name0.00110.082840.0003
XML
Image XML parsing0.00060.047320.0003
class_abstraction
Instantiating content class attribute0.00000.000840.0000
General
dbfile0.00190.1436160.0001
String conversion0.00000.000940.0000
Note: percentages do not add up to 100% because some accumulators overlap

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
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 25
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs