Developing Economic Intelligence Application

with

and

Outlines
• About Economic Intelligence Application
– Overview

• Introduction to Kohana
– Why Kohana?

• Features in Kohana PHP
– Drivers, Helpers, Libraries – Controller, Model (ORM), View

• jQuery implementation • Sample codes

Intelligence Cycle
1 Planning & Direction 2 Collection

5 Dissemination 4 Analysis

3 3 Processing Processing

Analysis

Modules in EIDA
VISION MISSION OBJECTIVES STRATEGIES 1. PERSONAL 4. CHARTS 5. TABLES DASHBOARD 2. E-MAIL 6. MAPPING 3. DATASET 9. NEWS

7. QUERY 8. DOCUMENT

10. REPORTING

ANALYSIS 11. MOLAP

12. WORKSHEET

13. TIME

14. ENTITY

MULTI-DIMENSION DATASET 15. PROJECT 16. ITEM 17. GEOGRAPHY 21. FILE IMPORT 22. DATA LOAD 23. RSS AGGREGATE

18. MEASURE 24. HTML SELECT

19. DATA ENTRY

20. FILE UPLOAD

25. USER MANAGER

ACCESS CONTROL 26. DATASET MANAGER

27. LOG STATISTICS

Modules
• Developed with
– Kohana PHP – Web app framework – jQuery – JavaScript framework

What is Kohana PHP ?
• • • • A web application framework Designed for PHP 5.2 Fully Object Oriented Programming approach Uses MVC – Model View Controller architecture pattern

Kohana

THE SWIFT PHP5 FRAMEWORK

PHP

Why Kohana PHP ?
• Full support PHP 5.2 OOP API
– interfaces, abstracts, singletons, public, private, protected and automatic class loading. – All PHP5 magics available _get() _set() _destruct() etc… – More logical structure to apps

• Strict OOP & MVC coding as RAD tool • Cascading file system
– Allow Plug & Play MVC modules – Never touch the core.

• Built in ORM – Object Relational Model • Secured
– Say goodbye to SQL strings ! – Built with performance in minds.

– SQL execution escaped (prevent injection) – GET, POST, COOKIE cleaned automagically. (prevent XSS)

Driver… what is drivers?
• Kohana Driver:
– Cache Drivers:

– Collection of standard API with different backend – Uses abstract class as definition & implements – Database Drivers:

• Use cache engine which available on your server

– Image Drivers:

– APC, eAccelerator, Memcache, SQLite, Xcache, flat file

• Drivers Collection in Kohana
• Query Builder / ORM may connect to these database

• Module generating graphics portability enhanced by
– GD, ImageMagick, GraphicMagick

– Captcha Drivers:

– Session Drivers:

– MySQL/i, SQLite, Postgres, MsSQL

• Choose your captcha strategy preference
– Alpha, Black, Basic, Math, Riddle, Word …

• Session Driver handle session storage

– Payment Drivers

• Payments API support

– Database, Cookie or in Cache Engine

– Authorize, PayPal, Paypal Pro, Google Checkout, Trident, Trust Commerce, YourPay.

ORM Library
• ORM definition (in simple word) • API for create, read, update & delete
– Object Relational Mapping – PHP object property (class attr.) mapped to a table and fields – Attributes value in the object loaded automatically from database upon object construct – Values assigned to the object attributes can be saved easily – No SQL string. No writing joins. QueryBuilder do SQL queries silently. – – – – $has_one for one-to-one relationships $has_many for the parent side of a one-to-many relationship $belongs_to for the child side of a one-to-many relationship $has_and_belongs_to_many for many-to-many relationships

• Support table relationship (for normalized data)

• Speed up CRUD developments.

Example of Using ORM
$user = ORM::factory(‘user’); // creating an object

$user->name = ‘Sanda’; $user->password = ‘paS$w0rD’; $user->email = ‘fasha@mail.com’; // assigning new values $user->save(); // without INSERT INTO

//Get full src. at: http://software.krimnet.com/kohana

Cascading File System
• Enables plug-andplay modules in MVC environment.

All files merged in a folder at run-time

jQuery implementation with Kohana
• No specific JavaScript framework implementation in Kohana • Contributed module/helper projects
– manage JavaScript globally & cache. – JS/CSS Collector, Assets, Minify OR Media module – Keep JS/CSS files inside modules folder

Tips Handling JavaScript
• How to Keep MVC approach
– Separate static JavaScript with dynamic JavaScript – Treat JavaScript as View. – Put dynamic JavaScript in View object.
• Advantages
– Utilize JS collector – Minify object output on the fly

Inside View Template
File:veiws/grid_script.php <script> jQuery("#list2").jqGrid({ url:'<?=$url?>', datatype: "json", colNames: <?=$column_name?>, colModel: <?=$column_model?>, rowNum: <?=$row_num?>, rowList: <?=$row_list?>, pager: jQuery('#pager2'), sortname: 'id', viewrecords: true, sortorder: "desc", caption: "<?=$caption?>" }).navGrid('#pager2',{edit:false,add:false,del:false}); </script>

Pass dynamic vars. to View
$script = View::factory('grid_script') ->set('caption', $caption) ->set('url', $url) ->set('column_name', $column_name) ->set('column_model', $column_model) ->set('row_num', $row_num) ->set('row_list', $row_list);

Layout View
<html> <head> <title>Title</title> <link href="/kohana/assets/jqgrid/css/ui.jqgrid.css" media="all" rel="stylesheet" type="text/css" /> <link href="/kohana/assets/jqgrid/css/redmond/jquery-ui-1.7.1.custom.css" media="all" rel="stylesheet" type="text/css" /> </head> <body> <table id="list2" class="scroll"></table> <div id="pager2" class="scroll" style="text-align:center;"></div> <script src="/kohana/assets/jqgrid/js/jquery-1.3.2.min.js"></script> <script src="/kohana/assets/jqgrid/js/jquery-ui-1.7.1.custom.min.js"> </script> <script src="/kohana/assets/jqgrid/js/i18n/grid.locale-en.js"></script> <script src="/kohana/assets/jqgrid/js/jquery.jqGrid.js"></script> <?=$script ?> //equals to echo $script </body> </html>

Q&A
• Website: kohanaphp.com • Documentation: docs.kohanaphp.com • Community: forum.kohanaphp.com • Blog: http://software.krimnet.com/kohana

Extras

Kohana Controller
• URL: http://myapp.com/module/function/para1/para2/ … / • The URL mapped into controller file below • This file located at: /app_folder/modules/user/controllers/user.php

User_Controller
{

extends Controller

public function edit($para1, $para2, { // your code here echo ‘<html> <body>Output to browser</body> </html>’; } }

...)

Kohana Model (with ORM)
Eg: Table Users
id name password email

User_Model extends ORM { protected $table_name = ‘users’; } • User model located at /app_path/modules/user/models/user.php • Other optional properties available:
– $primary_key, $primary_val, $table_columns, $has_one, $has_many, ... (see documentation for more …)

ORM (Example – Load a table row)
id 2 name Fasha password ***** email fasha@xmail.com

http://myapps/user/view/2 User_Controller extends Controller { public function view($id) {

$user = ORM::factory(‘user’, $id);
// load row id=2 into $user without SELECT * FROM … WHERE … $pass = $user->password; // copying a field value echo $user->name; // echo a field value, output: Fasha echo $user->email; // echo a field value, output: fasha@xmail.com } }

ORM (Example – Edit a table row)
id 2 2 name Sanda Fasha password xxxxx ***** email sanda@mail.com fasha@xmail.com

http://myapps/user/edit/2 User_Controller extends Controller { public function edit($id) { $user = ORM::factory(‘user’, $id); // load row id=2 without SELECT * FROM ... $user->name = ‘Fasha’; // assigning new value $user->password = ‘paS$w0rD’; $user->email = ‘fasha@xmail.com’; } }

$user->save();

// skip UPDATE … TABLE … WHERE id=2

View Example
• http://myapps/user/show/2 • /modules/user/controllers/user.php
User_Controller extends Controller { public function show($id) { $user = ORM::factory(‘user’, $id); • /modules/user/views/ user_view.php <html> <body> <div id=“user”> <p>Name: <?=$name?> </p> <p>Email: <?=$email?> </p> </div> </body> </html>

View::factory(‘user_view’)
->set(‘name’, $user->name) ->set(‘email’, $user->email);

echo

} }

www.transformersgame.com

www.mypicsmap.com

tutlist.com

Why Kohana PHP ?
• Community support
– Official Forum: Active (1500 members) – Central Projects Repository: Active (40 projects) – Official Documentation: Sufficient

• Official & contributed extendable drivers
– Database, Cache, Auth, Session, Captcha, Image, Form Element …etc

• Ready for production
– Current release v2.3.2 (svn/trunk has the latest) – Ver 2.4 (on-going) … Ver 3.0 (in planning)

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer: Get 4 months of Scribd and The New York Times for just $1.87 per week!

Master Your Semester with a Special Offer from Scribd & The New York Times