PHP Demo Application - Source Code
/Application/Model/DataObjects/City_Grid.php
<?php
/**
* Script Contents: Apeel_Application_Model_DataObjects_City_Grid Class
* Extends Apeel_Application_Model_DataObjects_City Class
* Implements Apeel_Framework_Model_DataObjects_Interfaces_GridData Interface
* @package Apeel_Application_Model_DataObjects
*/
/**
* Grid Data Object for City
* which extends the main Data Object for City
* 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_City_Grid extends Apeel_Application_Model_DataObjects_City 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 `address` WHERE `city`.`city_id` = `address`.`city_id`) > 0, '*', '') AS `city.link_status`,
`city`.`city_id` AS `city.city_id`,
`city`.`city` AS `city.city`,
`city`.`country_id` AS `city.country_id`,
`country_id__country`.`country` AS `city__country_id__desc`,
DATE_FORMAT(`city`.`last_update`,'" . $dateFormat['mysql'] . " %H:%i') AS `city.last_update_formatted`
";
}
/**
* Return SQL FROM clause.
*
* @return string
*/
protected function getFrom() {
return
'
FROM
`city`
LEFT JOIN `country` AS `country_id__country`
ON `country_id__country`.`country_id` = `city`.`country_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 'city.city_id';
}
/**
* Returns column definitions for the given index.
*
* @param integer $index
* @return array
*/
public function getGridColumns($index = '') {
$gridColumns = array(
0 => array('fieldname' => 'city.link_status', 'display' => '*', 'width' => '20', 'sortable' => true, 'align' => 'Center', 'type' => 'link_status'),
1 => array('fieldname' => 'city.city', 'display' => 'City', 'width' => '180', 'sortable' => true, 'align' => 'Left', 'type' => 'text'),
2 => array('fieldname' => 'city__country_id__desc', 'display' => 'Country', 'width' => '200', 'sortable' => true, 'align' => 'Left', 'type' => 'text'),
3 => array('fieldname' => 'city.last_update_formatted', 'display' => 'Last Update', 'width' => '125', 'sortable' => true, 'align' => 'Center', 'type' => 'date', 'sortfield' => 'city.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' => 'city.city', 'display' => 'City', 'editor' => 'text', 'nullable' => false),
2 => array('fieldname' => 'city.country_id', 'display' => 'Country', 'editor' => 'autocomplete', 'nullable' => false, 'dataObject' => '00114ad9b6b91d17529ba1407c252bad', 'matchingMethod' => 'CONTAINS')
);
// 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 array(array('column' => '1', 'direction' => 'asc'));
}
/**
* 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 'City';
}
/**
* 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 '8427eac72695a1485bd5667bba8e0325';
}
}
?>