SHARE
TWEET

Save event calendar view

eunion Mar 9th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     protected function getRecordModelFromRequest(Vtiger_Request $request) {
  2.         $moduleName = $request->getModule();
  3.         $recordId = $request->get('record');
  4.  
  5.         $moduleModel = Vtiger_Module_Model::getInstance($moduleName);
  6.  
  7.         if(!empty($recordId)) {
  8.             $recordModel = Vtiger_Record_Model::getInstanceById($recordId, $moduleName);
  9.             $modelData = $recordModel->getData();
  10.             $recordModel->set('id', $recordId);
  11.             $recordModel->set('mode', 'edit');
  12.             //Due to dependencies on the activity_reminder api in Activity.php(5.x)
  13.             $_REQUEST['mode'] = 'edit';
  14.         } else {
  15.             $recordModel = Vtiger_Record_Model::getCleanInstance($moduleName);
  16.             $modelData = $recordModel->getData();
  17.             $recordModel->set('mode', '');
  18.         }
  19.  
  20.         $fieldModelList = $moduleModel->getFields();
  21.         foreach ($fieldModelList as $fieldName => $fieldModel) {
  22.             $fieldValue = $request->get($fieldName, null);
  23.             // For custom time fields in Calendar, it was not converting to db insert format(sending as 10:00 AM/PM)
  24.             $fieldDataType = $fieldModel->getFieldDataType();
  25.             if($fieldDataType == 'time' && $fieldValue !== null){
  26.                 $fieldValue = Vtiger_Time_UIType::getTimeValueWithSeconds($fieldValue);
  27.             }
  28.             // End
  29.             if ($fieldName === $request->get('field')) {
  30.                 $fieldValue = $request->get('value');
  31.             }
  32.            
  33.             //SalesPlatform.ru begin
  34.             if($fieldModel->isCKEEnabled()) {
  35.                 $fieldValue = vtlib_purify(decode_html($fieldValue));
  36.             }
  37.             //SalesPlatform.ru end
  38.            
  39.             if($fieldValue !== null) {
  40.                 if(!is_array($fieldValue)) {
  41.                     $fieldValue = trim($fieldValue);
  42.                 }
  43.                 $recordModel->set($fieldName, $fieldValue);
  44.             }
  45.         }
  46.  
  47.         //Start Date and Time values
  48.         // Sergey Emelyanov - fixed empty date format
  49.         if (!$request->get('time_start')) {
  50.             $request->set('time_start', $recordModel->get('time_start'));
  51.         }
  52.         if (!$request->get('date_start')) {
  53.             $request->set('date_start', $recordModel->get('date_start'));
  54.         }
  55.         if (!$request->get('due_date')) {
  56.             $request->set('due_date', $recordModel->get('due_date'));
  57.         }
  58.         if (!$request->get('time_end')) {
  59.             $request->set('time_end', $recordModel->get('time_end'));
  60.         }
  61.         // Sergey Emelyanov - end fixing empty date format
  62.  
  63.         $startTime = Vtiger_Time_UIType::getTimeValueWithSeconds($request->get('time_start'));
  64.         $startDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($request->get('date_start')." ".$startTime);
  65.         list($startDate, $startTime) = explode(' ', $startDateTime);
  66.  
  67.         $recordModel->set('date_start', $startDate);
  68.         $recordModel->set('time_start', $startTime);
  69.  
  70.         //End Date and Time values
  71.         $endTime = $request->get('time_end');
  72.         $endDate = Vtiger_Date_UIType::getDBInsertedValue($request->get('due_date'));
  73.  
  74.         if ($endTime) {
  75.             $endTime = Vtiger_Time_UIType::getTimeValueWithSeconds($endTime);
  76.             $endDateTime = Vtiger_Datetime_UIType::getDBDateTimeValue($request->get('due_date')." ".$endTime);
  77.             list($endDate, $endTime) = explode(' ', $endDateTime);
  78.         }
  79.  
  80.         $recordModel->set('time_end', $endTime);
  81.         $recordModel->set('due_date', $endDate);
  82.  
  83.         $activityType = $request->get('activitytype');
  84.         if(empty($activityType)) {
  85.             $recordModel->set('activitytype', 'Task');
  86.             $recordModel->set('visibility', 'Private');
  87.         }
  88.  
  89.         //Due to dependencies on the older code
  90.         $setReminder = $request->get('set_reminder');
  91.         if($setReminder) {
  92.             $_REQUEST['set_reminder'] = 'Yes';
  93.         } else {
  94.             $_REQUEST['set_reminder'] = 'No';
  95.         }
  96.  
  97.         return $recordModel;
  98.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top