1 Introduction
APA Lines module enables the user to get news data as array .
APA Lines module is divided into two parts: backend which provides the ability to migrate data from xml files which appear in the delivery folder to database and frontend part which gets necessary data from database and gives the user. Database structure for this module consists of 3 tables: {{apalines_news}} - whose entries are news lines or background news lines bound to parent news, {{apalines_mm}} – whose entries are multimedia content such as image or video, bound to parent news line or background news line and each entry of such table must have children records from {{apalines_file}} table, entries of whose are files: thumbnail and original of the same image.
2 Structure
APA Lines module placed in folder <portal>/common/modules/apalines
Structure is the same as for other modules. Delivery folders have to be placed in the apalines/content folder but the path may be overwritten in configuration file. This module has separate config file “_apalines.php” which has path /custom/config/apalines.php, because when admin sets up inotify via console command folders where apalines content is (channels) should be the same with frontend channels which are shown to end user. if some channel is different (frontend/command sides) data which user sees will be incorrect. So this file is included in /custom/config/client_main.php and /custom/config/clientconsole.php
3 How to use backend command
Backend is a console command: ‘processApa’. The command should be executed via /common/yiic. This command has 2 parameters: ‘channel’ – the name of the channel which was specified in the config file, ‘clear’ – whether command should clear apalines tables before it start import. In delivery folder must be fertig.txt file to do import. First the command moves all files to work folder, the if file data was successfully migrate to database, command moves file to done folder, otherwise to error folder. So if you want to clear tables and get data from `test` channel which was specified in config as:
'test' => array( 'max_age_of_news' => 24*30*5, 'max_count_of_news' => 30, 'delivery_path' => 'apalines.content.News1', ),
you must execute follow command:
/common/yiic processApa --channel=test --clear
Consider a configuration file:
return array( 'class' => 'site.common.modules.apalines.APALinesModule', //alias of module class path 'customer_number' => 'CB86E6F1-1847-4BD9-8FA7-E5606B97BCE8', //Customer number to get access an external video resource(via the next url param) 'video_url' => 'http://videoservice.apa.at/Player/UniversalPlayer.aspx', //Url to external video resources 'cacheTime' => 60, //Caching time for widget 'total_max_age_of_news' => 24*30*5, //Max age of news to be shown(and deleted older) in hours. When widget mixes few channels !!! 'total_max_count_of_news' => 50, //Max count of news to be shown. When widget mixes few channels !!! //You can set multimedia sizes yourself by specifying following fields: 'DefaultSize'=>'640x480', 'VideoSize'=>'640x480', 'OriginalSize'=>'640x480', 'ThumbnailSize'=>'320x240', 'HiresSize'=>'128x128', 'channels' => array( 'test' => array( 'max_age_of_news' => 24*30*5, //Max age of news to be shown in hours. When widget shows one channel. 'max_count_of_news' => 30, //Max count of news to be shown. When widget shows one channel. 'delivery_path' => 'apalines.content.News1', //Alias of delivery path ), ), );
To automate importing (for each channel) is using ‘incrontab’(is a table manipulator for the inotify cron (incron) system). To use this feature incrontab should be installed in the server: 1) Install incrontab if it was not installed yet:
- If Debian / Ubuntu Linux:
sudo apt-get install incron
- If RHEL / Fedora / CentOS Linux:
sudo yum install incron
2) Set up all the channels in the config file. 3) Use command to configure incrontab for your channels:
/common/yiic processApa setup
To prevent errors you should make sure that logging in the /custom/config/client_console.php is set up correctly as in following example:
'log' => array( 'class' => 'CLogRouter', 'routes' => array( array( 'class' => 'CProfileLogRoute', 'levels' => 'profile', ), 'file'=>array( 'class' => 'CFileLogRoute', 'levels' => 'error, warning, info', 'logPath' => dirname(FILE) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'common/runtime', ), ), ),
and also processApa command should be specified in the command map section:
'commandMap' => array( 'processAPA' => array( 'class' => 'site.common.modules.apalines.commands.processAPACommand', ), ),
4 How to use APA Lines widget
APA Lines module includes 1 widget. It shows news overviews and detailed views of separate news. If was specified get parameter ‘id’ as DOCID or title(without accents and spaces) of exist news widget shows its detailed view , otherwise it shows overview.
$apalines = $this->widget('common.modules.apalines.widgets.ApaLinesWidget', array( 'channel' => 'test1,test3', //Channels to be shown 'max_age_of_news' => 24*30*5, //Max age of news to be shown in hours. When widget shows one channel. 'max_count_of_news' => 50 //Max count of news to be shown. When widget shows one channel. ) ); $data = $apalines->data;
If settings ‘max_age_of_news’, ‘max_count_of_news’ were not passed and widget should show 1 channel similar values will be taken from module config for this channel:
'channels' => array( 'test' => array( 'max_age_of_news' => 24*30*5, 'max_count_of_news' => 30, ), ),
If in the same situation widget should show few channels similar values will be taken from module config:
'total_max_age_of_news' => 24*30*5, 'total_max_count_of_news' => 50
The data is returned by widget has following form:
$data = array( '0' => array( 'doc_id' => '...' , 'has_bg_news' => '...' , // 1/0 whether news has background news 'title' => '...' , 'place' => '...' , 'source' => '...' , 'header' => '...' , 'text' => '...' , 'author' => '...' , 'keywords' => '...' , 'filename' => '...' , //Title without accents to access news 'channel' => '...' , 'date' => '...' , 'detailed_link => '...' , //Link to see detailed information of news // Related background news 'bg_news' => array( '0' => array( //The same form as regular news form //Can have multimedia also (the same form as regular news multimedia) ), ... ); $multimedia = array( 'doc_id' => '...' , 'title' => '...' , 'place' => '...' , 'source' => '...' , 'author' => '...' , 'keywords' => '...' , 'filename' => '...' , 'date' => '...' , 'type' => '...' , // image / video //If type is video, will be a next line: //width, height, videoUrl, customer_number - specified in module settings 'iframe' => "<iframe margin='' padding='' width='{$videoWidth}px' height='{$videoHeight}px' src='{$videoUrl}?customer={$customer_number}&data={$docid}' border='0' frameborder='0' >", 'files' => array( 'thumbnail' => array( 'href'=> '...' , 'width'=> '...' , 'height'=> '...' , 'format'=> '...' , ), 'original' => array( 'href'=> '...' , 'width'=> '...' , 'height'=> '...' , 'format'=> '...' , ), ... ), ); ), ... );