public static function deleteWithAppointmentId($appointmentId) { try { $reports = ReportFetcher::retrieveAllWithAppointmentId($appointmentId); $dbConnection = DatabaseManager::getConnection(); try { $dbConnection->beginTransaction(); $prevTransFromParent = false; } catch (PDOException $e) { $prevTransFromParent = true; } foreach ($reports as $report) { $reportId = $report[self::DB_COLUMN_ID]; ConclusionWrapUpFetcher::delete($reportId); StudentBroughtAlongFetcher::delete($reportId); PrimaryFocusOfConferenceFetcher::delete($reportId); AppointmentHasStudentFetcher::disconnectReport($reportId); self::delete($reportId); } AppointmentFetcher::updateLabel($appointmentId, Appointment::LABEL_MESSAGE_ADMIN_DISABLED, Appointment::LABEL_COLOR_CANCELED); if (!$prevTransFromParent) { $dbConnection->commit(); } return true; } catch (Exception $e) { if (isset($dbConnection)) { $dbConnection->rollback(); } throw new Exception($e->getMessage()); } return false; }
$updateDone = Appointment::updateTerm($appointmentId, $studentsAppointmentData[0][UserFetcher::DB_TABLE . "_" . UserFetcher::DB_COLUMN_ID], $user, $_POST['dateTimePickerStart'], $_POST['dateTimePickerEnd'], $_POST['termId'], $studentsAppointmentData[0][AppointmentFetcher::DB_COLUMN_TERM_ID]) || $updateDone; if (!$updateDone) { throw new Exception("No new data inserted."); } } else { if (isUrlRqstngAppointmentCancelByTutor()) { AppointmentFetcher::updateLabel($appointmentId, Appointment::LABEL_MESSAGE_TUTOR_CANCELED, Appointment::LABEL_COLOR_CANCELED); } else { if (isUrlRqstngAppointmentNoShowByStudent()) { AppointmentFetcher::updateLabel($appointmentId, Appointment::LABEL_MESSAGE_STUDENT_NO_SHOW, Appointment::LABEL_COLOR_CANCELED); } else { if (isUrlRqstngAppointmentNoShowByTutor()) { AppointmentFetcher::updateLabel($appointmentId, Appointment::LABEL_MESSAGE_TUTOR_NO_SHOW, Appointment::LABEL_COLOR_CANCELED); } else { if (isUrlRqstngAppointmentEnable()) { AppointmentFetcher::updateLabel($appointmentId, Appointment::LABEL_MESSAGE_PENDING, Appointment::LABEL_COLOR_PENDING); } else { if (isBtnDeleteAppointmentPressed() || isBtnDeleteReportPrsd()) { if (!$user->isAdmin()) { header('Location: /error-403'); exit; } // Appointment::delete($id); if (isBtnDeleteReportPrsd()) { Report::deleteWithAppointmentId($appointmentId); } else { if (isBtnDeleteAppointmentPressed()) { Appointment::delete($appointmentId); $_SESSION['success'] = "Appointment with id {$appointmentId} successfully deleted."; header('Location: ' . BASE_URL . 'appointments/list'); exit;
<?php /** * Created by PhpStorm. * User: rdok * Date: 9/18/2014 * Time: 2:35 PM */ try { require __DIR__ . "/../public_html/app/config/app.php"; date_default_timezone_set('Europe/Athens'); // run script only during working hours every two hours if (!App::isWorkingDateTimeOn()) { exit; } $appointments = AppointmentFetcher::retrieveCmpltWithoutRptsOnCurTerms(); foreach ($appointments as $appointment) { $students = AppointmentHasStudentFetcher::retrieveStudentsWithAppointment($appointment[AppointmentFetcher::DB_COLUMN_ID]); foreach ($students as $student) { $reportId = ReportFetcher::insert($student[AppointmentHasStudentFetcher::DB_COLUMN_STUDENT_ID], $student[AppointmentHasStudentFetcher::DB_COLUMN_ID], $student[AppointmentHasStudentFetcher::DB_COLUMN_INSTRUCTOR_ID]); } AppointmentFetcher::updateLabel($appointment[AppointmentFetcher::DB_COLUMN_ID], Appointment::LABEL_MESSAGE_COMPLETE, Appointment::LABEL_COLOR_SUCCESS); // Mailer::sendTutorNewReportsCronOnly($appointment); } } catch (Exception $e) { App::storeError($e); exit; }