Skip to content

Commit

Permalink
Merge pull request #125 from iCAPLyon1/5.x
Browse files Browse the repository at this point in the history
5.x
  • Loading branch information
ngodfraind committed Sep 11, 2015
2 parents cd23a3c + 86d5c0e commit 6d0ec27
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 49 deletions.
72 changes: 25 additions & 47 deletions Controller/DropzoneController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ public function editCommonAction(Request $request, Dropzone $dropzone, $user)
$this->get('icap.manager.dropzone_voter')->isAllowToOpen($dropzone);
$this->get('icap.manager.dropzone_voter')->isAllowToEdit($dropzone);
$platformConfigHandler = $this->get('claroline.config.platform_config_handler');
$form = $this->createForm(new DropzoneCommonType(), $dropzone, array('language' => $platformConfigHandler->getParameter('locale_language'), 'date_format' => $this->get('translator')->trans('date_form_format', array(), 'platform')));
$dateFormat = $this->get('translator')->trans('date_form_format', array(), 'platform');
$lang = $platformConfigHandler->getParameter('locale_language');
$form = $this->createForm(
new DropzoneCommonType(),
$dropzone,
array('language' => $lang, 'date_format' => $dateFormat)
);

if ($request->isMethod('POST')) {
// see if manual plannification option has changed.
Expand All @@ -76,13 +82,6 @@ public function editCommonAction(Request $request, Dropzone $dropzone, $user)
if ($dropzone->getEditionState() < 2) {
$dropzone->setEditionState(2);
}
/*
if (!$dropzone->getDisplayNotationToLearners() and !$dropzone->getDisplayNotationMessageToLearners()) {
$form->get('displayNotationToLearners')->addError(new FormError('Choose at least one type of ranking'));
$form
->get('displayNotationMessageToLearners')
->addError(new FormError('Choose at least one type of ranking'));
}*/

if (
!$dropzone->getAllowWorkspaceResource()
Expand All @@ -106,33 +105,29 @@ public function editCommonAction(Request $request, Dropzone $dropzone, $user)

if (array_key_exists('startAllowDrop', $form_array)) {
$dateStr = implode(' ', $form_array['startAllowDrop']);
if ($this->validateDate($dateStr)) {
$startAllowDrop = new DateTime($dateStr);
$dropzone->setStartAllowDrop($startAllowDrop);
if ($startDrop = $this->validateDate($dateStr, $dateFormat)) {
$dropzone->setStartAllowDrop($startDrop);
}
}

if (array_key_exists('endAllowDrop', $form_array)) {
$dateStr = implode(' ', $form_array['endAllowDrop']);
if ($this->validateDate($dateStr)) {
$endAllowDrop = new DateTime($dateStr);
$dropzone->setEndAllowDrop($endAllowDrop);
if ($endDrop = $this->validateDate($dateStr, $dateFormat)) {
$dropzone->setEndAllowDrop($endDrop);
}
}

if (array_key_exists('endReview', $form_array)) {
$dateStr = implode(' ', $form_array['endReview']);
if ($this->validateDate($dateStr)) {
$endReview = new DateTime(implode(' ', $form_array['endReview']));
$dropzone->setEndReview($endReview);
if (array_key_exists('startReview', $form_array)) {
$dateStr = implode(' ', $form_array['startReview']);
if ($startReview = $this->validateDate($dateStr, $dateFormat)) {
$dropzone->setStartReview($startReview);
}
}

if (array_key_exists('endAllowDrop', $form_array)) {
$dateStr = implode(' ', $form_array['endAllowDrop']);
if ($this->validateDate($dateStr)) {
$endAllowDrop = new DateTime(implode(' ', $form_array['endAllowDrop']));
$dropzone->setEndAllowDrop($endAllowDrop);
if (array_key_exists('endReview', $form_array)) {
$dateStr = implode(' ', $form_array['endReview']);
if ($endReview = $this->validateDate($dateStr, $dateFormat)) {
$dropzone->setEndReview($endReview);
}
}

Expand All @@ -144,11 +139,10 @@ public function editCommonAction(Request $request, Dropzone $dropzone, $user)
//if event already exist
if ($dropzone->getEventDrop() != null) {


// update event
$eventDrop = $dropzone->getEventDrop();
$eventDrop->setStart($dropzone->getStartAllowDrop());
$eventDrop->setEnd($dropzone->getEndAllowDrop());
$eventDrop->setStart($dropzone->getStartAllowDrop()->getTimeStamp());
$eventDrop->setEnd($dropzone->getEndAllowDrop()->getTimeStamp());

$AgendaManager->updateEvent($eventDrop);

Expand Down Expand Up @@ -177,18 +171,11 @@ public function editCommonAction(Request $request, Dropzone $dropzone, $user)
} else {
//create event
$eventReview = $this->createAgendaEventDrop($dropzone->getStartReview(), $dropzone->getEndReview(), $user, $dropzone, 'correction');

$AgendaManager->addEvent($eventReview, $workspace);
$dropzone->setEventCorrection($eventReview);

}
}

//$dropzone->setStartAllowDrop()
/*var_dump( $test_date);
var_dump($form_array);
die;
*/
if ($dropzone->getStartAllowDrop() == null) {
$form->get('startAllowDrop')->addError(new FormError('Choose a date'));
}
Expand Down Expand Up @@ -230,24 +217,17 @@ public function editCommonAction(Request $request, Dropzone $dropzone, $user)
// if manual mode, we delete agenda events related to
$AgendaManager = $this->get('claroline.manager.agenda_manager');


if ($dropzone->getEventDrop() != null) {
$event = $dropzone->getEventDrop();
$AgendaManager->deleteEvent($event);
$dropzone->setEventDrop(NULL);


}

if ($dropzone->getEventCorrection() != null) {
$event = $dropzone->getEventCorrection();
$AgendaManager->deleteEvent($event);
$dropzone->setEventCorrection(NULL);


}


}


Expand Down Expand Up @@ -550,17 +530,15 @@ public function openAction(Dropzone $dropzone, $user)
*/
private function validateDate($date, $format = 'Y-m-d H:i:s')
{

$d = DateTime::createFromFormat($format, $date);
return $d && $d->format($format) == $date;
return DateTime::createFromFormat($format, $date);
}


private function createAgendaEventDrop($startDate, $endDate, $user, Dropzone $dropzone, $type = "drop")
{
$event = new Event();
$event->setStart($startDate);
$event->setEnd($endDate);
$event->setStart($startDate->getTimeStamp());
$event->setEnd($endDate->getTimeStamp());
$event->setUser($user);

$dropzoneName = $dropzone->getResourceNode()->getName();
Expand Down Expand Up @@ -684,4 +662,4 @@ public function donwloadCopiesAction(Request $request, Dropzone $dropzone, $begi

}

}
}
4 changes: 2 additions & 2 deletions Form/DropzoneCommonType.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'component' => true,
'autoclose' => true,
'language' => $options['language'],
'format' => $options['date_format']
'date_format' => $options['date_format']
);

$builder
Expand Down Expand Up @@ -112,4 +112,4 @@ public function configureOptions(OptionsResolver $resolver)
)
);
}
}
}

0 comments on commit 6d0ec27

Please sign in to comment.