PHP Demo Application - Source Code
/Application/Model/DataObjects/Customer.php
<?php
/**
* Script Contents: Apeel_Application_Model_DataObjects_Customer Class
* Extends Apeel_Application_Model_DataObjects_Connection Class
* @package Apeel_Application_Model_DataObjects
*/
/**
* Main Data Object for Customer
* which manipulates data derived from one or more database tables.
*
* 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_Customer extends Apeel_Application_Model_DataObjects_Connection {
/**
* Return SQL SELECT clause.
*
* @return string
*/
protected function getSelect() {
$dateFormat = Apeel_Framework_Model_Libraries_Data::getClientDateFormat();
return
"
SELECT
`customer`.`customer_id` AS `customer.customer_id`,
`customer`.`store_id` AS `customer.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 `store_id__store.desc`,
`customer`.`first_name` AS `customer.first_name`,
`customer`.`last_name` AS `customer.last_name`,
`customer`.`email` AS `customer.email`,
`customer`.`address_id` AS `customer.address_id`,
`address_id__address`.`address` AS `address_id__address.desc`,
`customer`.`active` AS `customer.active`,
`customer`.`create_date` AS `customer.create_date`,
DATE_FORMAT(`customer`.`last_update`,'" . $dateFormat['mysql'] . " %H:%i') AS `customer.last_update`
";
}
/**
* Return SQL FROM clause.
*
* @return string
*/
protected function getFrom() {
return
'
FROM
`customer`
LEFT JOIN `store` AS `store_id__store`
ON `store_id__store`.`store_id` = `customer`.`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`
LEFT JOIN `address` AS `address_id__address`
ON `address_id__address`.`address_id` = `customer`.`address_id`
';
}
/**
* Return shorthand PDO field type for given field.
* s = PDO::PARAM_STRING
* i = PDO::PARAM_INT
* b = PDO::PARAM_BOOL
* l = PDO::PARAM_LOB
*
* @param string $field
* @return string
*/
public function getFieldDefinition($field) {
$definitions =
array
(
'customer.customer_id' => 'i',
'customer.store_id' => 'i',
'customer__store_id__desc' => 's',
'customer.first_name' => 's',
'customer.last_name' => 's',
'customer.email' => 's',
'customer.address_id' => 'i',
'customer__address_id__desc' => 's',
'customer.active' => 'b',
'customer.create_date' => 's',
'customer.last_update' => 's'
)
;
// Check if requested field exists in the array.
return Apeel_Framework_Controller_Libraries_Input::getArrayValueByIndexMustExist($definitions, $field, 'Field Definitions');
}
/**
* Stores blob and filename fieldnames for Binary Objects.
* Leave Array empty if none for this Data Object.
*
* @param integer $index
* @return array
*/
public function getBinaryObjectDefinitions($index) {
$definitions = NULL;
// Check if requested field exists in the array.
return Apeel_Framework_Controller_Libraries_Input::getArrayValueByIndexMustExist($definitions, $index, 'Binary Object Definitions');
}
/**
* Returns an array containing definitions of Multi Linked Objects
* (many-to-many relationships).
*
* return @array
*/
public function getMultiLinkedObjects() {
return NULL;
}
/**
* 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 'customer.customer_id';
}
/**
* Returns a human-readable description of this Data Object
*
* @return string
*/
public function getDataObjectName() {
return 'Customer';
}
/**
* Returns the name of the main table represented by this Data Object.
*
* @return string
*/
public function getMainTableName() {
return 'customer';
}
}
?>