ReportModel.php 1.3 KB

12345678910111213141516171819202122232425262728
  1. <?php
  2. class ReportModel extends Model {
  3. protected static $table_name = "regen_reports";
  4. // Создаёт запись в таблице
  5. public static function create($subject_id, $work_type, $number, $notice, $start_markup) {
  6. $db = Database::getConnection();
  7. $stm = $db->prepare("INSERT INTO ".static::$table_name." (subject_id, work_type, work_number, notice, date_create, markup) VALUES (:subject_id, :work_type, :work_number, :notice, datetime('now', 'localtime'), :markup)");
  8. $stm->bindValue(":subject_id", $subject_id);
  9. $stm->bindValue(":work_type", $work_type);
  10. $stm->bindValue(":work_number", $number);
  11. $stm->bindValue(":notice", $notice);
  12. $stm->bindValue(":markup", $start_markup);
  13. $stm->execute();
  14. return $db->lastInsertRowID();
  15. }
  16. // Обновляет запись в таблице
  17. public static function update($report) {
  18. $db = Database::getConnection();
  19. $stm = $db->prepare("UPDATE ".static::$table_name." SET notice=:notice,work_number=:work_number,work_type=:work_type WHERE id=:id");
  20. $stm->bindValue(":id", $report['id']);
  21. $stm->bindValue(":notice", $report['notice']);
  22. $stm->bindValue(":work_number", $report['work_number']);
  23. $stm->bindValue(":work_type", $report['work_type']);
  24. $stm->execute();
  25. }
  26. }