{"action":"created","comment":{"url":"https://api.github.com/repos/framgia/servey_01/pulls/comments/181936983","pull_request_review_id":112648480,"id":181936983,"diff_hunk":"@@ -108,92 +111,128 @@ public function getResutlSurvey($token)\n         return $results;\n     }\n \n-    public function createSurvey(\n-        $inputs,\n-        array $settings,\n-        array $arrayQuestionWithAnswer,\n-        array $questionsRequired,\n-        array $images,\n-        array $imageUrl,\n-        array $videoUrl,\n-        $locale\n-    ) {\n-        $surveyInputs = $inputs->only([\n-            'user_id',\n-            'mail',\n-            'title',\n-            'feature',\n-            'token',\n-            'token_manage',\n-            'status',\n-            'start_time',\n-            'next_reminder_time',\n-            'deadline',\n-            'description',\n-            'user_name',\n-        ]);\n-\n-        // if the lang is english will be format from M-D-Y to M/D/Y\n-        if ($inputs['start_time']) {\n-            $inputs['start_time'] = $surveyInputs['start_time'] = Carbon::parse(in_array($locale, config('settings.sameFormatDateTime'))\n-                ? str_replace('-', '/', $surveyInputs['start_time'])\n-                : $surveyInputs['start_time'])\n-                ->toDateTimeString();\n-        }\n+    public function createSurvey($userId, $data)\n+    {\n+        DB::beginTransaction();\n \n-        if ($inputs['deadline']) {\n-            $inputs['deadline'] = $surveyInputs['deadline'] = Carbon::parse(in_array($locale, config('settings.sameFormatDateTime'))\n-                ? str_replace('-', '/', $surveyInputs['deadline'])\n-                : $surveyInputs['deadline'])\n-                ->toDateTimeString();\n-        }\n+        try {\n+            if ($userId != Auth::user()->id) {\n+                throw new Exception(\"Error Processing Request\", 1);\n+            }\n \n-        if ($inputs['next_reminder_time']) {\n-            $inputs['next_reminder_time'] = $surveyInputs['next_reminder_time'] = Carbon::parse(in_array($locale, config('settings.sameFormatDateTime'))\n-                ? str_replace('-', '/', $surveyInputs['next_reminder_time'])\n-                : $surveyInputs['next_reminder_time'])\n-                ->toDateTimeString();\n-        }\n+            $surveyInputs = $data->only([\n+                'title', \n+                'description', \n+                'start_time',\n+                'end_time'\n+            ]);\n \n-        $surveyInputs['status'] = config('survey.status.available');\n-        $surveyInputs['start_time'] = $inputs['start_time'] ?: null;\n-        $surveyInputs['deadline'] = $inputs['deadline'] ?: null;\n-        $surveyInputs['next_reminder_time'] = $inputs['next_reminder_time'] ?: null;\n-        $surveyInputs['description'] = $inputs['description'] ?: null;\n-        $surveyInputs['created_at'] = $surveyInputs['updated_at'] = Carbon::now();\n-        $surveyId = parent::create($surveyInputs->toArray());\n+            $surveyInputs['feature'] = config('settings.survey.feature.default');\n+            $surveyInputs['token'] = md5(uniqid(rand(), true));\n+            $surveyInputs['token_manage'] = md5(uniqid(rand(), true));\n+            $surveyInputs['status'] = config('settings.survey.status.public');\n \n-        if (!$surveyId) {\n-            return false;\n-        }\n+            $survey = parent::create($surveyInputs);\n \n-        // (1,6) That is the settings quantity for a survey\n-        foreach (range(1, 6) as $key) {\n-            if (!array_has($settings, $key)) {\n-                $settings[$key] = null;\n+            if (!$survey) {\n+                throw new Exception(\"Error Processing Request\", 1);\n             }\n-        }\n \n-        if (!$settings[config('settings.key.tailMail')]) {\n-            $settings[config('settings.key.tailMail')] = null;\n-        }\n+            //create owner\n+            $survey->members()->attach($userId, [\n+                'role' =>Survey::OWNER,\n+                'status' => Survey::APPROVE,\n+            ]);\n+            \n+            // create invite email\n+            if ($data->invited_emails) {\n+                $invite_mails = $this->formatInviteMailsString($data->invited_emails);\n+\n+                $survey->invites()->create([\n+                    'invite_mails' => $invite_mails,\n+                    'answer_mails' => '',\n+                    'status' => config('settings.survey.invite_status.not_finish'),\n+                ]);\n+            }\n+\n+            // create settings of survey\n+            $settingsData = $this->createSettingDataArray($data->setting);\n+            $survey->settings()->createMany($settingsData);\n+\n+            $orderSection = 0;\n+\n+            // create sections\n+            foreach ($data->sections as $section) {\n+                $sectionData['title'] = $section['title'];\n+                $sectionData['description'] = $section['description'];\n+                $sectionData['order'] = ++$orderSection;\n+                $sectionData['update'] = config('settings.survey.section_update.default');;\n+\n+                $sectionCreated = $survey->sections()->create($sectionData);\n+\n+                $orderQuestion = 0;\n+\n+                // create questions\n+                if (isset($section['questions'])) {\n+                    foreach ($section['questions'] as $question) {\n+                        $questionData['title'] = $question['title'];\n+                        $questionData['description'] = $question['description'];\n+                        $questionData['required'] = $question['require'];\n+                        $questionData['order'] = ++$orderQuestion;\n+                        $questionData['update'] = config('settings.survey.question_update.default');\n \n-        app(SettingInterface::class)->createMultiSetting($settings, $surveyId);\n-        $txtQuestion = $arrayQuestionWithAnswer;\n-        $questions = $txtQuestion['question'];\n-        $answers = $txtQuestion['answers'];\n-        app(QuestionInterface::class)\n-            ->createMultiQuestion(\n-                $surveyId,\n-                $questions,\n-                $answers,\n-                $images,\n-                $imageUrl,\n-                $videoUrl,\n-                $questionsRequired\n-            );\n-\n-        return $surveyId;\n+                        $questionCreated = $sectionCreated->questions()->create($questionData);","path":"app/Repositories/Survey/SurveyRepository.php","position":165,"original_position":165,"commit_id":"540b5e7fc2e33b37c729fe39b80038e0166bbf03","original_commit_id":"540b5e7fc2e33b37c729fe39b80038e0166bbf03","user":{"login":"lamngockhuong","id":16838267,"avatar_url":"https://avatars0.githubusercontent.com/u/16838267?v=4","gravatar_id":"","url":"https://api.github.com/users/lamngockhuong","html_url":"https://github.com/lamngockhuong","followers_url":"https://api.github.com/users/lamngockhuong/followers","following_url":"https://api.github.com/users/lamngockhuong/following{/other_user}","gists_url":"https://api.github.com/users/lamngockhuong/gists{/gist_id}","starred_url":"https://api.github.com/users/lamngockhuong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lamngockhuong/subscriptions","organizations_url":"https://api.github.com/users/lamngockhuong/orgs","repos_url":"https://api.github.com/users/lamngockhuong/repos","events_url":"https://api.github.com/users/lamngockhuong/events{/privacy}","received_events_url":"https://api.github.com/users/lamngockhuong/received_events","type":"User","site_admin":false},"body":"@trangkarol ai đẻ rứa chị :v","created_at":"2018-04-17T02:26:38Z","updated_at":"2018-04-17T02:28:54Z","html_url":"https://github.com/framgia/servey_01/pull/224#discussion_r181936983","pull_request_url":"https://api.github.com/repos/framgia/servey_01/pulls/224","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/framgia/servey_01/pulls/comments/181936983"},"html":{"href":"https://github.com/framgia/servey_01/pull/224#discussion_r181936983"},"pull_request":{"href":"https://api.github.com/repos/framgia/servey_01/pulls/224"}},"in_reply_to_id":181934313},"pull_request":{"url":"https://api.github.com/repos/framgia/servey_01/pulls/224","id":182031540,"html_url":"https://github.com/framgia/servey_01/pull/224","diff_url":"https://github.com/framgia/servey_01/pull/224.diff","patch_url":"https://github.com/framgia/servey_01/pull/224.patch","issue_url":"https://api.github.com/repos/framgia/servey_01/issues/224","number":224,"state":"open","locked":false,"title":"[Server] create survey logic","user":{"login":"Vinhbb96er","id":31681597,"avatar_url":"https://avatars2.githubusercontent.com/u/31681597?v=4","gravatar_id":"","url":"https://api.github.com/users/Vinhbb96er","html_url":"https://github.com/Vinhbb96er","followers_url":"https://api.github.com/users/Vinhbb96er/followers","following_url":"https://api.github.com/users/Vinhbb96er/following{/other_user}","gists_url":"https://api.github.com/users/Vinhbb96er/gists{/gist_id}","starred_url":"https://api.github.com/users/Vinhbb96er/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Vinhbb96er/subscriptions","organizations_url":"https://api.github.com/users/Vinhbb96er/orgs","repos_url":"https://api.github.com/users/Vinhbb96er/repos","events_url":"https://api.github.com/users/Vinhbb96er/events{/privacy}","received_events_url":"https://api.github.com/users/Vinhbb96er/received_events","type":"User","site_admin":false},"body":"redmine: https://dev.framgia.com/redmine/issues/168939","created_at":"2018-04-17T01:54:30Z","updated_at":"2018-04-17T02:28:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3b2d7986a86d15bd7d3520670a6b5c035aaef87a","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/framgia/servey_01/pulls/224/commits","review_comments_url":"https://api.github.com/repos/framgia/servey_01/pulls/224/comments","review_comment_url":"https://api.github.com/repos/framgia/servey_01/pulls/comments{/number}","comments_url":"https://api.github.com/repos/framgia/servey_01/issues/224/comments","statuses_url":"https://api.github.com/repos/framgia/servey_01/statuses/540b5e7fc2e33b37c729fe39b80038e0166bbf03","head":{"label":"Vinhbb96er:create-survey-logic","ref":"create-survey-logic","sha":"540b5e7fc2e33b37c729fe39b80038e0166bbf03","user":{"login":"Vinhbb96er","id":31681597,"avatar_url":"https://avatars2.githubusercontent.com/u/31681597?v=4","gravatar_id":"","url":"https://api.github.com/users/Vinhbb96er","html_url":"https://github.com/Vinhbb96er","followers_url":"https://api.github.com/users/Vinhbb96er/followers","following_url":"https://api.github.com/users/Vinhbb96er/following{/other_user}","gists_url":"https://api.github.com/users/Vinhbb96er/gists{/gist_id}","starred_url":"https://api.github.com/users/Vinhbb96er/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Vinhbb96er/subscriptions","organizations_url":"https://api.github.com/users/Vinhbb96er/orgs","repos_url":"https://api.github.com/users/Vinhbb96er/repos","events_url":"https://api.github.com/users/Vinhbb96er/events{/privacy}","received_events_url":"https://api.github.com/users/Vinhbb96er/received_events","type":"User","site_admin":false},"repo":{"id":126468010,"name":"servey_01","full_name":"Vinhbb96er/servey_01","owner":{"login":"Vinhbb96er","id":31681597,"avatar_url":"https://avatars2.githubusercontent.com/u/31681597?v=4","gravatar_id":"","url":"https://api.github.com/users/Vinhbb96er","html_url":"https://github.com/Vinhbb96er","followers_url":"https://api.github.com/users/Vinhbb96er/followers","following_url":"https://api.github.com/users/Vinhbb96er/following{/other_user}","gists_url":"https://api.github.com/users/Vinhbb96er/gists{/gist_id}","starred_url":"https://api.github.com/users/Vinhbb96er/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Vinhbb96er/subscriptions","organizations_url":"https://api.github.com/users/Vinhbb96er/orgs","repos_url":"https://api.github.com/users/Vinhbb96er/repos","events_url":"https://api.github.com/users/Vinhbb96er/events{/privacy}","received_events_url":"https://api.github.com/users/Vinhbb96er/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Vinhbb96er/servey_01","description":null,"fork":true,"url":"https://api.github.com/repos/Vinhbb96er/servey_01","forks_url":"https://api.github.com/repos/Vinhbb96er/servey_01/forks","keys_url":"https://api.github.com/repos/Vinhbb96er/servey_01/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Vinhbb96er/servey_01/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Vinhbb96er/servey_01/teams","hooks_url":"https://api.github.com/repos/Vinhbb96er/servey_01/hooks","issue_events_url":"https://api.github.com/repos/Vinhbb96er/servey_01/issues/events{/number}","events_url":"https://api.github.com/repos/Vinhbb96er/servey_01/events","assignees_url":"https://api.github.com/repos/Vinhbb96er/servey_01/assignees{/user}","branches_url":"https://api.github.com/repos/Vinhbb96er/servey_01/branches{/branch}","tags_url":"https://api.github.com/repos/Vinhbb96er/servey_01/tags","blobs_url":"https://api.github.com/repos/Vinhbb96er/servey_01/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Vinhbb96er/servey_01/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Vinhbb96er/servey_01/git/refs{/sha}","trees_url":"https://api.github.com/repos/Vinhbb96er/servey_01/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Vinhbb96er/servey_01/statuses/{sha}","languages_url":"https://api.github.com/repos/Vinhbb96er/servey_01/languages","stargazers_url":"https://api.github.com/repos/Vinhbb96er/servey_01/stargazers","contributors_url":"https://api.github.com/repos/Vinhbb96er/servey_01/contributors","subscribers_url":"https://api.github.com/repos/Vinhbb96er/servey_01/subscribers","subscription_url":"https://api.github.com/repos/Vinhbb96er/servey_01/subscription","commits_url":"https://api.github.com/repos/Vinhbb96er/servey_01/commits{/sha}","git_commits_url":"https://api.github.com/repos/Vinhbb96er/servey_01/git/commits{/sha}","comments_url":"https://api.github.com/repos/Vinhbb96er/servey_01/comments{/number}","issue_comment_url":"https://api.github.com/repos/Vinhbb96er/servey_01/issues/comments{/number}","contents_url":"https://api.github.com/repos/Vinhbb96er/servey_01/contents/{+path}","compare_url":"https://api.github.com/repos/Vinhbb96er/servey_01/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Vinhbb96er/servey_01/merges","archive_url":"https://api.github.com/repos/Vinhbb96er/servey_01/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Vinhbb96er/servey_01/downloads","issues_url":"https://api.github.com/repos/Vinhbb96er/servey_01/issues{/number}","pulls_url":"https://api.github.com/repos/Vinhbb96er/servey_01/pulls{/number}","milestones_url":"https://api.github.com/repos/Vinhbb96er/servey_01/milestones{/number}","notifications_url":"https://api.github.com/repos/Vinhbb96er/servey_01/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Vinhbb96er/servey_01/labels{/name}","releases_url":"https://api.github.com/repos/Vinhbb96er/servey_01/releases{/id}","deployments_url":"https://api.github.com/repos/Vinhbb96er/servey_01/deployments","created_at":"2018-03-23T10:12:29Z","updated_at":"2018-03-23T10:12:31Z","pushed_at":"2018-04-17T01:57:47Z","git_url":"git://github.com/Vinhbb96er/servey_01.git","ssh_url":"git@github.com:Vinhbb96er/servey_01.git","clone_url":"https://github.com/Vinhbb96er/servey_01.git","svn_url":"https://github.com/Vinhbb96er/servey_01","homepage":null,"size":18738,"stargazers_count":0,"watchers_count":0,"language":"PHP","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"framgia:improve_view","ref":"improve_view","sha":"5104f5b7e55429d2863858fc64ce6501c20104d3","user":{"login":"framgia","id":2322183,"avatar_url":"https://avatars3.githubusercontent.com/u/2322183?v=4","gravatar_id":"","url":"https://api.github.com/users/framgia","html_url":"https://github.com/framgia","followers_url":"https://api.github.com/users/framgia/followers","following_url":"https://api.github.com/users/framgia/following{/other_user}","gists_url":"https://api.github.com/users/framgia/gists{/gist_id}","starred_url":"https://api.github.com/users/framgia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/framgia/subscriptions","organizations_url":"https://api.github.com/users/framgia/orgs","repos_url":"https://api.github.com/users/framgia/repos","events_url":"https://api.github.com/users/framgia/events{/privacy}","received_events_url":"https://api.github.com/users/framgia/received_events","type":"Organization","site_admin":false},"repo":{"id":78068076,"name":"servey_01","full_name":"framgia/servey_01","owner":{"login":"framgia","id":2322183,"avatar_url":"https://avatars3.githubusercontent.com/u/2322183?v=4","gravatar_id":"","url":"https://api.github.com/users/framgia","html_url":"https://github.com/framgia","followers_url":"https://api.github.com/users/framgia/followers","following_url":"https://api.github.com/users/framgia/following{/other_user}","gists_url":"https://api.github.com/users/framgia/gists{/gist_id}","starred_url":"https://api.github.com/users/framgia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/framgia/subscriptions","organizations_url":"https://api.github.com/users/framgia/orgs","repos_url":"https://api.github.com/users/framgia/repos","events_url":"https://api.github.com/users/framgia/events{/privacy}","received_events_url":"https://api.github.com/users/framgia/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/framgia/servey_01","description":null,"fork":false,"url":"https://api.github.com/repos/framgia/servey_01","forks_url":"https://api.github.com/repos/framgia/servey_01/forks","keys_url":"https://api.github.com/repos/framgia/servey_01/keys{/key_id}","collaborators_url":"https://api.github.com/repos/framgia/servey_01/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/framgia/servey_01/teams","hooks_url":"https://api.github.com/repos/framgia/servey_01/hooks","issue_events_url":"https://api.github.com/repos/framgia/servey_01/issues/events{/number}","events_url":"https://api.github.com/repos/framgia/servey_01/events","assignees_url":"https://api.github.com/repos/framgia/servey_01/assignees{/user}","branches_url":"https://api.github.com/repos/framgia/servey_01/branches{/branch}","tags_url":"https://api.github.com/repos/framgia/servey_01/tags","blobs_url":"https://api.github.com/repos/framgia/servey_01/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/framgia/servey_01/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/framgia/servey_01/git/refs{/sha}","trees_url":"https://api.github.com/repos/framgia/servey_01/git/trees{/sha}","statuses_url":"https://api.github.com/repos/framgia/servey_01/statuses/{sha}","languages_url":"https://api.github.com/repos/framgia/servey_01/languages","stargazers_url":"https://api.github.com/repos/framgia/servey_01/stargazers","contributors_url":"https://api.github.com/repos/framgia/servey_01/contributors","subscribers_url":"https://api.github.com/repos/framgia/servey_01/subscribers","subscription_url":"https://api.github.com/repos/framgia/servey_01/subscription","commits_url":"https://api.github.com/repos/framgia/servey_01/commits{/sha}","git_commits_url":"https://api.github.com/repos/framgia/servey_01/git/commits{/sha}","comments_url":"https://api.github.com/repos/framgia/servey_01/comments{/number}","issue_comment_url":"https://api.github.com/repos/framgia/servey_01/issues/comments{/number}","contents_url":"https://api.github.com/repos/framgia/servey_01/contents/{+path}","compare_url":"https://api.github.com/repos/framgia/servey_01/compare/{base}...{head}","merges_url":"https://api.github.com/repos/framgia/servey_01/merges","archive_url":"https://api.github.com/repos/framgia/servey_01/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/framgia/servey_01/downloads","issues_url":"https://api.github.com/repos/framgia/servey_01/issues{/number}","pulls_url":"https://api.github.com/repos/framgia/servey_01/pulls{/number}","milestones_url":"https://api.github.com/repos/framgia/servey_01/milestones{/number}","notifications_url":"https://api.github.com/repos/framgia/servey_01/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/framgia/servey_01/labels{/name}","releases_url":"https://api.github.com/repos/framgia/servey_01/releases{/id}","deployments_url":"https://api.github.com/repos/framgia/servey_01/deployments","created_at":"2017-01-05T01:37:19Z","updated_at":"2018-03-29T02:58:47Z","pushed_at":"2018-04-17T01:57:49Z","git_url":"git://github.com/framgia/servey_01.git","ssh_url":"git@github.com:framgia/servey_01.git","clone_url":"https://github.com/framgia/servey_01.git","svn_url":"https://github.com/framgia/servey_01","homepage":null,"size":18744,"stargazers_count":1,"watchers_count":1,"language":"PHP","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"archived":false,"open_issues_count":2,"license":null,"forks":12,"open_issues":2,"watchers":1,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/framgia/servey_01/pulls/224"},"html":{"href":"https://github.com/framgia/servey_01/pull/224"},"issue":{"href":"https://api.github.com/repos/framgia/servey_01/issues/224"},"comments":{"href":"https://api.github.com/repos/framgia/servey_01/issues/224/comments"},"review_comments":{"href":"https://api.github.com/repos/framgia/servey_01/pulls/224/comments"},"review_comment":{"href":"https://api.github.com/repos/framgia/servey_01/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/framgia/servey_01/pulls/224/commits"},"statuses":{"href":"https://api.github.com/repos/framgia/servey_01/statuses/540b5e7fc2e33b37c729fe39b80038e0166bbf03"}},"author_association":"NONE"}}
{"actor":{"display_login":"lamngockhuong"}}