Extend sdk

3,891 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
3,891
On SlideShare
0
From Embeds
0
Number of Embeds
1,094
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Extend sdk

  1. 1. Feature SDK / API<br />Presentation By:<br />Kumar Pratikpratikk@langoor.net<br />
  2. 2. Overview: Feature Development<br />What a developer should know before coding?<br />How widgets work on editor?<br />How to create your own feature?<br />Creating your first feature ( Hello World! )<br />Adding components (widget) to your feature<br />SDK / API – Quick Overview<br />Response from feature/widgets to editor & website<br />Form <br />Html <br />Code framework functions<br />Install<br />setProperty<br />getProperty<br />hasProperty<br />Zend DB API<br />
  3. 3. What should you know before coding?<br />HTML & CSS<br />JavaScript (Jqueryframework)<br />PHP 5.3<br />MySQL <br />ZendDB<br />
  4. 4. Youtube widget<br />
  5. 5. Login using your <br />sign-up crendentials<br />
  6. 6. After logging in, you will be re-directed to Dashboard as shown below.<br />Click on Features Manager to start Development of features<br />
  7. 7. Creating your first feature (hello world)<br />Since widgets constitute a feature, a widget should be added only after adding the feature<br />click to add the details of the new feature<br />
  8. 8. Feature Database<br />Every feature has its own database<br />When a feature is installed on a domain, it creates a new database (copying from the feature master database)<br />Developer can access the database using phpMyAdmin<br />A feature can have multiple widgets in it, and all the widgets will use the same database for accessing its data.<br />
  9. 9. Feature Database Access database using phpMyAdmin<br />Once a feature is created, a new database is created for the feature with its credentials being displayed on features manager as shown.<br />
  10. 10. Select the feature for the new widget<br />Click to create the new widget. Clicking on the create button re-directs to the feature manager dashboard<br />
  11. 11. Public: Feature is visible to all the subdomains on extend.langoor.net<br />Private: features visible only to the owner of the subdomain.<br />Click edit to go to feature manager editor.<br />
  12. 12. All the error log information associated with the feature can be accessed here<br />All the files related to the widgets are stored in the widgets folder <br />Thumbnail image for the feature which appears on the feature panel in langoor.net editor.<br />Main feature class<br />
  13. 13. // feature.php - Feature Main Installer Class<br />// Class pratikHelloWorld extends baseFeature { -- You should not write the class name in your code this is added automatically<br /> private $key = ‘d21a868268f8a43b268ee4937a1d8161'; // key of the feature<br />var $db; // variable for storing database object<br />var $instance_id; // instance id of the feature<br /> public function __construct($db, $instance_id = -1){ // feature should have 2 params in constructor, 1st database object (zendDb) & 2nd Instance Id<br /> $this->db = $db; <br /> $this->instance_id = $instance_id;<br /> }<br /> public function setInstanceId($instance_id){<br /> $this->instance_id = $instance_id;<br /> }<br /> public function install($data = array()){ // this function is called once the install action is performed from the feature panel on the editor.<br /> if(LFeature::setupComplete($this->key,$this->instance_id)){ // making the feature as installed to the editor / backend framework<br /> $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.<br />$response['done'] = 1; <br /> $response['action'] = "openWidgetPopup";<br /> $response['new_widgets'] = LWidget::getWidgetIdsByFeatureKey($this->key); // API for getting the widget ids from the feature<br /> }else{<br /> throw new Exception('Unable to Complete setup');<br /> }<br /> return $response;<br /> }<br />//---------------- Developer Code ------------------ <br />// }<br />Please read the comments for understanding the code better.<br />
  14. 14. // pratikHelloWorldView/widget.php - Feature Main Installer Class<br />// Class pratikHelloWorldView extends baseWidget { - same as the feature class you should not write the class starting and ending.<br />//---------------- Developer Code ---------------- <br />var $id;<br />public function __construct($id, $params=array(), $db){ $this->db = $db; $this->id = $id;}<br />public function getId() { return $this->id; }<br />public function hasProperty() { return 0; } // to enable / disable the setting button on the widget<br />public function delete() { } // this function will be called, if widget is being delete from the page.<br />private function get() { }<br />public function getData() { }<br />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.<br /> $response['done'] = 1;<br /> $response['widget_instance_id'] = -1;<br /> return $response;<br />} <br />public functiongetHtml($extra_class=array(),$extra_in_line_style=''){ <br />// this is called after once the user click on preview/publish to display the page on the browser <br />$html = '<div style="width:100%; padding-bottom:10px;">';<br /> $html .= "Hello world!";<br /> $html .= '</div>';<br /> return $html;<br />}<br />public functiongetEditorHtml($extra_class=array(),$extra_in_line_style=''){ <br />// 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.<br />return $this->getHtml($extra_class,$extra_in_line_style);}<br />// }<br />
  15. 15. Once the feature is saved, it appears in the feature panel of the editor.<br />
  16. 16. Once the feature is installed, its constituent widgets appear in the widget panel.<br />
  17. 17.
  18. 18.
  19. 19. SDK / API - Response formatcreating a form response (install/getProperty function)<br />$response = array();<br />$response['done'] = 0;<br />$response['action'] = "openDialog";<br />$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“<br />);<br />
  20. 20. SDK / API - Responsecreating a html response (install/getProperty function)<br />$response = array();<br />$response['done'] = 0;<br />$response['action'] = "openDialog";<br />$response['dialogContent'] = array( "title"=>'User Comment Widget', "contentType"=>‘html', "content" => “<h2>html content</h2><br /> This is a test content”, "buttonLabel"=>"Install", "type" => "centered“<br /> );<br />
  21. 21. SDK / API - Responsefor opening widget panel (install/getProperty function)<br />$response = array();<br />$response['done'] = 1;<br />$response['step'] = ++$step;<br />$response['widget_instance_id'] = $this->db->lastInsertId();<br />
  22. 22. SDK / API - Responsecreating a html response with form (install/getProperty function)<br />$html = “<br /><h2>html content</h2><br /><br /> This is a test content <br /><form action=“addcomment”><table><br /> <tr> <td>Name</td><br /> <td><input type = “text” name=“name”></td><br /> </tr><tr><br /> <td>Age</td><br /> <td><input type = “text” name=“age” class=“requirednumber”></td><br /> </tr><br /></table></form><br />“;<br />$response = array();<br />$response['done'] = 0;<br />$response['action'] = "openDialog";<br />$response['dialogContent'] = array( "title"=>'User Comment Widget', "contentType"=>‘html', "content“ => $html,<br /> "buttonLabel"=>“Add Entry", "type" => "centered“<br /> );<br />
  23. 23. Creating a form handler for widget<br />// widget.php<br />Public function addcomment($params){<br /> $params= $params[0];<br /> $name = $params['name'];<br /> $age= $params[‘age'];<br /> $sql = "insert into `l_w_pratikHelloWorld_entry` (`name`, `age`) values (?,?)";<br />$res = $this->db->query($sql,array($name,$age));<br /> return true;<br />}<br />
  24. 24. Zend DB Sample Query<br />$stmt = $db->query(<br />            'SELECT * FROM bugs WHERE reported_by = ? AND bug_status = ?',<br />            array('goofy', 'FIXED')<br />        );<br />$stmt = $db->query('SELECT * FROM bugs');<br /> while ($row = $stmt->fetch()) {<br />    echo $row['bug_description'];<br />}<br />$stmt = $db->query('SELECT * FROM bugs');<br /> $rows = $stmt->fetchAll();<br /> echo $rows[0]['bug_description'];<br />
  25. 25. Thank you!<br />Kumar Pratik<br />pratikk@langoor.net<br />

×