247 lines
8.7 KiB
PHP
247 lines
8.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
/**
|
||
|
|
* This is the model class for table "builders".
|
||
|
|
*
|
||
|
|
* @property integer $id
|
||
|
|
* @property string $name
|
||
|
|
* @property float $fee
|
||
|
|
* @property float $discount_fee
|
||
|
|
* @property string $pay_period
|
||
|
|
* @property string $adv
|
||
|
|
* @property string $logo
|
||
|
|
* @property string $note
|
||
|
|
* @property string $created_at
|
||
|
|
* @property string $updated_at
|
||
|
|
* @property boolean $newRecord
|
||
|
|
*/
|
||
|
|
class Builder implements ImportRecord
|
||
|
|
{
|
||
|
|
public $id;
|
||
|
|
public $name;
|
||
|
|
public $fee;
|
||
|
|
public $discount_fee;
|
||
|
|
public $pay_period;
|
||
|
|
public $logo;
|
||
|
|
public $adv;
|
||
|
|
public $note;
|
||
|
|
public $created_at;
|
||
|
|
public $updated_at;
|
||
|
|
public $newRecord;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Builder constructor.
|
||
|
|
*/
|
||
|
|
public function __construct()
|
||
|
|
{
|
||
|
|
$this->newRecord = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function save()
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
if ($this->newRecord) {
|
||
|
|
if (!isset($this->id)) {
|
||
|
|
$sql = "INSERT INTO builders (name, created_at, adv, pay_period, fee, discount_fee, logo, note) VALUES ('" . $this->name . "', NOW(), '"
|
||
|
|
. $this->adv . "', '" . $this->pay_period . "', '" . $this->fee .
|
||
|
|
"', '" . $this->discount_fee . "', '" . $this->logo . "', '" . $this->note . "')";
|
||
|
|
} else {
|
||
|
|
$sql = "INSERT INTO builders (id, name, created_at, adv, pay_period, fee, discount_fee, logo, note) VALUES ('" . $this->id . "', '"
|
||
|
|
. $this->name . "', NOW(), '" . $this->adv . "', '" . $this->pay_period .
|
||
|
|
"', '" . $this->fee . "', '" . $this->discount_fee . "', '" . $this->logo . "', '" . $this->note . "')";
|
||
|
|
}
|
||
|
|
mysql_query($sql);
|
||
|
|
$err = mysql_errno();
|
||
|
|
if ($err > 0) {
|
||
|
|
echo mysql_error();
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
if (!isset($this->id)) {
|
||
|
|
$this->id = mysql_insert_id();
|
||
|
|
}
|
||
|
|
} else {
|
||
|
|
$sql = "UPDATE builders SET name = '" . $this->name . "', adv = '" . $this->adv .
|
||
|
|
"', pay_period = '" . $this->pay_period . "', fee = '" . $this->fee .
|
||
|
|
"', discount_fee = '" . $this->discount_fee . "', logo = '" . $this->logo .
|
||
|
|
"', updated_at = NOW(), note = '" . $this->note . "' WHERE id = '" . $this->id . "'";
|
||
|
|
mysql_query($sql);
|
||
|
|
$err = mysql_errno();
|
||
|
|
if ($err > 0) {
|
||
|
|
echo mysql_error();
|
||
|
|
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 builders WHERE id='$id'";
|
||
|
|
$rez = mysql_query($sql);
|
||
|
|
if (mysql_num_rows($rez)) {
|
||
|
|
$builder = new Builder();
|
||
|
|
$builder->newRecord = false;
|
||
|
|
$dbObject = mysql_fetch_array($rez);
|
||
|
|
$builder->id = $dbObject['id'];
|
||
|
|
$builder->name = $dbObject['name'];
|
||
|
|
$builder->fee = $dbObject['fee'];
|
||
|
|
$builder->discount_fee = $dbObject['discount_fee'];
|
||
|
|
$builder->adv = $dbObject['adv'];
|
||
|
|
$builder->note = $dbObject['note'];
|
||
|
|
$builder->logo = $dbObject['logo'];
|
||
|
|
$builder->pay_period = $dbObject['pay_period'];
|
||
|
|
$builder->created_at = $dbObject['created_at'];
|
||
|
|
$builder->updated_at = $dbObject['updated_at'];
|
||
|
|
|
||
|
|
return $builder;
|
||
|
|
}
|
||
|
|
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function count($searchName)
|
||
|
|
{
|
||
|
|
if ($searchName != null) {
|
||
|
|
$sql = "SELECT count(id) FROM builders WHERE LOWER(name) like LOWER('%$searchName%')";
|
||
|
|
} else {
|
||
|
|
$sql = "SELECT count(id) FROM builders";
|
||
|
|
}
|
||
|
|
$rez = mysql_query($sql);
|
||
|
|
|
||
|
|
return mysql_result($rez,0);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function countActive($searchName)
|
||
|
|
{
|
||
|
|
if ($searchName != null) {
|
||
|
|
$sql = "SELECT count(id) FROM builders WHERE LOWER(name) like LOWER('%$searchName%') and id in (select builder_id from blocks where id in (select block_id from apartments))";
|
||
|
|
} else {
|
||
|
|
$sql = "SELECT count(id) FROM builders WHERE id in (select builder_id from blocks where id in (select block_id from apartments))";
|
||
|
|
}
|
||
|
|
$rez = mysql_query($sql);
|
||
|
|
|
||
|
|
return mysql_result($rez,0);
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function search($searchName, $from, $to)
|
||
|
|
{
|
||
|
|
if ($searchName != null) {
|
||
|
|
$sql = "SELECT * FROM builders WHERE LOWER(name) like LOWER('%$searchName%') LIMIT $from, $to";
|
||
|
|
} else {
|
||
|
|
$sql = "SELECT * FROM builders LIMIT $from, $to";
|
||
|
|
}
|
||
|
|
$rez = mysql_query($sql);
|
||
|
|
$builders = array();
|
||
|
|
if (mysql_num_rows($rez) > 0) {
|
||
|
|
while($dbObject = mysql_fetch_assoc($rez)) {
|
||
|
|
$builder = new Builder();
|
||
|
|
$builder->newRecord = false;
|
||
|
|
$builder->id = $dbObject['id'];
|
||
|
|
$builder->name = $dbObject['name'];
|
||
|
|
$builder->fee = $dbObject['fee'];
|
||
|
|
$builder->discount_fee = $dbObject['discount_fee'];
|
||
|
|
$builder->adv = $dbObject['adv'];
|
||
|
|
$builder->note = $dbObject['note'];
|
||
|
|
$builder->logo = $dbObject['logo'];
|
||
|
|
$builder->pay_period = $dbObject['pay_period'];
|
||
|
|
$builder->created_at = $dbObject['created_at'];
|
||
|
|
$builder->updated_at = $dbObject['updated_at'];
|
||
|
|
$builders[] = $builder;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return $builders;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function searchActive($searchName, $from, $to)
|
||
|
|
{
|
||
|
|
if ($searchName != null) {
|
||
|
|
$sql = "SELECT * FROM builders WHERE LOWER(name) like LOWER('%$searchName%') and id in (select builder_id from blocks where id in (select block_id from apartments)) LIMIT $from, $to";
|
||
|
|
} else {
|
||
|
|
$sql = "SELECT * FROM builders WHERE id in (select builder_id from blocks where id in (select block_id from apartments)) LIMIT $from, $to";
|
||
|
|
}
|
||
|
|
$rez = mysql_query($sql);
|
||
|
|
$builders = array();
|
||
|
|
if (mysql_num_rows($rez) > 0) {
|
||
|
|
while($dbObject = mysql_fetch_assoc($rez)) {
|
||
|
|
$builder = new Builder();
|
||
|
|
$builder->newRecord = false;
|
||
|
|
$builder->id = $dbObject['id'];
|
||
|
|
$builder->name = $dbObject['name'];
|
||
|
|
$builder->fee = $dbObject['fee'];
|
||
|
|
$builder->discount_fee = $dbObject['discount_fee'];
|
||
|
|
$builder->adv = $dbObject['adv'];
|
||
|
|
$builder->note = $dbObject['note'];
|
||
|
|
$builder->logo = $dbObject['logo'];
|
||
|
|
$builder->pay_period = $dbObject['pay_period'];
|
||
|
|
$builder->created_at = $dbObject['created_at'];
|
||
|
|
$builder->updated_at = $dbObject['updated_at'];
|
||
|
|
$builders[] = $builder;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return $builders;
|
||
|
|
}
|
||
|
|
|
||
|
|
public static function getElementsList($temp_region)
|
||
|
|
{
|
||
|
|
$user = new User;
|
||
|
|
$user->get($_SESSION['id']);
|
||
|
|
|
||
|
|
if(isset($temp_region)) {
|
||
|
|
$region_sql = $temp_region;
|
||
|
|
} else {
|
||
|
|
$region_sql = $user->region_rf_id;
|
||
|
|
}
|
||
|
|
|
||
|
|
$sql = "SELECT * FROM builders WHERE id in (
|
||
|
|
select builder_id from blocks
|
||
|
|
INNER JOIN regions re on re.id = blocks.region_id
|
||
|
|
where blocks.id in (select block_id from apartments)
|
||
|
|
and re.rf_region_id = $region_sql
|
||
|
|
) ORDER BY name";
|
||
|
|
$rez = mysql_query($sql);
|
||
|
|
|
||
|
|
$builders = array();
|
||
|
|
if (mysql_num_rows($rez) > 0) {
|
||
|
|
while($dbObject = mysql_fetch_assoc($rez)) {
|
||
|
|
$builder = new Builder();
|
||
|
|
$builder->newRecord = false;
|
||
|
|
$builder->id = $dbObject['id'];
|
||
|
|
$builder->name = $dbObject['name'];
|
||
|
|
$builder->fee = $dbObject['fee'];
|
||
|
|
$builder->discount_fee = $dbObject['discount_fee'];
|
||
|
|
$builder->adv = $dbObject['adv'];
|
||
|
|
$builder->note = $dbObject['note'];
|
||
|
|
$builder->logo = $dbObject['logo'];
|
||
|
|
$builder->pay_period = $dbObject['pay_period'];
|
||
|
|
$builder->created_at = $dbObject['created_at'];
|
||
|
|
$builder->updated_at = $dbObject['updated_at'];
|
||
|
|
$builders[] = $builder;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
return $builders;
|
||
|
|
}
|
||
|
|
}
|