MCIS/UA PHP Training 2003 Chapter 7b Hands-on Application - - PowerPoint PPT Presentation

mcis ua
SMART_READER_LITE
LIVE PREVIEW

MCIS/UA PHP Training 2003 Chapter 7b Hands-on Application - - PowerPoint PPT Presentation

MCIS/UA PHP Training 2003 Chapter 7b Hands-on Application Development Continued Query Builder The query builder element was designed to allow clients to perform ad hoc queries. Still under development - expect potential changes in the


slide-1
SLIDE 1

PHP Training 2003 Chapter 7b Hands-on Application Development Continued

MCIS/UA

slide-2
SLIDE 2

Query Builder

  • The query builder element was designed to allow clients to

perform ad hoc queries.

  • Still under development - expect potential changes in the

short term.

image

slide-3
SLIDE 3

Query Builder

  • >
slide-4
SLIDE 4

Query Builder

  • The Query Builder has the following hierarchy:

query_builder query_builder_fields query_builder_field . . . query_builder_data

do

slide-5
SLIDE 5

Query Builder element

  • The query builder element is added using the add_element

method $qb =& $body->add_element('query_builder', params)

  • params is a associative array of attributes:

name - name of the query builder submit_handler - URL to direct to when submit is pressed query_builder - 'on' or 'off' report_builder - 'on' or 'off'

do

slide-6
SLIDE 6

Query Builder element

search.php

<?php $body =& $presentation->add_body(); $qb =& $body->add_element("query_builder", array( "name" => "orgs_query", "submit_handler" => "search.php", "query_builder" => "on", "report_builder" => "on")); display($presentation, "Search Organizations"); ?> query_build_fields

slide-7
SLIDE 7

Query Builder Fields

  • query builder fields must be enclosed in a query_builder_fields

element $qbf =& $qb->add_element('query_builder_fields', params)

  • params is a associative array of attributes:

default_table - default table to use for query_builder_field elements

do

slide-8
SLIDE 8

Query Builder Fields

search.php <?php $body =& $presentation->add_body(); $qb =& $body->add_element("query_builder", array( "name" => "orgs_query", "submit_handler" => "search.php", "query_builder" => "on", "report_builder" => "on")); $qbf =& $qb->add_element("query_builder_fields", array("default_table" => "orgs"));

display($presentation, "Search Organizations");

?>

query_build_field

slide-9
SLIDE 9

Query Builder Field

  • query_builder_field elements are used to describe your table

structure to the query builder $qbf->add_element('query_builder_field', params, display)

  • >
slide-10
SLIDE 10

Query Builder Field

  • params is a associative array of attributes:

name - column name table - table the column is located in input_type - type of data - currently only text and list sortable - '0' or '1' - if no report section, specifies that this field can be used for sorting convert - allows conversion of the data list_source - array of data to be used with list input_type suppress_search - '0' or '1' - suppress from search section suppress_report - '0' or '1' - suppress from reporting section format - format for data (dates only) display_format - format for the output (XSLT format string) input_hint - hint for the user on the format of the data default_criteria - starting criteria in the search section

do

slide-11
SLIDE 11

Query Builder Field

search.php <?php [...] $qbf =& $qb->add_element("query_builder_fields", array("default_table" => "orgs")); $qbf->add_element("query_builder_field", array( "name"=>"shortname", "input_type"=>"text"), "Short Name"); $qbf->add_element("query_builder_field", array( "name"=>"description", "input_type"=>"text"), "Description"); $qbf->add_element("query_builder_field", array( "name"=>"advisor", "input_type"=>"text"), "Advisor");

display($presentation, "Search Organizations");

?>

query_builder_data

slide-12
SLIDE 12

Query Builder Data

  • A query_builder_data element is required at after your field

definitions. $qb->add_element('query_builder_data')

  • Handles processing, caching, cleanup, etc.
  • >
slide-13
SLIDE 13

Query Builder Data

search.php <?php [...] $qbf =& $qb->add_element("query_builder_fields", array("default_table" => "orgs")); [...] $qbf->add_element("query_builder_field", array( "name"=>"advisor", "input_type"=>"text"), "Advisor"); $qb->add_element("query_builder_data");

display($presentation, "Search Organizations");

?>

reporting

slide-14
SLIDE 14

Processing the report

  • The report should be processed if

$_REQUEST['query_builder_name']['run'] or $_REQUEST['query_report_name']['navigation']['start_ record'] is defined

  • >
slide-15
SLIDE 15

Processing the report

  • The select class of the database library was designed

specifically to work with the query builder

  • The select class contains the following methods:

tables() - defines the tables used by your select add_limit() - defines intelligent limits (where clause) report_from() - handles query from query builder execute() - executes the query add_output() - defines additional tabulator attributes

do

slide-16
SLIDE 16

Processing the report

search.php <?php [...] $qb->add_element("query_builder_data"); if ($_REQUEST['orgs_query']['run'] || $_REQUEST['orgs_query_output']['navigation']['start_record']) { $select = $dbh->select(); $select->tables('orgs'); $select->report_from($_REQUEST['orgs_query']); $select->execute(); $select->add_output($body, array( "title"=>"Organizations", "name"=>"orgs_query_output")); } display($presentation, "Search Organizations"); ?>

convert

slide-17
SLIDE 17

Debugging databases

search.php <?php [...] $select = $dbh->select(); $select->db->statement_tracking = true; [...] $body->add_element('para','','<sourcecode>' . htmlentities(wordwrap($select->db->statements())) . '</sourcecode>');

  • >
slide-18
SLIDE 18

Processing the report

search.php <?php [...] $qbf =& $qb->add_element("query_builder_fields", array("default_table" => "orgs")); $qbf->add_element("query_builder_field", array( "name"=>"shortname", "input_type"=>"text", "convert"=>"all:lowercase"), "Short Name"); $qbf->add_element("query_builder_field", array( "name"=>"description", "input_type"=>"text", "convert"=>"all:lowercase"), "Description"); $qbf->add_element("query_builder_field", array( "name"=>"advisor", "input_type"=>"text", "convert"=>"all:lowercase"), "Advisor");

default_criteria

slide-19
SLIDE 19

Processing the report

search.php <?php [...] $qbf->add_element("query_builder_field", array( "name"=>"advisor", "input_type"=>"text", "default_criteria"=>"eq", "convert"=>"both:lowercase"), "Advisor"); display($presentation, "Search Organizations"); ?>

date fields

slide-20
SLIDE 20

Processing the report

search.php <?php [...] $fields->add_element("query_builder_field", array( "name"=>"startdate", "input_type"=>"text", "convert"=>"value:date", "format"=>"%m/%d/%Y", "input_hint"=>"e.g. 1/15/2003"), "Start Date"); $fields->add_element("query_builder_field", array( "name"=>"enddate", "input_type"=>"text", "convert"=>"value:date", "format"=>"%m/%d/%Y", "input_hint"=>"e.g. 1/15/2003"), "End Date");

display($presentation, "Search Organizations"); advisors

slide-21
SLIDE 21

Processing the report

search.php <?php [...] $advisors = $dbh->queryall_list( 'select unique advisor, name from orgs,person where advisor=uniqueId'); $fields->add_element("query_builder_field", array( "name"=>"advisor", "input_type"=>"list", "list_source" => $advisors), "Advisor"); display($presentation, "Search Organizations"); ?>

  • >
slide-22
SLIDE 22

Processing the report

search.php <?php [...] $fields->add_element("query_builder_field", array( "name"=>"advisor", "input_type"=>"list", "list_source" => $advisors, "suppress_report" => "1"), "Advisor"); $fields->add_element("query_builder_field", array( "name"=>"advisorname", "table"=>"person", "column" => "name", "suppress_search" => "1"), "Advisor"); [...] $select->tables('orgs','person'); $select->add_limit('orgs.advisor = person.uniqueid');

debug

slide-23
SLIDE 23

Query Builder Futures

  • The following have been discussed as future

enhancements to Query Builder

  • Cleanup interface
  • Improved input controls (date, validation, etc.)
  • Default values and default report fields
  • Saved queries and reports
  • Other output options (CSV, PDF, etc.)
  • Query Builder Class - simplified programmer

interface

  • >
slide-24
SLIDE 24

Logging out

  • The end_session() function can be used to end a

session.

  • The function returns true on success or false on

failure.

do

slide-25
SLIDE 25

Logging out

Application.php <?php [...]

function addnav(&$presentation) {

$navmenu = array("Home" => "index.php",

"View" => "view.php", "Search" => "search.php", "Logout" => "logout.php"); $presentation->add_navigation($navmenu); $suptext = array('For help, please contact the '. '<link href="http://www.muohio.edu/supportdesk/">MCIS Support Desk</link>'); $presentation->add_supplemental($suptext); $relmenu = array( array("title" => "MCIS Home Page", "content" => "The main MCIS webpage", "href" => "http://www.muohio.edu/mcis/"),

  • >
slide-26
SLIDE 26

Logging Out

logout.php <?php $body =& $presentation->add_body(); if (end_session()) { $body->add_element('para',NULL,'You have successfully logged out.'); } else { $body->add_element('para',NULL, 'An unexpected error has occurred. You may not have been logged out.'); } display($presentation, "Logout"); ?>

leftovers

slide-27
SLIDE 27

Application Leftovers

  • The application developed in class was a simple
  • example. In a real application, the following should be

done differently:

  • Better error handling:

print "An error occurred";

  • New Organizations, Delete Organizations
  • WAS enabled

'was_enabled' => '1'

  • Better organization
  • separate organization logic into it's own file
  • classes/OOP
  • Possibly cache database results

end

slide-28
SLIDE 28

Questions?

slide-29
SLIDE 29

Library change

  • The attribute() method has been retired.
  • We used the attribute() method in view.php

$modifiable = $auth->check_authorization("PHP Training", "general", "modify"); $table =& $body->add_element('tabulator', array( 'title' => "Organizations", 'name' => "orgs", 'navigation' => 'on', 'record_count' => $recordCount, 'start_record' => $start, 'show_records' => $show, 'sort_by' => $sort_by, 'sort_direction' => $sort_direction, 'link_using' => ($modifiable === true ? 'shortname' : '') ));

tabulator_row