CSCI399 Autumn Session 2015 Assignment 4: Zend framework

• Aims
• Objectives • Example
• Task
• Submission

Aims

CSCI399 Autumn Session 2015

Assignment 4: Zend framework

10 marks

This assignment will give you experience with the construction of web applications based on the “Front Controller” design pattern as realized through the Zend framework.

Objectives

You are to implement a (simplified) PHP based application that supposedly runs a web site for a theatre company. The objectives are for you to:

  • Gain an understanding of frameworks that implement the “Front Controller” design pattern.
  • Learn how to implement applications in PHP that exploit the Zend framwork. Note: data tables that you construct for this assignment will be used in later assignments.

Example

An example NetBeans project is supplied in /share/cs-pub/399/A4 (also via web). This project builds a Zend 1.11 application that illustrates features such as access control of resources and HTML5 input. You should start by experimenting with this example.

You will of course have to change things such as file paths in the .htaccess file (you need to supply the path to your directory, not mine), and the database password in application.ini.

The example is simply meant to let you quickly explore a Zend project that should work with Ubuntu 14, Apache 2.4, and MySQL. Don’t try creating your assignment 4 solution by cut-and-paste editing of the code – changes to things like names of Controllers and Actions just don’t work well! (There are some hidden configuration files. If you change an action such as “doA” to a meaningful name like “doCreateShow”, the build system may get confused.) Just use the example as a working prototype. For your assignment, you should create a completely new project defining your Controllers and Actions through the Zend scripts.

Example – main issues addressed

Problem of “IndexController”

Apache 2.4 has some optimisations and smarts relating to “indexing” of directories. Unfortunately, these break the operation of Zend’s IndexController! (The interaction is subtle. It

occurs during the application of the re-write rules that are used to route all requests via the index.php “front controller”. If the request is asking for an action by the IndexController, the term “index” will appear in the path – and Apache will promptly change this before applying the rewrite rules.)

The supplied project has a .htaccess file that fixes the problem. (Took me a couple of days of work to identify the problem and find a fix; there isn’t anything at stackoverflow about this.) The modified .htaccess file has an extra directive telling Apache not to try its fancy processing of directory indexes.

Problem of “HTML5” input fields

The Zend 1 framework only supports HTML4 input fields – it does not have definitions for all the modern input types such as “date”, “color”, “number”, “range”, etc. The newer Zend 2 framework defines these input types but they have not been retrofitted to Zend 1.

The “Enrise” company did define new input classes for HTML5 (https://enrise.com/2010/12/html5-zend-framework-form-elements ). Unfortunately, Enrise essentially created a fork of Zend 1 with changes to many other components and their HTML5 input elements depend on these other changes that they have made. Consequently, their classes don’t help much.

Of course, most of the new HTML5 input types are just minor variations of <input type= ‘text’ …>. In the example provided, I have defined a simple class extending Zend’s text form element; my class can be used to create most of the new HTML5 input types. The example form in the project illustrates usage of my class.

Example – operation

Do nothing much

Just a place holder action with the auto-generated view file

HTML5 form

(The form has some custom Javascript code invoked on submit that checks that end date >= start date.)

Submit form – echoes back inputs

(Form definition includes some filters – e.g. one removing spaces from the title! It also has validation checks. Browser will do partial validation for HTML5 elements; more done in server code. The validation rules for the number input define a different range from those in the browser.)

List movies

The project has table definitions for two MySQL tables. The first table is for a collection of movies; the second table has standard login data with user-name, role, full-name. (Simplified, only a single role allowed to a user.)

The List movies option does a dump of the movie table, ordering output by year of movie.

Do privileged action

Illustrating access control – attempt to use privileged action should be blocked.

Login

After login, identity should be displayed and privileged actions allowed.

Example project

The project supplies my class definitions in its “library”. ACL and PLUGIN contain classes for access control. These are the classes that appear in the Photomania example from the lectures. The classes in Element and View/Helper are my extensions that allow for use of some HTML5 form elements. These files (with identical directory structure and naming) should be copied into your A4 project.

The project adds some actions to the standard IndexController and ErrorController supplied by Zend. The DataController has the action for accessing the movies data table; the models/DbTable has a class that Zend/PDO will use to retrieve data.

Task – the “Entertainment Centre” website

The “Entertainment Centre” used as example in this application was inspired by the Sydney Opera House and the example data use Opera House shows.

The Entertainment Centre has four venues – an Opera theatre, a Concert hall, a Playhouse, and a Studio. There are many kinds of entertainment event presented in these venues. Entertainment Centre management refers to them as “Presentations” and uses the catagories ‘Drama’, ‘Film’, ‘Opera’, ‘Jazz’, ‘World Music’, ‘Ballet’, ‘Recital’, ‘Concert’, ‘Choral’, ‘Contemporary Dance’, ‘Comedy’, and ‘Children’. A “Presentation” will have a season (possibly one day, more typically a couple of weeks, sometimes months), there will be some number of matinee and evening performances for each presentation.

The Entertainment Centre requires a web-site that presents the presentations scheduled. The web-site will allow prospective clients to search for presentations of specified type(s) in a specified time period, e.g. concert in June. The site is to respond with a list showing summary details of selected presentations; each summary will contain a link to more detailed information about presentations.

The site uses a database that has tables characterizing the presentations, the schedule of performances, and detailed information (pictures and accompanying text copy) relating to presentations.

The components used by the general public will simply run queries against these tables and display selected data. Other components will be used by Entertainment Centre support staff to enter data into the tables. More senior staff can schedule presentations; clerical staff are limited to adding supplementary data to scheduled presentations.

Walkthrough overview of website

Welcome

There should be a simple welcome page with links that allow visitors to reach a search page and staff to login.

Search

The search form has input fields that allow a user to constrain the search to select only presentations (shows) at a particular venue, or of a particular type, along with a date range.

Search results

A successful search will result in a list of show titles – these act as links to more detailed information. (A simple apology page is shown if there are no shows that satisfy the user supplied constraints).

Show details

A user can follow the link to get more details of the presentation:

Staff login

Senior staff schedule a presentation

The top part of the form has fields (mostly standard Zend_Form_Elements, apart from the date fields that are HTML5 style). These allow the staff member to set:

Show identifier (primary key)
Title
Venue (selection list, options Opera, Concert, Studio, Playhouse) Type (selection list, options Drama … Childrens)
Start of season and end of season dates

Company Description
Set of performances

The lower part of the form has controls for adding performances. Performances are either matinee or evening, and have a specific date. Javascript coding is used to handle the “Add performance” button. Performance details are copied into the (readonly) textarea used for performances. The Javascript code also validates the performance data, making sure that it lies between the specified start and end of season dates.

Further validation checks are performed in the server code. If the data are valid, a new performance record is created and a simple response page is displayed.

Adding supplementary information to a presentation record

This option is available to senior staff and clerical staff.

I chose not to use a Zend form here. Instead, my .phtml file uses HTML markup (and associated Javascript) recycled from assignment 3.

The form allows a user to enter a show identifier, and then add any number of “info items”. Each “info item” consists of a small picture and some text.

When the “info items” have been added, the “Add details” action will send the supplementary data to the server where they will be used to created records in the database.

The response is an acknowledgement and redisplay of the data entry form (defaulting to the same show identifier).

Some hints

Data tables

You can use mine

(Pictures are converted to URL data format and stored as “medium text”.)

Use of dbAdapter or Zend’s ORM

Many of the data base operations required in this assignment are easily handled by having the a Zend dbAdapter run a simple select, or insert operation as defined by an SQL string.

Retrieval of a complete show record can usefully exploit the Zend/PDO approach to object- relational-mapping.

Zend project in Netbeans

Something like the following:

The project will need access control code, and HTML5 code, from the example.

A variety of controllers, forms, models, and views will need to be defined.

Submission

The due date for submission will be announced in lectures; provisionally set for Friday May 9th.

You are to submit a report with:

  • An overview of the application
  • Your PHP classes, .phtml view template files, Javascript, and CSS files.
  • Summary data showing the structure of your Netbeans project
  • Evidence for the system working.

    turnin

    For CSCI399, assignments are submitted electronically via the turnin system. For this assignment you submit your assignment via the command:

    turnin -c csci399 -a 4 A4.pdf
    

    Late submissions would be submitted as:

    turnin -c csci399 -a 4late A4.pdf
    

    Remember, turnin only works when you are logged in to the main banshee undergraduate server machine. Transfer your report file to banshee using an ftp client. Then login via ssh and run the turnin program.

    Mark distribution

    Overall presentation and appearance of Web site – 2 marks Evidence for everything working – 2 marks
    Netbeans project information – 1 mark
    Code – 5 marks