PHP Demo Application - Source Code
/Application/Model/DataObjects/Language_Grid.php
<?php
/**
* Script Contents: Apeel_Application_Model_DataObjects_Language_Grid Class
* Extends Apeel_Application_Model_DataObjects_Language Class
* Implements Apeel_Framework_Model_DataObjects_Interfaces_GridData Interface
* @package Apeel_Application_Model_DataObjects
*/
/**
* Grid Data Object for Language
* which extends the main Data Object for Language
* 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_Language_Grid extends Apeel_Application_Model_DataObjects_Language 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 `film` WHERE `language`.`language_id` = `film`.`language_id`) +
(SELECT COUNT(*) FROM `film` WHERE `language`.`language_id` = `film`.`original_language_id`) > 0, '*', '') AS `language.link_status`,
`language`.`language_id` AS `language.language_id`,
`language`.`name` AS `language.name`,
DATE_FORMAT(`language`.`last_update`,'" . $dateFormat['mysql'] . " %H:%i') AS `language.last_update_formatted`
";
}
/**
* Return SQL FROM clause.
*
* @return string
*/
protected function getFrom() {
return
'
FROM
`language`
';
}
/**
* 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 'language.language_id';
}
/**
* Returns column definitions for the given index.
*
* @param integer $index
* @return array
*/
public function getGridColumns($index = '') {
$gridColumns = array(
0 => array('fieldname' => 'language.link_status', 'display' => '*', 'width' => '20', 'sortable' => true, 'align' => 'Center', 'type' => 'link_status'),
1 => array('fieldname' => 'language.name', 'display' => 'Name', 'width' => '180', 'sortable' => true, 'align' => 'Left', 'type' => 'text'),
2 => array('fieldname' => 'language.last_update_formatted', 'display' => 'Last Update', 'width' => '125', 'sortable' => true, 'align' => 'Center', 'type' => 'date', 'sortfield' => 'language.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' => 'language.name', 'display' => 'Name', 'editor' => 'text', 'nullable' => false)
);
// 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 'Language';
}
/**
* 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 '4e04fc24a5cccddd187d97baa86c22ee';
}
}
?>