| Friday 25 July 2003 4:08:09 pm 
                                                                 
OK! I try to start from beginning again... :(This isn't going to be as much documented example, 'cause I'm tired and pissed...
 
In this example we make a module named "mymodule"."mymodule" has 1 view called "list".
 We have one template where we use fetch to list all our data from our database table called "mytable".
 
Folders and files:-----------
 In your Exponential directory there is "extension"-folder (If not, create one).
 Inside that folder we make folder for our module "mymodule".
 Inside that folder we make folder structure like this:
 (/extension/mymodule)/modules/mymodule
 (extension/mymodule)/settings
 
The we create folder under the "standard" design./design/standard/templates/mymodule/
 
Inside folder: extension/mymodule/modules/mymodule,we put all the files expect the "list.tpl" -file.
 
Inside folder: extension/mymodule/settings,we put the module.ini.append file.
 
Inside folder: /design/standard/templates/mymodule/,we will put the list.tpl -file.
 -----------
 
1. Our module.ini.append file:-----------
 [ModuleSettings]
 ExtensionRepositories[]=mymodule
 -----------
 
2. The database:-----------
 We create a table named "mytable" to ez database and make 2 cells, "id" and "name".
 We add some data to the table:
 id name
 1 First row
 2 Second row
 -----------
 
3. Our module.php file:-----------
 $Module = array( 'name' => 'mymodule' );
 
$ViewList = array();$ViewList['list'] = array(
 'script' => 'list.php',
 "unordered_params" => array( "offset" => "Offset" ) );
 
What happens here is that we make a view "list" for the module,witch points to file "list.php" and we send parameter "Offset" to it.
 ----------
 
4. Our list.php file:----------
 $Module =& $Params['Module'];
 
$Offset = $Params['Offset'];if ( !is_numeric( $Offset ) )
 $Offset = 0;
 $viewParameters = array( 'offset' => $Offset ); 
include_once( 'kernel/common/template.php' );$tpl =& templateInit();
 $tpl->setVariable( 'view_parameters', $viewParameters ); 
$Result = array();$Result['content'] = $tpl->fetch( "design:mymodule/list.tpl" );
 $Result['path'] = array( array( 'url' => false,
 'text' => 'MY Module' ),
 array( 'url' => false,
 'text' => 'List' ) );
 
In here we receive the parameters from module.php and send them forward to list.tpl with "setVariable" function.Then we load the list.tpl to screen...
 -----------
 
5. Our list.tpl file:-----------
 {let data_limit=10
 data_list=fetch('mymodule','list',hash(offset,$view_parameters.offset,limit,$data_limit))}
 <h1>All URLs</h1>
 {section name=DATA loop=$data_list sequence=array(bglight,bgdark)}
 <b>{$:item.id}</b>{$:item.name}
 {/section}
 {/let}
 
Actually we don't need that "data_limit" and "hash(offset...)" thing in our example now,but it's there just to show how the Offset parameter goes around the files... ;)
 
Hint: {$:item.xxx} is the name of our database tables cell... ;)-----------
 
6. Our fetch function:-----------
 To archieve in this we need 2 files: mymodulefunctioncollection.php and function_definition.php.
 
First, function_definition.php-----
 $FunctionList = array();
 $FunctionList['list'] = array(
 'name' => 'list',
 'operation_types' => array( 'read' ),
 'call_method' => array( 'include_file' => 'extension/mymodule/modules/mymodule/mymodulefunctioncollection.php',
 'class' => 'MyModuleFunctionCollection',
 'method' => 'fetchList' ),
 'parameter_type' => 'standard',
 'parameters' => array( array( array( 'name' => 'offset',
 'required' => false,
 'default' => false ),
 array( 'name' => 'limit',
 'required' => false,
 'default' => false ) ) );
 -----
 
Second, mymodulefunctioncollection.php:-----
 include_once( 'extension/mymodule/modules/mymodule/mymodule.php' );
 
class MyModuleFunctionCollection{
 
 function MyModuleFunctionCollection(){
 }
 
 function &fetchList( $offset, $limit ){
 $parameters = array( 'offset' => $offset,
 'limit' => $limit );
 $lista =& Mymodule::fetchListFromDB( $parameters );
 
 return array( 'result' => &$lista );}
 } ----- 
Third, mymodule.php:-----
 include_once( 'kernel/classes/ezpersistentobject.php' );
 
class Mymodule extends eZPersistentObject{
 
 function Mymodule( $row ){
 $this->eZPersistentObject( $row );
 }
 
 function &definition(){
 return array( 'fields' => array(
 'id' => array(
 'name' => 'id',
 'datatype' => 'integer',
 'default' => 0,
 'required' => true ),
 'name' => array(
 'name' => 'name',
 'datatype' => 'string',
 'default' => '',
 'required' => true ) ),
 'keys' => array( 'id' ),
 'increment_key' => 'id',
 'class_name' => 'mymodule',
 'name' => 'mytable' );
 }
 
 function &fetchListFromDB( $parameters = array() ){
 return Mymodule::handleList( $parameters, false );
 }
 
 function &handleList( $parameters = array(), $asCount = false ){
 $parameters = array_merge( array( 'as_object' => true,
 'offset' => false,
 'limit' => false ),
 $parameters );
 $asObject = $parameters['as_object'];
 $offset = $parameters['offset'];
 $limit = $parameters['limit'];
 $limitArray = null;
 if ( !$asCount and $offset !== false and $limit !== false )
 $limitArray = array( 'offset' => $offset,
 'length' => $limit );
 
 return eZPersistentObject::fetchObjectList( Mymodule::definition(),null, null, null, $limitArray,
 $asObject );
 }
 
}-----
 
Now we just login to our admin site and goto url: /mymodule/list.We see our list.tpl showing the 2 variables from the database... (Hopefully)
 
I'm sorry but I cannot write anymore notes right now... I'm too tired. (And still pissed,because I lost the original example what I was writing... It had a lot more notes and hints...)
 
Hope this helps,Jerry
 |