154 lines
4.5 KiB
PHP
154 lines
4.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* This is the model class for table "mortgages".
|
|
*
|
|
* @property integer $id
|
|
* @property integer $building_id
|
|
* @property integer $program_id
|
|
* @property string $created_at
|
|
* @property string $updated_at
|
|
* @property boolean $newRecord
|
|
*/
|
|
class Mortgage implements ImportRecord
|
|
{
|
|
public $id;
|
|
public $building_id;
|
|
public $program_id;
|
|
public $created_at;
|
|
public $updated_at;
|
|
public $newRecord;
|
|
|
|
/**
|
|
* Mortgage constructor.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->newRecord = true;
|
|
}
|
|
|
|
|
|
public function save()
|
|
{
|
|
try {
|
|
if ($this->newRecord) {
|
|
if (!isset($this->id)) {
|
|
$sql = "INSERT INTO mortgages (program_id, building_id, created_at) VALUES ('" . $this->program_id .
|
|
"', '" . $this->building_id . "', NOW())";
|
|
} else {
|
|
$sql = "INSERT INTO mortgages (id, program_id, building_id, created_at) VALUES ('" . $this->id .
|
|
"', '" . $this->program_id . "', '" . $this->building_id . "', NOW())";
|
|
}
|
|
mysql_query($sql);
|
|
$err = mysql_errno();
|
|
if ($err > 0) {
|
|
echo $err;
|
|
return false;
|
|
}
|
|
if (!isset($this->id)) {
|
|
$this->id = mysql_insert_id();
|
|
}
|
|
} else {
|
|
$sql = "UPDATE mortgages SET program_id = '" . $this->program_id .
|
|
"', building_id = '" . $this->building_id . "', updated_at = NOW() WHERE id = '" . $this->id . "'";
|
|
mysql_query($sql);
|
|
$err = mysql_errno();
|
|
if ($err > 0) {
|
|
echo $err;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
} catch (Exception $e) {
|
|
echo $e->getMessage();
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public function getIsNewRecord()
|
|
{
|
|
return $this->newRecord;
|
|
}
|
|
|
|
public static function deleteAll($condition = '')
|
|
{
|
|
throw new Exception("deleteALL not implemented");
|
|
}
|
|
|
|
public static function className()
|
|
{
|
|
return get_called_class();
|
|
}
|
|
|
|
public static function findOne($id)
|
|
{
|
|
$sql = "SELECT * FROM mortgages WHERE id='$id'";
|
|
$rez = mysql_query($sql);
|
|
if (mysql_num_rows($rez)) {
|
|
$mortgage = new Mortgage();
|
|
$mortgage->newRecord = false;
|
|
$dbObject = mysql_fetch_array($rez);
|
|
$mortgage->id = $dbObject['id'];
|
|
$mortgage->program_id = $dbObject['program_id'];
|
|
$mortgage->building_id = $dbObject['building_id'];
|
|
$mortgage->created_at = $dbObject['created_at'];
|
|
$mortgage->updated_at = $dbObject['updated_at'];
|
|
|
|
return $mortgage;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static function findByBuildingIdAndBankId($buildingId, $bankId)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
public static function findByBuildingIdAndProgramId($buildingId, $programId)
|
|
{
|
|
$sql = "SELECT * FROM mortgages WHERE building_id='$buildingId' and program_id = '$programId'";
|
|
$rez = mysql_query($sql);
|
|
if (mysql_num_rows($rez)) {
|
|
$mortgage = new Mortgage();
|
|
$mortgage->newRecord = false;
|
|
$dbObject = mysql_fetch_array($rez);
|
|
$mortgage->id = $dbObject['id'];
|
|
$mortgage->program_id = $dbObject['program_id'];
|
|
$mortgage->building_id = $dbObject['building_id'];
|
|
$mortgage->created_at = $dbObject['created_at'];
|
|
$mortgage->updated_at = $dbObject['updated_at'];
|
|
|
|
return $mortgage;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static function findByBuildingId($buildingId)
|
|
{
|
|
$sql = "SELECT * FROM mortgages WHERE building_id='$buildingId'";
|
|
$rez = mysql_query($sql);
|
|
|
|
$mortgages = array();
|
|
|
|
if (mysql_num_rows($rez)) {
|
|
while ($dbObject = mysql_fetch_assoc($rez)) {
|
|
$mortgage = new Mortgage();
|
|
$mortgage->newRecord = false;
|
|
$mortgage->id = $dbObject['id'];
|
|
$mortgage->program_id = $dbObject['program_id'];
|
|
$mortgage->building_id = $dbObject['building_id'];
|
|
$mortgage->created_at = $dbObject['created_at'];
|
|
$mortgage->updated_at = $dbObject['updated_at'];
|
|
|
|
$mortgages[] = $mortgage;
|
|
}
|
|
}
|
|
|
|
return $mortgages;
|
|
}
|
|
|
|
}
|