Jump to content

Adding a printable view: Difference between revisions

From NusaATK
Ihcfan (talk | contribs)
No edit summary
Ihcfan (talk | contribs)
No edit summary
Line 24: Line 24:




Blah
The goal of the derived attribute is to handle rendering the record in both a popup window and on the edit/view pages. In this howto, only view mode is handled, since the primary goal is the display of a window suitable for printing.
 
Starting with the atkDummyAttribute, modify the display method.  In this case, I've modified display to execute a query and display the contents.
 
  /**
    * Display a record
    * Here it will only returns the text.
    * @param $record  Array with fields
    * @return Parsed string
    */
    function display($record)
    {
      $db = &atkGetDb();
   
      $query = &$db->createQuery();
      $query->addTable("stuff");
      $query->addJoin("item", "", "item.id = stuff.item_id", false);
      $query->addJoin("notes", "", "notes.id = item.notes_id", false);
      $query->addField("item.item");
      $query->addField("item.name");
      $query->addField("notes.note");
      $query->addField("stuff.name as sname");
      $query->addCondition("stuff.person_id = ".$record["id"]);
 
      $stuff = $db->getrows($query->buildSelect());
      $tbl = &atknew("atk.utils.atktablerenderer");
 
      $data = array();
      // Develop a table however you'd like it to display
 
      // Use cascading style sheets to alter the appearance.
      $tbl->setRowClass(1, "superbold");
      // ....
      // Create data
      for ($i=0, $_i=count($stuff); $i<$_i; $i++)
      {
        $row = array();
        $row[]="";
        $row[]=$stuff[$i]["..."];
        $row[]=$stuff[$i]["..."];
        $data[] = $row;
      }
 
      // render table.
      $output = $tbl->render($data, 0, "navpers");
      return $output;
    }
 
 





Revision as of 08:09, 15 October 2007

ATK Howto: Adding a printable view

Complexity: Medium
Author: ihcfan <ihcfan@braincookie.com>

List of other Howto's

Summary

In this howto you will create a popup window with altered format stripping away elements that interfere with cleanly rendering the information on a printer or other alternative output device.


Basic Process

I am sure there are many ways of achieving this, however this presents a method that I used, that worked for my application. There are four main development tasks to complete:

1. Develop a derived attribute capable of rendering the appropriate view.

2. Develop a node which uses the derived attribute.

3. Add a button to the node which pops up the the window.

4. Develop the appropriate template and style sheets if necessary.


Create Derived Attribute

The goal of the derived attribute is to handle rendering the record in both a popup window and on the edit/view pages. In this howto, only view mode is handled, since the primary goal is the display of a window suitable for printing.

Starting with the atkDummyAttribute, modify the display method. In this case, I've modified display to execute a query and display the contents.

  /**
   * Display a record
   * Here it will only returns the text.
   * @param $record  Array with fields
   * @return Parsed string
   */
   function display($record)
   {
     $db = &atkGetDb();
   
     $query = &$db->createQuery();
     $query->addTable("stuff");
     $query->addJoin("item", "", "item.id = stuff.item_id", false);
     $query->addJoin("notes", "", "notes.id = item.notes_id", false);
     $query->addField("item.item");
     $query->addField("item.name");
     $query->addField("notes.note");
     $query->addField("stuff.name as sname");
     $query->addCondition("stuff.person_id = ".$record["id"]);
     $stuff = $db->getrows($query->buildSelect());
     $tbl = &atknew("atk.utils.atktablerenderer");
     $data = array();
     // Develop a table however you'd like it to display
     // Use cascading style sheets to alter the appearance.
     $tbl->setRowClass(1, "superbold");
     // ....
     // Create data
     for ($i=0, $_i=count($stuff); $i<$_i; $i++)
     {
        $row = array();
        $row[]="";
        $row[]=$stuff[$i]["..."];
        $row[]=$stuff[$i]["..."];
        $data[] = $row;
     }
     // render table.
     $output = $tbl->render($data, 0, "navpers");
     return $output;
   }



Create New Node

Blah


Add Button

Blah


Create Templates

Blah


Try it Out

Blah