PHP Demo Application - Source Code
/Application/Model/DataObjects/Inventory_Grid.php
<?php
/**
* Script Contents: Apeel_Application_Model_DataObjects_Inventory_Grid Class
* Extends Apeel_Application_Model_DataObjects_Inventory Class
* Implements Apeel_Framework_Model_DataObjects_Interfaces_GridData Interface
* @package Apeel_Application_Model_DataObjects
*/
/**
* Grid Data Object for Inventory
* which extends the main Data Object for Inventory
* and provides specific functionality for Data Grids, including all lookup
* values.
*
* The core abstract class contains all the PDO code for connecting to the
* database, reading and writing data.
*
* This concrete class contain the specifics of which tables/fields to read,
* what kind of editor should be used with each field (e.g. text box, dropdown,
* autocomplete etc) and could represent (for example) the data required to
* populate a data entry form, or a grid, or to populate a drop down list, or
* any other use you can think of.
*
* The structure of Data Objects is based on the Template Design Pattern.
*
* @package Apeel_Application_Model_DataObjects
* @version 1.1.0
* @author John W. King (email: contact@apeelframework.net)
* @copyright City Business Logic Limited 2001-2011
* @license Dual MIT / GNU Lesser General Public License Version 3
*/
class Apeel_Application_Model_DataObjects_Inventory_Grid extends Apeel_Application_Model_DataObjects_Inventory implements Apeel_Framework_Model_DataObjects_Interfaces_GridData {
/**
* Return SQL SELECT clause.
*
* @return string
*/
protected function getSelect() {
$dateFormat = Apeel_Framework_Model_Libraries_Data::getClientDateFormat();
return
"
SELECT
IF((SELECT COUNT(*) FROM `rental` WHERE `inventory`.`inventory_id` = `rental`.`inventory_id`) > 0, '*', '') AS `inventory.link_status`,
`inventory`.`inventory_id` AS `inventory.inventory_id`,
`inventory`.`film_id` AS `inventory.film_id`,
`film_id__film`.`title` AS `inventory__film_id__desc`,
`inventory`.`store_id` AS `inventory.store_id`,
CONCAT(`store_id__store__manager_staff_id__staff`.`first_name`, ' ', `store_id__store__manager_staff_id__staff`.`last_name`, ' - ', `store_id__store__address_id__address`.`address`) AS `inventory__store_id__desc`,
DATE_FORMAT(`inventory`.`last_update`,'" . $dateFormat['mysql'] . " %H:%i') AS `inventory.last_update_formatted`
";
}
/**
* Return SQL FROM clause.
*
* @return string
*/
protected function getFrom() {
return
'
FROM
`inventory`
LEFT JOIN `film` AS `film_id__film`
ON `film_id__film`.`film_id` = `inventory`.`film_id`
LEFT JOIN `store` AS `store_id__store`
ON `store_id__store`.`store_id` = `inventory`.`store_id`
LEFT JOIN `staff` AS `store_id__store__manager_staff_id__staff`
ON `store_id__store`.`manager_staff_id` = `store_id__store__manager_staff_id__staff`.`staff_id`
LEFT JOIN `address` AS `store_id__store__address_id__address`
ON `store_id__store`.`address_id` = `store_id__store__address_id__address`.`address_id`
';
}
/**
* Returns a string or an array containing one or more fieldnames that form
* the Primary key that identifies a unique row in this Data Object.
*
* @return string | array
*/
public function getPrimarykey() {
return 'inventory.inventory_id';
}
/**
* Returns column definitions for the given index.
*
* @param integer $index
* @return array
*/
public function getGridColumns($index = '') {
$gridColumns = array(
0 => array('fieldname' => 'inventory.link_status', 'display' => '*', 'width' => '20', 'sortable' => true, 'align' => 'Center', 'type' => 'link_status'),
1 => array('fieldname' => 'inventory__film_id__desc', 'display' => 'Film', 'width' => '200', 'sortable' => true, 'align' => 'Left', 'type' => 'text'),
2 => array('fieldname' => 'inventory__store_id__desc', 'display' => 'Store', 'width' => '200', 'sortable' => true, 'align' => 'Left', 'type' => 'text'),
3 => array('fieldname' => 'inventory.last_update_formatted', 'display' => 'Last Update', 'width' => '125', 'sortable' => true, 'align' => 'Center', 'type' => 'date', 'sortfield' => 'inventory.last_update')
);
// Check if requested column exists in the array.
return Apeel_Framework_Controller_Libraries_Input::getArrayValueByIndexMustExist($gridColumns, $index, 'Grid Columns');
}
/**
* Returns editor definitions for the given index.
*
* Data Grids contain a dropdown list of fields that can be used to filter
* the data. These definitions specify which editor to use for the user
* to select the value.
*
* @param integer $index
* @return array
*/
public function getEditors($index = NULL) {
$editorFields = array(
1 => array('fieldname' => 'inventory.film_id', 'display' => 'Film', 'editor' => 'autocomplete', 'nullable' => false, 'dataObject' => '6cb555d4c4d37148b2590ef443605d95', 'matchingMethod' => 'CONTAINS'),
2 => array('fieldname' => 'inventory.store_id', 'display' => 'Store', 'editor' => 'dropdown', 'nullable' => false, 'dataObject' => '3f66ab7aa96528dae1912358a6e3708a')
);
// Check if requested column exists in the array.
return Apeel_Framework_Controller_Libraries_Input::getArrayValueByIndexMustExist($editorFields, $index, 'Editors');
}
/**
* Returns an array containing details of the default Sort columns.
*
* @return array
*/
public function getDefaultSortColumns() {
return NULL;
}
/**
* Returns human readable description of the data represented by this Data
* Object, used as a title on the Grid.
*
* @return string
*/
public function getTitle() {
return 'Inventory';
}
/**
* Returns Hash value for this Data Object. The hash value can be passed
* around in public areas such as Javascript or on the URI without
* revealing the name of the actual Data Object to the end user.
*
* @return string
*/
public function getHash() {
return 'e9c9924109b6d683f15f08d47762bb66';
}
}
?>