Creating a BlockModule

From PeopleAggregator

Jump to: navigation, search

Creating a block Module in People Aggregator is very simple. Follow these steps:

1. Create Folder at following location:

web/BlockModules/YourModule

2. Make a block module class as YourModule.php and save it in the directory "web/BlockModules/YourModule"

3. Now there are two parts for this - rendering html code and putting data to that code.

4. Create a class YourModule. This class should extend Module class.

5. Sample code :


<?php
global $path_prefix;

require_once "$path_prefix/api/Category/Category.php";

require_once "$path_prefix/ext/Group/Group.php";

require_once "$path_prefix/web/includes/classes/Pagination.php";


class YourModule extends Module {
  public $outer_template = 'outer_public_side_module.tpl';//define the container
  public $uid, $Paging;
  public $page_links, $page_prev, $page_next, $page_count;//pagination vars set here

  function __construct() {
    $this->title = 'My Module';// define title of YourModule
    $this->main_block_id = "mod_your_module";// define this variable - this is the class name that will should be defined in the concerned css file for styling.
  }
  
  public function get_links() {//use this function to populate data
    //Write code to get the list or what ever content you need to put in the module
    // This may include call to api
    //api is code library that deal with database - pa/api/YourAPI/YourAPI.php
    // You can define your own library for the model
    $links = YourAPI::get_your_links();
    return $links;
  }

  function render() {//use this function to get the html part

    $this->links = $this->get_links();
    if (sizeof($this->links)) {
      $this->view_all_url = "$base_url/view_all.php?uid=".$this->uid;// not mandatory -> only signifies if you have link to other page- for viewing all of the links
    }
    $this->inner_HTML = $this->generate_inner_html ();// this function fetches the inner data
    $content = parent::render();// this renders the html
    return $content;
  }

  function generate_inner_html () {//this function generates the html part of the page
    $tmp_file = dirname(__FILE__).'/side_inner_public.tpl';// inner html that needs to be displayed
    $inner_html_gen = & new Template($tmp_file);// creating template 
    $inner_html_gen->set('links', $this->links);//set vars for this template
    $inner_html = $inner_html_gen->fetch();//fetch the inner template
    return $inner_html;
  }
 
}
?>

Here what we have done is this: 1. we made a class for module 2. we get the links from api 3. we feed these links for putting in inner data 4. setting variables for inner data

Related links:

Personal tools