Beruflich Dokumente
Kultur Dokumente
Refreshing eLearning…
eFront
Manual for module programmers
EPIGNOSIS LTD
44, Katehaki, Athens, Greece, 11525
email: info@efront.gr
phone: (+30) 210 6756008, (+30) 210 6756112
Fax: (+30) 210 6756527
• Basic PHP skills (well you wouldn’t be reading this tutorial otherwise)
• Fundamental object-oriented understanding
• Basic XML knowledge (for writing the module manifest)
• Blindly obeying to the 3 golden rules of eFront modules
There are a few things we could tell about the eFront modules system. It is based
upon the logic that the main responsibility of module programmers is to define the
methods of an existing abstract base module class. The return values of these methods
will be used by the core eFront system to display and manage your module. Some of
those methods are mandatory, while others might be used or not. If your module does
not use them, then they will return the default values as defined in the base class and
the system will know that they have not been implemented for this module. Therefore,
define only mandatory derived methods and only the derived methods that are
required by your module in order to avoid unnecessary problems. Leave everything
else alone!
If you are an experienced programmer, then you might figure out pretty easily how to
write a module by reading the following chapter and studying the methods of the
modules.class.php file, where the module base class exists. Otherwise, take a look at
the step-by-step tutorial below:
We assume that you have downloaded and setup eFront and that you have an idea for
an eFront module on your mind. Great! The first thing to do is write an XML
description file called module.xml regarding your module.
module.xml
<?xml version="1.0" ?>
<module>
<title>Any title for the module </title>
<author>For vanity reasons mainly </author>
<date>For historians to know</date>
<version>The version of your module</version>
<description>A free-text description of the module </description>
<className>the PHP class of the module</className>
</module>
The className tells eFront that the base class of your module will be called
className and will be defined in a file called className.class.php. For example, the
module
Moreover, the definition of your class should be set to extend the abstract global class
for eFront called eFrontModule. This is done as follows:
module_faq.class.php
<?php
?>
A sample implementation of those basic two functions, for a module called (with
className) module_best_student, which shows the name of the student with the best
grade in a lesson to its professor, would be the following:
}
?>
If the students were also to see who the best student is, then the getPermittedRoles()
function would change as:
getPermittedRoles method
public function getPermittedRoles() {
return array("professor", “student”);
}
Well, believe it or not, this is all that is required for you to create the basis of your
module. You needn’t even define a constructor class. (Note: Actually you shouldn’t
define a constructor class). In fact, if you do not need to add or alter any table
structures in the eFront database for your module to function correctly, then you might
as well install the module right away. Of course, if no other methods are implemented,
the module won’t do anything, but it will be recognized by eFront and you would be
able to view the changes on your code on the eFront system, since programming in
blind is always risky.
Note: If you try to copy-paste code from this document, make sure that all quotes “”
and ‘’ appear the way they should in PHP.
Before we move on to the installation part, we will have a brief view of how to incur
any changes to the database.
You may define your module to setup the eFront database in three occasions: during
its installation and its uninstalling. The methods used for this reason are onInstall and
onUninstall respectively.
Note: As a good practice, use your module’s class name in the name of the table so as
to avoid conflicts with existing tables.
Note: For multilingual support set the default charset of each created table to UT F8.
After optionally designating the database setup functions (and more significantly the
onInstall one), we suggest you install the module right away. Installation can take
place from the administrator menu, namely from the “Modules” option at the
administrator control panel. To install a module:
• Create a zip file having all module files. The root of the zip directory should
necessarily contain the module.xml manifest file and the className.class.php
file, otherwise the module won’t be installed.
Note: It is suggested that the zip file has the same className as your module, in
order to avoid any collision problems of modules with the same name.
• Click “Add new module” link of the module administration page and upload
the zipped file.
Note: If a module exists in the system with the same className, then your module
will not be installed. Solution: Change the className
Note: If the your module cannot be installed maybe there is a problem with the
database script (if you provided one) or the xml manifest. Check whether the name in
the manifest file is exactly the same as the one provided as the className for your
module class.
Now, if the module has been correctly installed, it should appear on the list of
modules on the administrator module page. You can edit your module’s code by going
to the www/modules/ folder, opening your own module folder and editing or inserting
the files you want (or only the className.class.php one).
To this point, we have installed a module that doesn’t do anything, so it might as well
all seem like a waste of time. Not at all! In fact, we have let eFront know of a new
unique module class called className and take it into account for all pages of the
roles returned by the getPermittedRoles() method array defined there. Moreover, we
(optionally) have changed the underlying database for our module to function
correctly.
So, we can start making the module do something. The easiest way to do that is open
the module.class.php file and have a look at the methods provided for
implementation. These can be divided into the following categories:
These methods trigger the appearance and functionality of the module page(s) that
should appear as stand-alone on the right hand side frame of the eFront system
window. Links to these pages could be defined as explained in the 5.2 Link methods
section and their urls should all begin with the $this->moduleBaseUrl string. This
leads to the first golden rule of eFront modules:
Rule I: Any URLs related with your module’s main-independent pages should begin
with the $this->moduleBaseUrl string.
Understanding this example means that you have the entire eFront modules system
figured out. Let’s make some observations here:
a) The getModule() method returns 4 (at least – since we have “else”) pages executing
different code according to the $_GET variables set. Speaking of $_GET variables
let’s have a look at the second golden rule of eFront modules:
Rule II: You might have your pages using any $_GET/$_POST variables you like
except from ‘ctg’ and ‘op’
b) In 3 out of the 4 cases, pure HTML code is returned which will be printed as is.
Take notice that the $this->moduleBaseDir is used to denote the module directory
path. However, the path for the image file logo.png in folder images is referenced
with the $this->moduleBaseLink variable. This leads to the third golden rule of
eFront modules.
Rule III: The root of your module extracted folder is stored as the
$this->moduleBaseDir variable. Any further paths inside that directory may be
referenced normally. The URL location of this folder is stored in the
$this->moduleBaseLink variable.
This means that the path on the hard disk of the file my_photo.png inside the photos
folder of the module directory should be referred to as:
$this->moduleBaseDir . “photos/my_photo.png”
Therefore, if you want to link to an image file you will have to use the following
syntax:
echo “<img src = ‘“.$this->moduleBaseLink.“ photos /my_photo.png’ />”;
c) In the 4th case smarty is used. The global smarty variable is received from the
eFront system with the getSmartyVar() method and is used normally. No HTML
code is returned by the getModule() function. However, the getSmartyTpl() method
returns the filename of the template file to be used for that scenario, thus explaining to
the system that smarty is being used in this case.
d) Finally, have a look at how the smarty template file still makes use of the
$this->moduleBaseUrl, $this->moduleBaseLink and $this->moduleBaseDir
variables as defined by rules 1 and 3.
Note: These variables can be assigned to the global smarty object, as it is done in the
getSmartyTpl() function of the example above, and be used by the template. However,
make sure as a good practice to use smarty variable names that include your module’s
class name, so as to ensure uniqueness. The smarty object is the same for the entire
eFront system and for all modules. Thus using general names like
“T_MODULE_BASELINK” or “T_USER” or “LESSON” might conflict with
existing variables with various results on the system. For a module called
“best_module” you could alternatively use “T_BEST_MODULE_BASELINK” or
“T_BEST_MODULE_USER” or “BEST_MODULE_LESSON”.
Methods related to module links are used to make links appear for the module,
meaning to the module’s pages or to any other pages in the system the module author
wants to.
menu id: is the unique identifier of one of the existing eFront menus. These
are shown on the table below:
Note: Every module can create up to one custom menu and overall modules
may define up to 8 new custom eFront menus. If more than these are used,
then all links of all “Other” module menus will be put under the “Modules”
menu.
link: an array with all necessary information for the link. These are:
o íd: the unique id of the link within the module framework. This
can be later used for highlighting purposes (see
getLinkToHighlight() method)
o title: the title of the link
o image: the image that will appear next to the link. Note: remember
to use $this->moduleBaseLink if you use pictures inside the
module directory. Otherwise, use the relative path from the main
www/ folder of eFront.
o eFrontExtensions: allows you to alternatively use ‘png’ and ‘gif’
images instead of always the same image depending on the
browser. This approach is followed throughout eFront and
guarantees better icon appearances. Therefore, if this field is
defined, then
the image file provided should have no extension
two different image files with the same filename and
different extension should be provided in the path set in the
image field. One should be ‘png’ and the other ‘gif’
1
For the eFront Enterprise™ version
$link_of_menu_lessons = array (
'id' => 'other_link_id1',
'title' => “Lesson link title”,
'image' => $this -> moduleBaseLink . 'images/image16',
'eFrontExtensions' => '1', //no extension provided up
'link' => $this -> moduleBaseUrl .
"&module_operation=lesson_related");
// and admins should see a link in the users menu and in a newly defined menu
} else if ($currentUser -> getType() == “administrator”) {
$link_of_menu_other = array (
'id' => 'other_link_id1',
'title' => “Other link title”,
'image' => 'images/16x16/pens',
'eFrontExtensions' => '1', //no extension provided up
'link' => $this -> moduleBaseUrl .
"&module_op=user_related");
}
}
The sample should be self – explanatory. Just note again the how variables
$this -> moduleBaseUrl and $this -> moduleBaseLink are used, and how the
Methods related lesson modules have to do with sub-windows that may appear on the
current lesson control panel for professors and students. They work in the exact same
way as the “Main – Independent module pages”, meaning that either pure HTML
code is returned and printed or a smarty template file is defined.
The picture above shows a snapshot of a typical professor lesson control panel,
denoting with red color the places where module related links or frames might be put.
The corresponding methods are the following:
Note: Lesson modules must be activated for each lesson from the lesson
administration page by the administrator or one of the lesson’s professors.
The picture above shows a snapshot of a typical administrator control panel, denoting
with red color the places where module related links or frames might be put. The
corresponding methods are the following:
The eFront module’s system offers further possibilities for increasing the appearance
customization and functionalities of modules. This is accomplished with methods that
allow you to define a ‘css’ file for your module, a ‘js’ file or language files.
A good way to create Multilanguage interfaces in php is using different language files
where the same constant variables are defined, and including the appropriate one into
your code. For example, you can have a
language_english.php language_german.php
define(“GREETING”, “Good morning”); define(“GREETING”,“Guten morgen”);
You can distinguish which language file to include each time with the following
method:
Note: If you name your language files like lang-language.php then you do not need to
implement the getLanguageFile method at all. The default method will work in this
case.
Note: As a good practice we advice you to use your module’s class name (which will
be unique) as a prefix for all constant variables you define, so as to avoid conflict with
other modules or existing eFront constants. For example, the above given example
should be for the “best_student_module”something like:
language_english.php
define(“BEST_STUDENT_MODULE_GREETING”, “Good morning”);
language_german.php
define(“BEST_STUDENT_MODULE_GREETING”, “Guten morgen”);
You might define a custom css file for your module with the method:
• public function getModuleCSS ():
This method should return the filename of the css file corresponding to the module. It
is a good idea to use a module specific namespace in your css so as to avoid collision
with existing classes.
Note: Do not forget to use the $this->moduleBaseDir variable in the filename
definition.
You might define a custom js file for your module with the method:
• public function getModuleJs ():
This method should return the filename of a js file containing all Javascript functions
that might be needed by your module. Bear in mind that name collisions are an
important issue in Javascript and therefore, you suggest you use your className as a
prefix to every function you define.
Note: Do not forget to use the $this->moduleBaseDir variable in the filename
definition.
A series of methods is derived from the base eFrontModule class in order to provide
all necessary runtime information to the module’s programmer. Most of these methods
return objects whose methods may also be used by your modules. These are:
It should be evident by now what string is required to be put into the array for the
correct script library to be loaded.
The last series of methods involves the triggering of module related actions on
specific predetermined actions that take place within the eFront framework. The
current version of eFront modules system supports events triggered on:
Note: Bear in mind that the imported lesson data might contain ‘id’ fields that relate
to the lesson that was exported. We advice you to consider that during the
implementation of the onImportLesson() function and set all those fields equal to the
id of the lesson into which the data are imported, namely to $lessonId. Otherwise, the
imported lesson data will refer to the previously exported and not to the newly
imported lesson.
Now, that we have a good overview of how eFront modules can be defined, let’s go
and create a sample module. This module should return to the professor a list of the
three most students with the highest score in the current lesson.
Step 0: Design
module_highest_rank.class.php – version 1
<?php
Step 4: Install the module by logging into the eFront system as administrator and
selecting the “Modules” link of the control panel.
Since we want to create a control panel module for the professor we are going to use
the getLessonModule (or it in conjunction with getLessonSmartyTpl) as explained
above (paragraph 5.3).
At this point we assume that the eFront SQL interface and database is known to the
programmer, so we will directly implement the getLessonModule code.
module_highest_rank.class.php – version 2
<?php
The resulting lesson control panel for the professor is the following
module_highest_rank.class.php – version 2
public function getSidebarLinkInfo() {
$link_of_menu_clesson = array (array ('id' => 'module_best_link',
'title' => ‘Best student page’,
'image' => 'images/16x16/star_yellow',
'eFrontExtensions' => 1,
'link’ => $this -> moduleBaseUrl ));
Finally, we may define the navigational links for our module page with the
getNavigationLinks method. We will define two links, one for the Home page of the
lesson and one for our module page.
Future steps: These steps more or less wrap up the fundamental notions behind
eFront module programming. Following the same steps, defining the well-known
derived methods of your choice and blindly obeying to three golden rules will enable
you to create from obscenely trivial to extremely complicated modules. Just as a
reminder of the last:
Rule I: Any URLs related with your module’s main-independent pages should begin
with the $this->moduleBaseUrl string.
Rule II: You might have your pages using any $_GET/$_POST variables you like
except from ‘ctg’ and ‘op’
Rule III: The root of your module extracted folder is stored as the
$this->moduleBaseDir variable. Any further paths inside that directory may be
referenced normally. The URL location of this folder is stored in the
$this->moduleBaseLink variable.
And a final tip: if at any point of the module development you come across a blank
screen then go to “/libraries/globals.php” and uncomment the line
error_reporting( E_ALL );
The last error message should give you a pretty good idea of what is wrong with your
module.