src/Generator/templates/dao_object.mustache
<?php
/* This file is generated by the open source Parm Generator. https://github.com/cassell/Parm */
{{#namespaceClassSyntax}}
{{namespaceClassSyntax}}
{{/namespaceClassSyntax}}
use \Parm\Config;
class {{className}}DaoObject extends \Parm\DataAccessObject implements {{className}}Table
{
use {{className}}TableFunctions;
{{#id.exists}}{{#id.isInteger}}
/**
* Get the ID (Primary Key) of the object
* @return integer|null ID of the record in the database. null if a new record
*/
public function getId()
{
return $this->getIntFieldValue($this->getIdField());
}
/**
* Set the ID (Primary Key) of the object
* @param int $id
*/
public function setNewObjectId($id)
{
$this->setIntFieldValue($this->getIdField(),$id);
$this->setupAsNewObject();
}
/**
* @return bool
*/
public function isAutoIncremented()
{
{{#id.isAutoIncremented}}
return true;
{{/id.isAutoIncremented}}
{{^id.isAutoIncremented}}
return false;
{{/id.isAutoIncremented}}
}
{{/id.isInteger}}{{/id.exists}}
{{#id.exists}}{{^id.isInteger}}
/**
* Get the ID (Primary Key) of the object
* @return string|null ID of the record in the database. null if a new record
*/
public function getId()
{
return $this->getFieldValue($this->getIdField());
}
/**
* Set the ID (Primary Key) of the object
* @param string $id
*/
public function setNewObjectId($id)
{
$this->setFieldValue($this->getIdField(),$id);
$this->setupAsNewObject();
}
/**
* @return bool
*/
public function isAutoIncremented()
{
return false;
}
{{/id.isInteger}}{{/id.exists}}
{{^id.exists}}
/**
* Get the ID (Primary Key) of the object
* @throws \Parm\Exception\GetFieldValueException
*/
public function getId()
{
throw new \Parm\Exception\GetFieldValueException("There is no id field on this table.");
}
/**
* @return bool
*/
public function isAutoIncremented()
{
return false;
}
{{/id.exists}}
{{#columns}}
{{#isPrimaryKey}}
{{#id.isCalledId}}
{{#typeInt}}
/**
* Set {{Type}} field {{tableName}}.{{Field}} in logical database "{{databaseName}}"
* @param int|null $val
*/
public function set{{FieldCase}}($val)
{
$this->setNewObjectId($val);
}
{{/typeInt}}
{{#typeString}}
/**
* Set {{Type}} field {{tableName}}.{{Field}} in logical database "{{databaseName}}"
* @param string|null $val
*/
public function set{{FieldCase}}($val)
{
$this->setNewObjectId($val);
}
{{/typeString}}
{{/id.isCalledId}}
{{^id.isCalledId}}
{{#typeInt}}
/**
* Set the ID (Primary Key) of the object
* @param int $id
*/
public function setId($id)
{
$this->setNewObjectId($id);
}
/**
* Set {{Type}} field {{tableName}}.{{Field}} in logical database "{{databaseName}}"
* @param int|null $val
*/
public function set{{FieldCase}}($val)
{
$this->setNewObjectId($val);
}
/**
* Get {{Type}} field {{tableName}}.{{Field}} from logical database "{{databaseName}}"
* @return int|null
*/
public function get{{FieldCase}}()
{
return $this->getId();
}
{{/typeInt}}
{{#typeString}}
/**
* Set the ID (Primary Key) of the object
* @param string $id
*/
public function setId($id)
{
$this->setNewObjectId($id);
}
/**
* Set {{Type}} field {{tableName}}.{{Field}} in logical database "{{databaseName}}"
* @param string|null $val
*/
public function set{{FieldCase}}($val)
{
$this->setNewObjectId($val);
}
/**
* Get {{Type}} field {{tableName}}.{{Field}} from logical database "{{databaseName}}"
* @return string|null
*/
public function get{{FieldCase}}()
{
return $this->getId();
}
{{/typeString}}
{{/id.isCalledId}}
{{/isPrimaryKey}}
{{^isPrimaryKey}}
{{#typeDatetime}}
/**
* Set {{Type}} field {{tableName}}.{{Field}} in logical database "{{databaseName}}"
* @param string|\DateTime|int|timestamp $val
*/
public function set{{FieldCase}}($val)
{
$this->setDatetimeFieldValue(self::{{AllCaps}}_COLUMN,$val);
}
/**
* Get {{Type}} field {{tableName}}.{{Field}} from logical database "{{databaseName}}"
* @param string $format optional Defaults to MySQL formatted Datetime YYYY-MM-DD HH:MM:SS
* @return string
*/
public function get{{FieldCase}}($format = null)
{
return $this->getDatetimeFieldValue(self::{{AllCaps}}_COLUMN,$format);
}
/**
* Get {{Type}} field {{tableName}}.{{Field}} from logical database "{{databaseName}}" as a DateTime object
* @return \DateTime
*/
public function get{{FieldCase}}DateTimeObject()
{
return $this->getDatetimeObjectFromField(self::{{AllCaps}}_COLUMN,Config::getDatetimeStorageFormat());
}
{{/typeDatetime}}
{{#typeDate}}
/**
* Set {{Type}} field {{tableName}}.{{Field}} in logical database "{{databaseName}}"
* @param string|\DateTime|int|timestamp|null $val
* @return string|null MySQL formatted Datetime YYYY-MM-DD
*/
public function set{{FieldCase}}($val)
{
$this->setDateFieldValue(self::{{AllCaps}}_COLUMN,$val);
}
/**
* Get {{Type}} field {{tableName}}.{{Field}} from logical database "{{databaseName}}"
* @param string|null $format optional Defaults to MySQL formatted Date YYYY-MM-DD
* @return string|null
*/
public function get{{FieldCase}}($format = null)
{
return $this->getDateFieldValue(self::{{AllCaps}}_COLUMN,$format);
}
/**
* Get {{Type}} field {{tableName}}.{{Field}} from logical database "{{databaseName}}" as a DateTime object
* @return \DateTime|null
*/
public function get{{FieldCase}}DateTimeObject()
{
return $this->getDatetimeObjectFromField(self::{{AllCaps}}_COLUMN,$this->getFactory()->getDateStorageFormat());
}
{{/typeDate}}
{{#typeInt}}
/**
* Set {{Type}} field {{tableName}}.{{Field}} in logical database "{{databaseName}}"
* @param string|int|null $val
*/
public function set{{FieldCase}}($val)
{
$this->setIntFieldValue(self::{{AllCaps}}_COLUMN,$val);
}
/**
* Get {{Type}} field {{tableName}}.{{Field}} from logical database "{{databaseName}}"
* @return int|null
*/
public function get{{FieldCase}}()
{
return $this->getIntFieldValue(self::{{AllCaps}}_COLUMN);
}
{{/typeInt}}
{{#typeBoolean}}
/**
* Set {{Type}} field {{tableName}}.{{Field}} in logical database "{{databaseName}}"
* @param string|int|bool|null $val
*/
public function set{{FieldCase}}($val)
{
$this->setBooleanFieldValue(self::{{AllCaps}}_COLUMN,$val);
}
/**
* Get {{Type}} field {{tableName}}.{{Field}} from logical database "{{databaseName}}"
* @return bool|null
*/
public function get{{FieldCase}}()
{
return $this->getBooleanFieldValue(self::{{AllCaps}}_COLUMN);
}
{{/typeBoolean}}
{{#typeNumeric}}
/**
* Set {{Type}} field {{tableName}}.{{Field}} in logical database "{{databaseName}}"
* @param string|int|null $val
*/
public function set{{FieldCase}}($val)
{
$this->setNumericalFieldValue(self::{{AllCaps}}_COLUMN,$val);
}
/**
* Get {{Type}} field {{tableName}}.{{Field}} from logical database "{{databaseName}}"
* @return float|null
*/
public function get{{FieldCase}}()
{
return $this->getNumericalFieldValue(self::{{AllCaps}}_COLUMN);
}
{{/typeNumeric}}
{{#typeString}}
/**
* Set {{Type}} field {{tableName}}.{{Field}} in logical database "{{databaseName}}"
* @param string|null $val
*/
public function set{{FieldCase}}($val)
{
$this->setFieldValue(self::{{AllCaps}}_COLUMN,$val);
}
/**
* Get {{Type}} field {{tableName}}.{{Field}} from logical database "{{databaseName}}"
* @return string|null
*/
public function get{{FieldCase}}()
{
return $this->getFieldValue(self::{{AllCaps}}_COLUMN);
}
{{/typeString}}
{{/isPrimaryKey}}
{{/columns}}
}