add event to calendar
This commit is contained in:
@@ -13,6 +13,7 @@ use App\Models\InvoiceModel;
|
|||||||
use App\Models\InvoiceEventModel;
|
use App\Models\InvoiceEventModel;
|
||||||
use App\Models\ClassSectionModel;
|
use App\Models\ClassSectionModel;
|
||||||
use App\Models\PaymentModel;
|
use App\Models\PaymentModel;
|
||||||
|
use App\Models\CalendarModel;
|
||||||
use Config\Database;
|
use Config\Database;
|
||||||
#use ???
|
#use ???
|
||||||
use App\Controllers\View\InvoiceController;
|
use App\Controllers\View\InvoiceController;
|
||||||
@@ -127,6 +128,45 @@ class EventController extends ResourceController
|
|||||||
'created_by' => session()->get('user_id'),
|
'created_by' => session()->get('user_id'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
if ($eventId && $this->request->getPost('add_to_calendar')) {
|
||||||
|
$calendarModel = new CalendarModel();
|
||||||
|
|
||||||
|
$title = trim((string)$this->request->getPost('event_name'));
|
||||||
|
$date = (string)$this->request->getPost('expiration_date');
|
||||||
|
$schoolYear = (string)$this->request->getPost('school_year');
|
||||||
|
$semester = (string)$this->request->getPost('semester');
|
||||||
|
|
||||||
|
if ($title !== '' && $date !== '' && $schoolYear !== '') {
|
||||||
|
$data = [
|
||||||
|
'title' => $title,
|
||||||
|
'description' => (string)$this->request->getPost('description'),
|
||||||
|
'event_type' => 'Event',
|
||||||
|
'date' => $date,
|
||||||
|
'notify_parent' => $this->request->getPost('notify_parent') ? 1 : 0,
|
||||||
|
'notify_teacher' => $this->request->getPost('notify_teacher') ? 1 : 0,
|
||||||
|
'notify_admin' => $this->request->getPost('notify_admin') ? 1 : 0,
|
||||||
|
'no_school' => 0,
|
||||||
|
'school_year' => $schoolYear,
|
||||||
|
'semester' => $semester ?: $this->semester,
|
||||||
|
];
|
||||||
|
if (!$calendarModel->supportsEventType()) {
|
||||||
|
unset($data['event_type']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$dupQuery = $calendarModel
|
||||||
|
->where('school_year', $data['school_year'])
|
||||||
|
->where('date', $data['date'])
|
||||||
|
->where('title', $data['title']);
|
||||||
|
if ($calendarModel->supportsEventType() && isset($data['event_type'])) {
|
||||||
|
$dupQuery = $dupQuery->where('event_type', $data['event_type']);
|
||||||
|
}
|
||||||
|
$existing = $dupQuery->first();
|
||||||
|
if (!$existing) {
|
||||||
|
$calendarModel->save($data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return redirect()->to('/administrator/events')->with('success', 'Event created successfully');
|
return redirect()->to('/administrator/events')->with('success', 'Event created successfully');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -56,9 +56,56 @@
|
|||||||
<input type="text" name="school_year" class="form-control" required>
|
<input type="text" name="school_year" class="form-control" required>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="card mb-3">
|
||||||
|
<div class="card-header">School Calendar</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<div class="form-check mb-2">
|
||||||
|
<input class="form-check-input" type="checkbox" id="add_to_calendar" name="add_to_calendar" value="1">
|
||||||
|
<label class="form-check-label" for="add_to_calendar">
|
||||||
|
Add this event to the school calendar
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="calendar_recipients" class="ms-3" style="display:none;">
|
||||||
|
<div class="mb-2 fw-semibold">Visible On Calendars</div>
|
||||||
|
<div class="d-flex flex-wrap gap-3">
|
||||||
|
<label class="form-check-label">
|
||||||
|
<input class="form-check-input me-1" type="checkbox" name="notify_parent" value="1" checked>
|
||||||
|
Parents
|
||||||
|
</label>
|
||||||
|
<label class="form-check-label">
|
||||||
|
<input class="form-check-input me-1" type="checkbox" name="notify_teacher" value="1" checked>
|
||||||
|
Teachers
|
||||||
|
</label>
|
||||||
|
<label class="form-check-label">
|
||||||
|
<input class="form-check-input me-1" type="checkbox" name="notify_admin" value="1" checked>
|
||||||
|
Admins
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-text">If none are selected, the event is visible to everyone.</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<button type="submit" class="btn btn-success">Create Event</button>
|
<button type="submit" class="btn btn-success">Create Event</button>
|
||||||
<a href="<?= site_url('administrator/events') ?>" class="btn btn-secondary">Cancel</a>
|
<a href="<?= site_url('administrator/events') ?>" class="btn btn-secondary">Cancel</a>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<?= $this->endSection() ?>
|
<?= $this->endSection() ?>
|
||||||
|
|
||||||
|
<?= $this->section('scripts') ?>
|
||||||
|
<script>
|
||||||
|
(function () {
|
||||||
|
const toggle = document.getElementById('add_to_calendar');
|
||||||
|
const recipients = document.getElementById('calendar_recipients');
|
||||||
|
if (!toggle || !recipients) return;
|
||||||
|
|
||||||
|
function sync() {
|
||||||
|
recipients.style.display = toggle.checked ? '' : 'none';
|
||||||
|
}
|
||||||
|
toggle.addEventListener('change', sync);
|
||||||
|
sync();
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
<?= $this->endSection() ?>
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 321 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 32 KiB |
Reference in New Issue
Block a user