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
|