Extend sdk

  • View
    3.698

  • Download
    4

Embed Size (px)

DESCRIPTION

 

Text of Extend sdk

  • 1. Feature SDK / API
    Presentation By:
    Kumar Pratikpratikk@langoor.net

2. Overview: Feature Development
What a developer should know before coding?
How widgets work on editor?
How to create your own feature?
Creating your first feature ( Hello World! )
Adding components (widget) to your feature
SDK / API Quick Overview
Response from feature/widgets to editor & website
Form
Html
Code framework functions
Install
setProperty
getProperty
hasProperty
Zend DB API
3. What should you know before coding?
HTML & CSS
JavaScript (Jqueryframework)
PHP 5.3
MySQL
ZendDB
4. Youtube widget
5. Login using your
sign-up crendentials
6. After logging in, you will be re-directed to Dashboard as shown below.
Click on Features Manager to start Development of features
7. Creating your first feature (hello world)
Since widgets constitute a feature, a widget should be added only after adding the feature
click to add the details of the new feature
8. Feature Database
Every feature has its own database
When a feature is installed on a domain, it creates a new database (copying from the feature master database)
Developer can access the database using phpMyAdmin
A feature can have multiple widgets in it, and all the widgets will use the same database for accessing its data.
9. Feature Database Access database using phpMyAdmin
Once a feature is created, a new database is created for the feature with its credentials being displayed on features manager as shown.
10. Select the feature for the new widget
Click to create the new widget. Clicking on the create button re-directs to the feature manager dashboard
11. Public: Feature is visible to all the subdomains on extend.langoor.net
Private: features visible only to the owner of the subdomain.
Click edit to go to feature manager editor.
12. All the error log information associated with the feature can be accessed here
All the files related to the widgets are stored in the widgets folder
Thumbnail image for the feature which appears on the feature panel in langoor.net editor.
Main feature class
13. // feature.php- Feature Main Installer Class
// Class pratikHelloWorld extends baseFeature { -- You should not write the class name in your code this is added automatically
private $key = d21a868268f8a43b268ee4937a1d8161'; // key of the feature
var $db; // variable for storing database object
var $instance_id; // instance id of the feature
public function __construct($db, $instance_id = -1){ // feature should have 2 params in constructor, 1st database object (zendDb) & 2nd Instance Id
$this->db = $db;
$this->instance_id = $instance_id;
}
public function setInstanceId($instance_id){
$this->instance_id = $instance_id;
}
public function install($data = array()){ // this function is called once the install action is performed from the feature panel on the editor.
if(LFeature::setupComplete($this->key,$this->instance_id)){ // making the feature as installed to the editor / backend framework
$response = array();// response array is the main message which is passed to the editor to perform the required steps, please refer the response format for different type of possible message.
$response['done'] = 1;
$response['action'] = "openWidgetPopup";
$response['new_widgets'] = LWidget::getWidgetIdsByFeatureKey($this->key); // API for getting the widget ids from the feature
}else{
throw new Exception('Unable to Complete setup');
}
return $response;
}
//---------------- Developer Code ------------------
// }
Please read the comments for understanding the code better.
14. // pratikHelloWorldView/widget.php- Feature Main Installer Class
// Class pratikHelloWorldView extends baseWidget {- same as the feature class you should not write the class starting and ending.
//---------------- Developer Code ----------------
var $id;
public function __construct($id, $params=array(), $db){$this->db = $db; $this->id = $id;}
public function getId(){return $this->id;}
public function hasProperty(){return 0; } // to enable / disable the setting button on the widget
public function delete(){} // this function will be called, if widget is being delete from the page.
private function get(){}
public function getData(){}
public static function install($params = array()){ // this function is called when a user click on the widget to install on the page, currently this function is returning done = 1, ie installation completed.
$response['done'] =1;
$response['widget_instance_id'] = -1;
return $response;
}
public functiongetHtml($extra_class=array(),$extra_in_line_style=''){
// this is called after once the user click on preview/publish to display the page on the browser
$html = '

';
$html .= "Hello world!";
$html .= '

';
return $html;
}
public functiongetEditorHtml($extra_class=array(),$extra_in_line_style=''){
// its acts exactly as the above the only difference is editor will always call getEditorHtml for getting the widget data on the page. You can just call the gethtml function to send the same data. If you do not want a difference in live and preview version of the widget.
return $this->getHtml($extra_class,$extra_in_line_style);}
// }
15. Once the feature is saved, it appears in the feature panel of the editor.
16. Once the feature is installed, its constituent widgets appear in the widget panel.
17. 18. 19. SDK / API -Response formatcreating a form response (install/getProperty function)
$response = array();
$response['done'] = 0;
$response['action'] = "openDialog";
$response['dialogContent'] = array("title"=>'User Comment Widget',"contentType"=>'form',"formaction"=>'install',"content" => array("fields" => array(array( "label" => 'Name', "name" => 'name', "value" => '',"inputType" => 'input',"class" => 'required' // jQuery Validators ))),"buttonLabel"=>"Install","type" => "centered
);
20. SDK / API -Responsecreating a html response (install/getProperty function)
$response = array();
$response['done'] = 0;
$response['action'] = "openDialog";
$response['dialogContent'] = array("title"=>'User Comment Widget',"contentType"=>html',"content" => html content
This is a test content,"buttonLabel"=>"Install","type" => "centered
);
21. SDK / API -Responsefor opening widget panel (install/getProperty function)
$response = array();
$response['done'] =1;
$response['step'] = ++$step;
$response['widget_instance_id'] = $this->db->lastInsertId();
22. SDK / API-Responsecreating a html response with form (install/getProperty function)
$html =
html content

This is a test content

Name


Age



;
$response = array();
$response['done'] = 0;
$response['action'] = "openDialog";
$response['dialogContent'] = array("title"=>'User Comment Widget',"contentType"=>html',"content => $html,
"buttonLabel"=>Add Entry","type" => "centered
);
23. Creating a form handler for widget
// widget.php
Public function addcomment($params){
$params= $params[0];
$name = $params['name'];
$age= $params[age'];
$sql = "insert into `l_w_pratikHelloWorld_entry` (`name`, `age`) values (?,?)";
$res = $this->db->query($sql,array($name,$age));
return true;
}
24. Zend DB Sample Query
$stmt=$db->query(
'SELECT * FROM bugs WHERE reported_by = ? AND bug_status = ?',
array('goofy','FIXED')
);
$stmt=$db->query('SELECT * FROM bugs');
while($row=$stmt->fetch()){
echo$row['bug_description'];
}
$stmt=$db->query('SELECT * FROM bugs');
$rows=$stmt->fetchAll();
echo$rows[0]['bug_description'];
25. Thank you!
KumarPratik
pratikk@langoor.net