@@ 275-323 (lines=49) @@ | ||
272 | ||
273 | // handle timetracking |
|
274 | $insValues = []; |
|
275 | foreach ($schema as $field) |
|
276 | { |
|
277 | $fieldValue = $request->input($field['key']); |
|
278 | if (!isset($fieldValue) || !$fieldValue) { |
|
279 | continue; |
|
280 | } |
|
281 | ||
282 | if ($field['type'] == 'TimeTracking') { |
|
283 | if (!$this->ttCheck($fieldValue)) { |
|
284 | throw new \UnexpectedValueException('the format of timetracking is incorrect.', -11102); |
|
285 | } |
|
286 | $insValues[$field['key']] = $this->ttHandle($fieldValue); |
|
287 | $insValues[$field['key'] . '_m'] = $this->ttHandleInM($insValues[$field['key']]); |
|
288 | } |
|
289 | else if ($field['type'] == 'DatePicker' || $field['type'] == 'DateTimePicker') { |
|
290 | if ($this->isTimestamp($fieldValue) === false) { |
|
291 | throw new \UnexpectedValueException('the format of datepicker field is incorrect.', -11122); |
|
292 | } |
|
293 | } |
|
294 | else if ($field['type'] == 'SingleUser') { |
|
295 | $user_info = Sentinel::findById($fieldValue); |
|
296 | if ($user_info) { |
|
297 | $insValues[$field['key']] = [ 'id' => $fieldValue, 'name' => $user_info->first_name, 'email' => $user_info->email ]; |
|
298 | } |
|
299 | } |
|
300 | else if ($field['type'] == 'MultiUser') { |
|
301 | $user_ids = $fieldValue; |
|
302 | $new_user_ids = []; |
|
303 | $insValues[$field['key']] = []; |
|
304 | foreach ($user_ids as $uid) |
|
305 | { |
|
306 | $user_info = Sentinel::findById($uid); |
|
307 | if ($user_info) { |
|
308 | array_push($insValues[$field['key']], [ 'id' => $uid, 'name' => $user_info->first_name, 'email' => $user_info->email ]); |
|
309 | $new_user_ids[] = $uid; |
|
310 | } |
|
311 | } |
|
312 | $insValues[$field['key'] . '_ids'] = $new_user_ids; |
|
313 | } |
|
314 | } |
|
315 | ||
316 | // handle assignee |
|
317 | $assignee = []; |
|
318 | $assignee_id = $request->input('assignee'); |
|
319 | if (!$assignee_id) { |
|
320 | $module_ids = $request->input('module'); |
|
321 | if ($module_ids) { |
|
322 | //$module_ids = explode(',', $module_ids); |
|
323 | $module = Provider::getModuleById($module_ids[0]); |
|
324 | if (isset($module['defaultAssignee']) && $module['defaultAssignee'] === 'modulePrincipal') { |
|
325 | $assignee2 = $module['principal'] ?: ''; |
|
326 | $assignee_id = isset($assignee2['id']) ? $assignee2['id'] : ''; |
|
@@ 860-909 (lines=50) @@ | ||
857 | ||
858 | // handle timetracking |
|
859 | $updValues = []; |
|
860 | foreach ($schema as $field) |
|
861 | { |
|
862 | $fieldValue = $request->input($field['key']); |
|
863 | if (!isset($fieldValue) || !$fieldValue) { |
|
864 | continue; |
|
865 | } |
|
866 | ||
867 | if ($field['type'] == 'TimeTracking') { |
|
868 | if (!$this->ttCheck($fieldValue)) { |
|
869 | throw new \UnexpectedValueException('the format of timetracking field is incorrect.', -11102); |
|
870 | } |
|
871 | ||
872 | $updValues[$field['key']] = $this->ttHandle($fieldValue); |
|
873 | $updValues[$field['key'] . '_m'] = $this->ttHandleInM($updValues[$field['key']]); |
|
874 | } |
|
875 | else if ($field['type'] == 'DatePicker' || $field['type'] == 'DateTimePicker') { |
|
876 | if ($this->isTimestamp($fieldValue) === false) { |
|
877 | throw new \UnexpectedValueException('the format of datepicker field is incorrect.', -11122); |
|
878 | } |
|
879 | } |
|
880 | else if ($field['type'] == 'SingleUser') { |
|
881 | $user_info = Sentinel::findById($fieldValue); |
|
882 | if ($user_info) { |
|
883 | $updValues[$field['key']] = [ 'id' => $fieldValue, 'name' => $user_info->first_name, 'email' => $user_info->email ]; |
|
884 | } |
|
885 | } |
|
886 | else if ($field['type'] == 'MultiUser') { |
|
887 | $user_ids = $fieldValue; |
|
888 | $updValues[$field['key']] = []; |
|
889 | $new_user_ids = []; |
|
890 | foreach ($user_ids as $uid) |
|
891 | { |
|
892 | $user_info = Sentinel::findById($uid); |
|
893 | if ($user_info) { |
|
894 | array_push($updValues[$field['key']], [ 'id' => $uid, 'name' => $user_info->first_name, 'email' => $user_info->email ]); |
|
895 | } |
|
896 | $new_user_ids[] = $uid; |
|
897 | } |
|
898 | $updValues[$field['key'] . '_ids'] = $new_user_ids; |
|
899 | } |
|
900 | } |
|
901 | ||
902 | $assignee_id = $request->input('assignee'); |
|
903 | if ($assignee_id) { |
|
904 | if ((!isset($issue['assignee']) || (isset($issue['assignee']) && $assignee_id != $issue['assignee']['id'])) && !$this->isPermissionAllowed($project_key, 'assigned_issue', $assignee_id)) { |
|
905 | return response()->json(['ecode' => -11118, 'emsg' => 'the assigned user has not assigned-issue permission.']); |
|
906 | } |
|
907 | ||
908 | $user_info = Sentinel::findById($assignee_id); |
|
909 | if ($user_info) { |
|
910 | $assignee = [ 'id' => $assignee_id, 'name' => $user_info->first_name, 'email' => $user_info->email ]; |
|
911 | $updValues['assignee'] = $assignee; |
|
912 | } |