newRecord = true; } public function save() { try { if ($this->newRecord) { if (!isset($this->id)) { $sql = "INSERT INTO subways (name, created_at) VALUES ('" . $this->name . "', NOW())"; } else { $sql = "INSERT INTO subways (id, name, created_at) VALUES ('" . $this->id . "', '" . $this->name . "', NOW())"; } 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 subways SET name = '" . $this->name . "', updated_at = NOW() 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 subways WHERE id='$id'"; $rez = mysql_query($sql); if (mysql_num_rows($rez)) { $subway = new Subway(); $subway->newRecord = false; $dbObject = mysql_fetch_array($rez); $subway->id = $dbObject['id']; $subway->name = $dbObject['name']; $subway->created_at = $dbObject['created_at']; $subway->updated_at = $dbObject['updated_at']; return $subway; } return null; } 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 subways WHERE rf_region_id = $region_sql ORDER BY name"; $rez = mysql_query($sql); $subways = array(); if (mysql_num_rows($rez) > 0) { while ($dbObject = mysql_fetch_assoc($rez)) { $subway = new Subway(); $subway->newRecord = false; $subway->id = $dbObject['id']; $subway->name = $dbObject['name']; $subway->created_at = $dbObject['created_at']; $subway->updated_at = $dbObject['updated_at']; $subways[] = $subway; } } return $subways; } }