What We Do
We provide top quality services and best solutions based on your requirements and needs.
Share

Introduction to Program Triggering

Recently, I was involved in a project that dealt with Flash. The project was divided into 2 parts; the main website and its micro site. I have been assigned to the main website part and the website was to be built in Flash. Luckily for me, the Flash was already developed and my job is to synchronize the Flash content with the content in MXAE.
 
The first problem that I have is where would the Flash contents be stored? As I scanned thru the flash template, I found out that the contents for the Flash are stored in an xml file, which makes my job easier. Now that I know which file to update for the Flash content, the next question is how am I going to pump in the articles from MXAE into the xml file automatically?
 
This is where I get to know about the "program trigger" feature in MXAE. With this feature, the MXAE articles can be automatically updated into the xml file whenever there are changes on the articles.
 
What is ‘Program Trigger’? It is basically a function that allows the developer to perform something on the article object before (PRE) or after (POST) the article is submitted at AMS. The feature is similar to the ‘Member Trigger’, ‘Post-Callback’ and ‘C allback’. To illustrate the normal flow of the ‘Program Trigger’ feature, please refer to the image below.

Image 1: Normal Operation Flow
 
To start the program triggering, the template code and the function name have to be defined and the format is

Template Code||Function Name

And the function definition for the trigger is

function triggerFunc($triggerType, $eventType, $article) { ... }

Where:
Parameter Description Possible value
$triggerType MX_TRIGGER_PRE or MX_TRIGGER_POST to indicate the call if before the event is done or after it is completed MX_TRIGGER_PRE = 0
MX_TRIGGER_POST = 1
$eventType the MX_EVENT_* constants defining the event triggering this notification
 
MX_EVENT_ADD = 1
MX_EVENT_UPDATE = 2
MX_EVENT_DELETE = 4
$article the article object that is currently undergoing this triggering Article Object
 
In this project, I have defined the
  • Program trigger: contenttrigger.tsl||getAnnouncements
  • Trigger: function getAnnouncements($triggerType, $eventType, $article) { ... }

Image 2: Program Trigger
 
As quoted from the ‘Program Trigger’ explanation,
 
During a call to with a pre-trigger, the user can return false for MX_EVENT_UPDATE, MX_EVENT_ADD and MX_EVENT_DELETE to stop the normal process from continuing. However, doing so may cause complications if error messages are not set properly.
 
To illustrate this, please refer to the image below, where the red line is representing the ‘return false’.

Image 3: Return false on the pre-trigger
 
With all these information, the getAnnouncements function is
  • Triggered on the POST operation
  • Write all the articles into the xml file
Below is how the getAnnouncements function looks like
function getAnnouncements($triggerType, $eventType, $article) {
                $proceed = false;
                $filters = array('orderby' => '>dateannounce');
                if (MX_EVENT_DELETE == $eventType) {
                                $filters = array('id' => array($article->id, '!='), 'orderby' => '>dateannounce');
                                $proceed = true;
                } else {
                                if (MX_TRIGGER_POST == $triggerType) $proceed = true;
                }
                               
                if ($proceed) {
                                $annData = '';
                                               
                                $pgObj = $article->getProgram();
                                $articles = $pgObj->getArticles($filters);
                                foreach ($articles as $oneArticle) {
                                                $moreUrl = '';
                                                if ($oneArticle->url != '') $moreUrl = '<moreLink href="'.trim($oneArticle->url).'" target="_blank">Read More</moreLink>';
                                                               
                                                $imageFile = '019712.jpg';
                                                $repositories = $oneArticle->getAllRepositories();
                                                foreach ($repositories as $oneRepository) {
                                                                $imageFile = basename($oneRepository->filepath);
                                                }
                                                               
                                                $annData .= "\n".'<entry date="'.$oneArticle->dateannounce->format('y/m/d').'">
                                                                                <textBlock>
                                                                                                <title>'.trim(rmNewline($oneArticle->title)).'</title>
                                                                                                <content><![CDATA[<font color="#FFFFFF">'.trim(rmNewline($oneArticle->desc)).'</font>]]></content>
                                                                                                <thumbnail>'.$imageFile.'</thumbnail>
                                                                                                '.$moreUrl.'
                                                                                </textBlock>
                                                                </entry>';
                                }
                                               
                                $annData = '<menuName>Announcements</menuName>
                                                <thumbnail>0178announcements_active_thumbnail.jpg</thumbnail>
                                                <tooltip>Latest Announcements</tooltip>
                                                <background>0147background_announcements.jpg</background>
                                                <template type="news">
                                                                <title>Announcements</title>
                                                                '.$annData.'
                                                </template>';
                                               
                                                writeContentFile('content_announcements.xml', $annData);
                }
                               
                return true;
}
 
With this been done, whenever there is an article operation, this function will be triggered and update the articles into the xml file and in turn the Flash will read the xml contents and will display the contents automatically.
 
With this feature been added into the family of ‘Member Trigger’, ‘Post-Callback’ and ‘Callback’, the developer have been awarded with more control over the data as well as the flexibility of choosing which feature to implement based on the project requirement.

MXAE Release News

MXAE 2.7.5 Released
We would like to announce the immediate availability of MXAE 2.7.5. This release focuses on...




Tips & Tricks

CSS Conditional Comments on MXAE
Conditional comments make it easy for developers to take advantage of the enhanced features...




MXAE Free Hosting

We are offering FREE hosting on MXAE platform with no string attached. You can use it as a development or demo hosting for your company. You can also use it to build your own website or host your client website.