Skip to content

Commit

Permalink
Merge pull request #1727 from JortvD/feature/education-similar
Browse files Browse the repository at this point in the history
Add similar courses in course page
  • Loading branch information
tomudding authored Oct 6, 2023
2 parents b0a55ba + 74036dd commit c17c980
Show file tree
Hide file tree
Showing 15 changed files with 324 additions and 73 deletions.
10 changes: 10 additions & 0 deletions module/Application/language/en.po

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions module/Application/language/gewisweb.pot

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions module/Application/language/nl.po

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 39 additions & 47 deletions module/Education/src/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Education\Controller;

use Education\Model\Course as CourseModel;
use Education\Model\Exam as ExamModel;
use Education\Model\Summary as SummaryModel;
use Education\Service\AclService;
use Education\Service\Exam as ExamService;
use Education\Service\Course as CourseService;
use Laminas\Form\FormInterface;
use Laminas\Http\Request;
use Laminas\Http\Response;
use Laminas\Mvc\Controller\AbstractActionController;
Expand All @@ -29,7 +29,7 @@ class AdminController extends AbstractActionController
public function __construct(
private readonly AclService $aclService,
private readonly Translator $translator,
private readonly ExamService $examService,
private readonly CourseService $courseService,
private readonly array $educationTempConfig,
) {
}
Expand All @@ -51,7 +51,7 @@ public function courseAction(): ViewModel
throw new NotAllowedException($this->translator->translate('You are not allowed to administer courses'));
}

return new ViewModel(['courses' => $this->examService->getAllCourses()]);
return new ViewModel(['courses' => $this->courseService->getAllCourses()]);
}

public function addCourseAction(): Response|ViewModel
Expand All @@ -62,27 +62,25 @@ public function addCourseAction(): Response|ViewModel

/** @var Request $request */
$request = $this->getRequest();
$form = $this->examService->getCourseForm();
$form = $this->courseService->getCourseForm();

if ($request->isPost()) {
$form->setData($request->getPost()->toArray());

if ($form->isValid()) {
/** @var CourseModel $course */
$course = $form->getObject();
$data = $form->getData(FormInterface::VALUES_AS_ARRAY);
$course = $this->courseService->saveCourse($data);

if ($this->examService->saveCourse($course)) {
$this->flashMessenger()->addSuccessMessage(
$this->translator->translate('Successfully added course!'),
);

return $this->redirect()->toRoute('admin_education/course/edit', ['course' => $course->getCode()]);
}

$this->flashMessenger()->addErrorMessage(
$this->translator->translate('An error occurred while saving the course!'),
$this->flashMessenger()->addSuccessMessage(
$this->translator->translate('Successfully added course!'),
);

return $this->redirect()->toRoute('admin_education/course/edit', ['course' => $course->getCode()]);
}

$this->flashMessenger()->addErrorMessage(
$this->translator->translate('The course form is invalid!'),
);
}

return new ViewModel(
Expand All @@ -99,32 +97,26 @@ public function editCourseAction(): ViewModel
}

$courseId = $this->params()->fromRoute('course');
$course = $this->examService->getCourse($courseId);
$course = $this->courseService->getCourse($courseId);

if (null === $course) {
return $this->notFoundAction();
}

/** @var Request $request */
$request = $this->getRequest();
$form = $this->examService->getCourseForm($course);
$form = $this->courseService->getCourseForm($course);

if ($request->isPost()) {
$form->setData($request->getPost()->toArray());

if ($form->isValid()) {
/** @var CourseModel $course */
$course = $form->getObject();
$data = $form->getData(FormInterface::VALUES_AS_ARRAY);
$course = $this->courseService->updateCourse($course, $data);

if ($this->examService->saveCourse($course)) {
$this->flashMessenger()->addSuccessMessage(
$this->translator->translate('Successfully updated course information!'),
);
} else {
$this->flashMessenger()->addErrorMessage(
$this->translator->translate('An error occurred while saving the course!'),
);
}
$this->flashMessenger()->addSuccessMessage(
$this->translator->translate('Successfully updated course information!'),
);
}
}

Expand All @@ -146,8 +138,8 @@ public function deleteCourseAction(): Response|ViewModel
if ($request->getPost()) {
$courseId = $this->params()->fromRoute('course');

if (null !== ($course = $this->examService->getCourse($courseId))) {
$this->examService->deleteCourse($course);
if (null !== ($course = $this->courseService->getCourse($courseId))) {
$this->courseService->deleteCourse($course);

return $this->redirect()->toRoute('admin_education/course');
}
Expand All @@ -163,16 +155,16 @@ public function courseDocumentsAction(): ViewModel
}

$courseId = $this->params()->fromRoute('course');
$course = $this->examService->getCourse($courseId);
$course = $this->courseService->getCourse($courseId);

if (null === $course) {
return $this->notFoundAction();
}

return new ViewModel([
'course' => $course,
'exams' => $this->examService->getDocumentsForCourse($course, ExamModel::class),
'summaries' => $this->examService->getDocumentsForCourse($course, SummaryModel::class),
'exams' => $this->courseService->getDocumentsForCourse($course, ExamModel::class),
'summaries' => $this->courseService->getDocumentsForCourse($course, SummaryModel::class),
]);
}

Expand All @@ -185,7 +177,7 @@ public function deleteCourseDocumentAction(): Response|ViewModel
}

$courseId = $this->params()->fromRoute('course');
$course = $this->examService->getCourse($courseId);
$course = $this->courseService->getCourse($courseId);

if (null === $course) {
return $this->notFoundAction();
Expand All @@ -197,8 +189,8 @@ public function deleteCourseDocumentAction(): Response|ViewModel
if ($request->getPost()) {
$documentId = (int) $this->params()->fromRoute('document');

if (null !== ($document = $this->examService->getDocument($documentId))) {
$this->examService->deleteDocument($document);
if (null !== ($document = $this->courseService->getDocument($documentId))) {
$this->courseService->deleteDocument($document);

return $this->redirect()->toRoute('admin_education/course/documents', ['course' => $course->getCode()]);
}
Expand All @@ -214,7 +206,7 @@ public function bulkExamAction(): ViewModel

if ($request->isPost()) {
// try uploading
if ($this->examService->tempExamUpload($request->getPost(), $request->getFiles())) {
if ($this->courseService->tempExamUpload($request->getPost(), $request->getFiles())) {
return new ViewModel(
[
'success' => true,
Expand All @@ -233,7 +225,7 @@ public function bulkExamAction(): ViewModel

return new ViewModel(
[
'form' => $this->examService->getTempUploadForm(),
'form' => $this->courseService->getTempUploadForm(),
],
);
}
Expand All @@ -245,7 +237,7 @@ public function bulkSummaryAction(): ViewModel

if ($request->isPost()) {
// try uploading
if ($this->examService->tempSummaryUpload($request->getPost(), $request->getFiles())) {
if ($this->courseService->tempSummaryUpload($request->getPost(), $request->getFiles())) {
return new ViewModel(
[
'success' => true,
Expand All @@ -264,7 +256,7 @@ public function bulkSummaryAction(): ViewModel

return new ViewModel(
[
'form' => $this->examService->getTempUploadForm(),
'form' => $this->courseService->getTempUploadForm(),
],
);
}
Expand All @@ -276,13 +268,13 @@ public function editExamAction(): ViewModel
{
/** @var Request $request */
$request = $this->getRequest();
$form = $this->examService->getBulkExamForm();
$form = $this->courseService->getBulkExamForm();

if ($request->isPost()) {
$form->setData($request->getPost()->toArray());

if ($form->isValid()) {
if ($this->examService->bulkExamEdit($form->getData())) {
if ($this->courseService->bulkExamEdit($form->getData())) {
return new ViewModel(
[
'success' => true,
Expand All @@ -308,7 +300,7 @@ public function editSummaryAction(): ViewModel
/** @var Request $request */
$request = $this->getRequest();

if ($request->isPost() && $this->examService->bulkSummaryEdit($request->getPost()->toArray())) {
if ($request->isPost() && $this->courseService->bulkSummaryEdit($request->getPost()->toArray())) {
return new ViewModel(
[
'success' => true,
Expand All @@ -320,7 +312,7 @@ public function editSummaryAction(): ViewModel

return new ViewModel(
[
'form' => $this->examService->getBulkSummaryForm(),
'form' => $this->courseService->getBulkSummaryForm(),
'config' => $config,
],
);
Expand All @@ -332,7 +324,7 @@ public function deleteTempAction(): JsonModel|ViewModel
$request = $this->getRequest();

if ($request->isPost()) {
$this->examService->deleteTempExam(
$this->courseService->deleteTempExam(
$this->params()->fromRoute('filename'),
$this->params()->fromRoute('type'),
);
Expand Down
10 changes: 5 additions & 5 deletions module/Education/src/Controller/EducationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Education\Controller;

use Education\Form\SearchCourse as SearchCourseForm;
use Education\Service\Exam as ExamService;
use Education\Service\Course as CourseService;
use Laminas\Http\Response;
use Laminas\Http\Response\Stream;
use Laminas\Mvc\Controller\AbstractActionController;
Expand All @@ -14,7 +14,7 @@
class EducationController extends AbstractActionController
{
public function __construct(
private readonly ExamService $examService,
private readonly CourseService $courseService,
private readonly SearchCourseForm $searchCourseForm,
) {
}
Expand All @@ -29,7 +29,7 @@ public function indexAction(): ViewModel
$form->setData($query);

if ($form->isValid()) {
$courses = $this->examService->searchCourse($form->getData());
$courses = $this->courseService->searchCourse($form->getData());

return new ViewModel(
[
Expand All @@ -50,7 +50,7 @@ public function indexAction(): ViewModel
public function courseAction(): Response|ViewModel
{
$code = $this->params()->fromRoute('code');
$course = $this->examService->getCourse($code);
$course = $this->courseService->getCourse($code);

// If the course does not exist, trigger 404
if (null === $course) {
Expand All @@ -71,7 +71,7 @@ public function downloadAction(): Stream|ViewModel
{
$id = (int) $this->params()->fromRoute('id');

$download = $this->examService->getDocumentDownload($id);
$download = $this->courseService->getDocumentDownload($id);

if (null === $download) {
return $this->notFoundAction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __invoke(
return new AdminController(
$container->get('education_service_acl'),
$container->get(MvcTranslator::class),
$container->get('education_service_exam'),
$container->get('education_service_course'),
$container->get('config')['education_temp'],
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __invoke(
?array $options = null,
): EducationController {
return new EducationController(
$container->get('education_service_exam'),
$container->get('education_service_course'),
$container->get('education_form_searchcourse'),
);
}
Expand Down
Loading

0 comments on commit c17c980

Please sign in to comment.