[TYPO3-ect] tx_lib_tcaModel
Steve Ryan
stever at syntithenai.com
Mon Feb 12 00:01:59 CET 2007
and this as the next level.
followed by
tx_lib_tcaView($model), tx_lib_tcaFormView, tx_lib_tcaListView
implements ResultBrowser
at what point does this belong to tx_forms? The existing tx_forms, form
elements look good for importing into tx_lib_htmlElements and then used
in tcaView for rendering based on a switch of TCA config.type?
class tx_lib_tcaView extends tx_lib_viewBase {
function getHTMLFormInput($field) {
}
function getFieldValue($field){
}
}
<?php
require_once(t3lib_extMgm::extPath('div') . 'class.tx_div.php');
require_once(t3lib_extMgm::extPath('lib') . 'class.tx_lib_object.php');
require_once(t3lib_extMgm::extPath('lib') . 'class.tx_lib_modelBase.php');
// TODO - RELATIONSHIPS
// TODO -
class tx_lib_tcaModel extends tx_lib_modelBase {
var $TCA ;
var $relationShips;
// constructor calls parent and grabs TCA reference
function tx_lib_tcaModel($a=array(),$b=array()) {
// grab controller reference as a parameter ?
parent::tx_lib_object($a,$b);
// table name as a parameter ??
if (is_string($a)) {
$this->table=$a;
$this->loadTCA($a);
} else if (is_string($b)) {
$this->table=$b;
$this->loadTCA($b);
}
}
function setTable($val) {
parent::setTable($val);
$this->loadTCA($val);
}
function loadTCA($tables=array()) {
if (count($GLOBALS['TCA'])>0) {
if (!is_array($tables)) $tables=new
tx_lib_object(tx_div::explode($tables));
if ($tables->count()==0&&strlen(trim($this->table))>0)
$tables->append($this->table);
// do we need to fully load the columns of any tables ?
for ($tables->rewind(); $tables->valid(); $tables->next()) {
if (count($GLOBALS['TCA'][$this->current()]['columns'])==0) {
tx_div::loadTCATables($this->table);
}
}
// reassign updated copy
tslib_fe::includeTCA(); // ???? from admin int
$this->TCA=$GLOBALS['TCA'];
}
}
function setTCA($val) {
$this->TCA=$val;
}
function getTCA() {
return $this->TCA;
}
function getFieldTCA($fieldName) {
return $this->TCA[$this->table]['columns'][$fieldName];
}
function save($data=array()) {
parent::save($data);
}
function _update() {
// default tstamp
$tstampField=$this->TCA[$this->table]['ctrl']['tstamp'] ;
if (strlen(trim($tstampField))>0) $this-set($tstampField,time());
parent::_update();
}
function _insert() {
//default crdate,tstamp,be_user,fe_user_owner
// default crdate
$crdateField=$this->TCA[$this->table]['ctrl']['crdate'] ;
if (strlen(trim($crdateField))>0) $this-set($crdateField,time());
// default tstamp
$tstampField=$this->TCA[$this->table]['ctrl']['tstamp'] ;
if (strlen(trim($tstampField))>0) $this-set($tstampField,time());
parent::_insert();
}
function load($uid) {
parent::load($uid);
}
function _createWhereClause($criteria,$configuration) {
// apply extra filtering for hidden/deleted/start/stop
$cObj=$this->findCObject();
$where=parent::_createWhereClause($criteria,$configuration);
$where=$where?$where:' (1=1) ';
$where.=$cObj->enableFields($this->table);
return $where;
}
function delete($uid) {
// is there a deleted field to use instead of real delete
$deletedField=$this->TCA[$this->table]['ctrl']['delete'] ;
if (strlen(trim($deletedField))>0) {
$this-set($deletedField,1);
$this->save();
} else {
parent::delete($uid);
}
}
function setRelationships($val) {
$this->relationships=$val;
}
function getRelationships() {
return $this->relationships;
}
function saveRelationships() {
}
function loadRelationships() {
}
function deleteRelationships() {
}
function getOrderBy() {
// get default from TCA
if (strlen(trim($this->orderBy))==0)
$this->orderBy=$this->TCA['config']['sortby'];
return $this->orderBy;
}
function getLabelField() {
// from TCA or default uid
return
($this->TCA['config']['sortby']?$this->TCA['config']['sortby']:'uid') ;
}
function getLabel() {
return $this->get($this->getLabelField());
}
}
?>
More information about the TYPO3-team-extension-coordination
mailing list