Skip to content
Snippets Groups Projects
Commit 30cf5636 authored by Uma's avatar Uma
Browse files

Merge branch '1301_DragandDrop' into 'master'

Cleaning up #1301

I tested this on a recent pull and it seems to be working correctly.

See merge request !642
parents 3eff2d3c b5c4d979
No related branches found
No related tags found
No related merge requests found
...@@ -44,13 +44,9 @@ class Calendar_DragDropAjax_Action extends Calendar_SaveAjax_Action { ...@@ -44,13 +44,9 @@ class Calendar_DragDropAjax_Action extends Calendar_SaveAjax_Action {
$record = Vtiger_Record_Model::getInstanceById($recordId, $moduleName); $record = Vtiger_Record_Model::getInstanceById($recordId, $moduleName);
$record->set('mode','edit'); $record->set('mode','edit');
$startDateTime[] = $record->get('date_start'); $startDateTime = $this->getFormattedDateTime($record->get('date_start'), $record->get('time_start'));
$startDateTime[] = $record->get('time_start'); $oldDateTime = $this->getFormattedDateTime($record->get('due_date'), $record->get('time_end'));
$startDateTime = implode(' ',$startDateTime);
$oldDateTime[] = $record->get('due_date');
$oldDateTime[] = $record->get('time_end');
$oldDateTime = implode(' ',$oldDateTime);
$resultDateTime = $this->changeDateTime($oldDateTime,$dayDelta,$minuteDelta,$secondsDelta); $resultDateTime = $this->changeDateTime($oldDateTime,$dayDelta,$minuteDelta,$secondsDelta);
$interval = strtotime($resultDateTime) - strtotime($startDateTime); $interval = strtotime($resultDateTime) - strtotime($startDateTime);
...@@ -68,24 +64,18 @@ class Calendar_DragDropAjax_Action extends Calendar_SaveAjax_Action { ...@@ -68,24 +64,18 @@ class Calendar_DragDropAjax_Action extends Calendar_SaveAjax_Action {
$recordModel = Vtiger_Record_Model::getInstanceById($childId, 'Events'); $recordModel = Vtiger_Record_Model::getInstanceById($childId, 'Events');
$recordModel->set('mode','edit'); $recordModel->set('mode','edit');
$startDateTime = ''; $startDateTime = $this->getFormattedDateTime($recordModel->get('date_start'), $recordModel->get('time_start'));
$startDateTime[] = $recordModel->get('date_start');
$startDateTime[] = $recordModel->get('time_start');
$startDateTime = implode(' ',$startDateTime);
$dueDate = strtotime($startDateTime) + $interval; $dueDate = strtotime($startDateTime) + $interval;
$formatDate = date("Y-m-d H:i:s", $dueDate); $formatDate = date("Y-m-d H:i:s", $dueDate);
$parts = explode(' ',$formatDate); $parts = explode(' ',$formatDate);
$startDateTime = new DateTime($startDateTime); $startDateTime = new DateTime($startDateTime);
$recordModel->set('due_date',$parts[0]); $recordModel->set('due_date',$parts[0]);
if(activitytype != 'Task') { if($activityType != 'Task') {
$recordModel->set('time_end',$parts[1]); $recordModel->set('time_end',$parts[1]);
} }
$endDateTime = ''; $endDateTime = $this->getFormattedDateTime($recordModel->get('due_date'), $recordModel->get('time_end'));
$endDateTime[] = $recordModel->get('due_date');
$endDateTime[] = $recordModel->get('time_end');
$endDateTime = implode(' ',$endDateTime);
$endDateTime = new DateTime($endDateTime); $endDateTime = new DateTime($endDateTime);
if($startDateTime <= $endDateTime) { if($startDateTime <= $endDateTime) {
...@@ -97,26 +87,18 @@ class Calendar_DragDropAjax_Action extends Calendar_SaveAjax_Action { ...@@ -97,26 +87,18 @@ class Calendar_DragDropAjax_Action extends Calendar_SaveAjax_Action {
} }
$result['recurringRecords'] = true; $result['recurringRecords'] = true;
} else { } else {
$oldDateTime = ''; $oldDateTime = $this->getFormattedDateTime($record->get('due_date'), $record->get('time_end'));
$oldDateTime[] = $record->get('due_date');
$oldDateTime[] = $record->get('time_end');
$oldDateTime = implode(' ',$oldDateTime);
$resultDateTime = $this->changeDateTime($oldDateTime,$dayDelta,$minuteDelta,$secondsDelta); $resultDateTime = $this->changeDateTime($oldDateTime,$dayDelta,$minuteDelta,$secondsDelta);
$parts = explode(' ',$resultDateTime); $parts = explode(' ',$resultDateTime);
$record->set('due_date',$parts[0]); $record->set('due_date',$parts[0]);
if(activitytype != 'Task') { if($activityType != 'Task') {
$record->set('time_end',$parts[1]); $record->set('time_end',$parts[1]);
} }
$startDateTime = ''; $startDateTime = $this->getFormattedDateTime($record->get('date_start'), $record->get('time_start'));
$startDateTime[] = $record->get('date_start');
$startDateTime[] = $record->get('time_start');
$startDateTime = implode(' ',$startDateTime);
$startDateTime = new DateTime($startDateTime); $startDateTime = new DateTime($startDateTime);
$endDateTime[] = $record->get('due_date'); $endDateTime = $this->getFormattedDateTime($record->get('due_date'), $record->get('time_end'));
$endDateTime[] = $record->get('time_end');
$endDateTime = implode(' ',$endDateTime);
$endDateTime = new DateTime($endDateTime); $endDateTime = new DateTime($endDateTime);
//Checking if startDateTime is less than or equal to endDateTime //Checking if startDateTime is less than or equal to endDateTime
if($startDateTime <= $endDateTime) { if($startDateTime <= $endDateTime) {
...@@ -195,15 +177,11 @@ class Calendar_DragDropAjax_Action extends Calendar_SaveAjax_Action { ...@@ -195,15 +177,11 @@ class Calendar_DragDropAjax_Action extends Calendar_SaveAjax_Action {
$record = Vtiger_Record_Model::getInstanceById($recordId, $moduleName); $record = Vtiger_Record_Model::getInstanceById($recordId, $moduleName);
$record->set('mode','edit'); $record->set('mode','edit');
$oldStartDateTime[] = $record->get('date_start'); $oldStartDateTime = $this->getFormattedDateTime($record->get('date_start'), $record->get('time_start'));
$oldStartDateTime[] = $record->get('time_start');
$oldStartDateTime = implode(' ',$oldStartDateTime);
$resultDateTime = $this->changeDateTime($oldStartDateTime, $dayDelta, $minuteDelta, $secondsDelta); $resultDateTime = $this->changeDateTime($oldStartDateTime, $dayDelta, $minuteDelta, $secondsDelta);
$startDateInterval = strtotime($resultDateTime) - strtotime($oldStartDateTime); $startDateInterval = strtotime($resultDateTime) - strtotime($oldStartDateTime);
$oldEndDateTime[] = $record->get('due_date'); $oldEndDateTime = $this->getFormattedDateTime($record->get('due_date'), $record->get('time_end'));
$oldEndDateTime[] = $record->get('time_end');
$oldEndDateTime = implode(' ', $oldEndDateTime);
$resultDateTime = $this->changeDateTime($oldEndDateTime, $dayDelta, $minuteDelta, $secondsDelta); $resultDateTime = $this->changeDateTime($oldEndDateTime, $dayDelta, $minuteDelta, $secondsDelta);
$endDateInterval = strtotime($resultDateTime) - strtotime($oldEndDateTime); $endDateInterval = strtotime($resultDateTime) - strtotime($oldEndDateTime);
...@@ -221,29 +199,23 @@ class Calendar_DragDropAjax_Action extends Calendar_SaveAjax_Action { ...@@ -221,29 +199,23 @@ class Calendar_DragDropAjax_Action extends Calendar_SaveAjax_Action {
$recordModel = Vtiger_Record_Model::getInstanceById($childId, 'Events'); $recordModel = Vtiger_Record_Model::getInstanceById($childId, 'Events');
$recordModel->set('mode', 'edit'); $recordModel->set('mode', 'edit');
$startDateTime = ''; $startDateTime = $this->getFormattedDateTime($recordModel->get('date_start'), $recordModel->get('time_start'));
$startDateTime[] = $recordModel->get('date_start');
$startDateTime[] = $recordModel->get('time_start');
$startDateTime = implode(' ', $startDateTime);
$startDate = strtotime($startDateTime) + $startDateInterval; $startDate = strtotime($startDateTime) + $startDateInterval;
$formatStartDate = date("Y-m-d H:i:s", $startDate); $formatStartDate = date("Y-m-d H:i:s", $startDate);
$parts = explode(' ', $formatStartDate); $parts = explode(' ', $formatStartDate);
$startDateTime = new DateTime($startDateTime); $startDateTime = new DateTime($startDateTime);
$recordModel->set('date_start', $parts[0]); $recordModel->set('date_start', $parts[0]);
if (activitytype != 'Task') if ($activityType != 'Task')
$recordModel->set('time_start', $parts[1]); $recordModel->set('time_start', $parts[1]);
$endDateTime = ''; $endDateTime = $this->getFormattedDateTime($recordModel->get('due_date'), $recordModel->get('time_end'));
$endDateTime[] = $recordModel->get('due_date');
$endDateTime[] = $recordModel->get('time_end');
$endDateTime = implode(' ', $endDateTime);
$endDate = strtotime($endDateTime) + $endDateInterval; $endDate = strtotime($endDateTime) + $endDateInterval;
$formatEndDate = date("Y-m-d H:i:s", $endDate); $formatEndDate = date("Y-m-d H:i:s", $endDate);
$endDateParts = explode(' ', $formatEndDate); $endDateParts = explode(' ', $formatEndDate);
$endDateTime = new DateTime($endDateTime); $endDateTime = new DateTime($endDateTime);
$recordModel->set('due_date', $endDateParts[0]); $recordModel->set('due_date', $endDateParts[0]);
if (activitytype != 'Task') if ($activityType != 'Task')
$recordModel->set('time_end', $endDateParts[1]); $recordModel->set('time_end', $endDateParts[1]);
$this->setRecurrenceInfo($recordModel); $this->setRecurrenceInfo($recordModel);
...@@ -251,19 +223,13 @@ class Calendar_DragDropAjax_Action extends Calendar_SaveAjax_Action { ...@@ -251,19 +223,13 @@ class Calendar_DragDropAjax_Action extends Calendar_SaveAjax_Action {
} }
$result['recurringRecords'] = true; $result['recurringRecords'] = true;
} else { } else {
$oldStartDateTime = array(); $oldStartDateTime = $this->getFormattedDateTime($record->get('date_start'), $record->get('time_start'));
$oldStartDateTime[] = $record->get('date_start');
$oldStartDateTime[] = $record->get('time_start');
$oldStartDateTime = implode(' ', $oldStartDateTime);
$resultDateTime = $this->changeDateTime($oldStartDateTime,$dayDelta,$minuteDelta,$secondsDelta); $resultDateTime = $this->changeDateTime($oldStartDateTime,$dayDelta,$minuteDelta,$secondsDelta);
$parts = explode(' ',$resultDateTime); $parts = explode(' ',$resultDateTime);
$record->set('date_start',$parts[0]); $record->set('date_start',$parts[0]);
$record->set('time_start',$parts[1]); $record->set('time_start',$parts[1]);
$oldEndDateTime = array(); $oldEndDateTime = $this->getFormattedDateTime($record->get('due_date'), $record->get('time_end'));
$oldEndDateTime[] = $record->get('due_date');
$oldEndDateTime[] = $record->get('time_end');
$oldEndDateTime = implode(' ',$oldEndDateTime);
$resultDateTime = $this->changeDateTime($oldEndDateTime,$dayDelta,$minuteDelta,$secondsDelta); $resultDateTime = $this->changeDateTime($oldEndDateTime,$dayDelta,$minuteDelta,$secondsDelta);
$parts = explode(' ',$resultDateTime); $parts = explode(' ',$resultDateTime);
$record->set('due_date',$parts[0]); $record->set('due_date',$parts[0]);
......
...@@ -207,4 +207,13 @@ class Calendar_SaveAjax_Action extends Vtiger_SaveAjax_Action { ...@@ -207,4 +207,13 @@ class Calendar_SaveAjax_Action extends Vtiger_SaveAjax_Action {
return $recordModel; return $recordModel;
} }
/**
* Helper API. See #1301 on code.vtiger.com
**/
public function getFormattedDateTime($date, $time) {
return trim($date . ' ' . $time);
}
} }
...@@ -101,9 +101,7 @@ class Calendar_SaveFollowupAjax_Action extends Calendar_SaveAjax_Action { ...@@ -101,9 +101,7 @@ class Calendar_SaveFollowupAjax_Action extends Calendar_SaveAjax_Action {
} }
else{ else{
//checking if the event can be marked as Held (status validation) //checking if the event can be marked as Held (status validation)
$startDateTime[] = $recordModel->get('date_start'); $startDateTime = $this->getFormattedDateTime($recordModel->get('date_start'), $recordModel->get('time_start'));
$startDateTime[] = $recordModel->get('time_start');
$startDateTime = implode(' ',$startDateTime);
$startDateTime = new DateTime($startDateTime); $startDateTime = new DateTime($startDateTime);
$currentDateTime = date("Y-m-d H:i:s"); $currentDateTime = date("Y-m-d H:i:s");
$currentDateTime = new DateTime($currentDateTime); $currentDateTime = new DateTime($currentDateTime);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment