예제 #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     die('not implemented yet');
     $isVerbose = $output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE;
     $projectCode = $input->getOption('project-code');
     //        $limit = $input->getOption('limit');
     $taskResource = new TaskResource($this->sourceClient);
     $page = 0;
     $perPage = 10;
     $maxPages = 1;
     $criteria = [];
     $data = [];
     while ($page < $maxPages) {
         $tasks = $taskResource->getList(++$page, $perPage, $this->getTaskCriteria(), [], [], ['project_code' => $projectCode, 'PII' => 1]);
         $maxPages = $tasks['pages'];
         // if no items, return
         if (!count($tasks['items']) || !$tasks['total']) {
             break;
         }
         foreach ($tasks['items'] as $key => $task) {
             if ($isVerbose) {
                 $no = ($page - 1) * $perPage + $key + 1;
                 $output->writeln("{$no} - Reading member #{$task['id']}");
             }
             if ($this->checkAction($task)) {
                 // do action (needs implementing in task resource helper)
                 //                    $taskResource->setApplicantsStatus([$task['id']], 'accept', 'Accepted via API');
                 var_dump($task);
                 if ($isVerbose) {
                     $output->writeln("action on task  #{$task['id']}");
                 }
             }
         }
     }
 }
 /**
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->services = [];
     $isVerbose = $output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE;
     $projectCode = $input->getOption('project-code');
     /** @type AssignmentResource $assignmentResource */
     $assignmentResource = new AssignmentResource($this->sourceClient);
     $page = 0;
     $perPage = 10;
     $maxPages = 1;
     $criteria = [];
     $data = [];
     // need much better filter!  Maybe the survey or wave needs to associate itself with an external service?
     $assignments = $assignmentResource->getList(1, 1, ['survey_response_status_code' => 'initiated'], null, null, ['project_code' => 'behattest']);
     // if no items, return
     if (!count($assignments['items']) || !$assignments['total']) {
         return;
     }
     $tasksIds = array_map(function ($item) {
         return $item['task_id'];
     }, $assignments['items']);
     $taskResource = new TaskResource($this->sourceClient);
     $tasks = $taskResource->getList(null, null, ['id' => array_unique($tasksIds)], ['id' => SurvosCriteria::IN]);
     $surveyByTask = [];
     foreach ($tasks['items'] as $task) {
         $surveyByTask[$task['id']] = isset($task['survey_json']) ? json_decode($task['survey_json'], true) : null;
     }
     foreach ($assignments['items'] as $key => $assignment) {
         $taskId = $assignment['task_id'];
         $survey = $surveyByTask[$taskId];
         // $answers = [];
         foreach ($survey['questions'] as $question) {
             if ($isVerbose) {
                 $output->writeln("Checking question \\'{$question['text']}\\' ");
             }
             switch ($question['code']) {
                 case 'temp':
                     $weatherData = $this->getWeatherData();
                     // needs persisting to responses
                     $answers[$question['code']] = $weatherData['main']['temp'];
                     break;
                 case 'wind_speed':
                     $weatherData = $this->getWeatherData();
                     $answers[$question['code']] = $weatherData['wind']['speed'];
                     break;
                 default:
                     throw new Exception("Unhandled field '{$question['code']}' in survey");
             }
         }
         if (!empty($answers)) {
             $assignment['flat_data'] = array_merge($assignment['flat_data'] ?: [], $answers);
             $assignmentResource->save($assignment);
         }
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $isVerbose = $output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE;
     $projectCode = $input->getOption('project-code');
     $limit = $input->getOption('limit');
     $tasksResource = new TaskResource($this->sourceClient);
     $params = [];
     if ($projectCode) {
         $params['project_code'] = $projectCode;
     }
     $criteria = [];
     if ($taskTypeCode = $input->getOption('task_type_code')) {
         $criteria['task_type_code'] = $taskTypeCode;
     }
     $page = 0;
     $perPage = 100;
     $maxPages = 1;
     $data = [];
     $no = 1;
     $resolver = new OptionsResolver();
     $resolver->setDefaults($keys = ['no' => null, 'code' => '', 'wave_id' => null, 'project_code' => null, 'assignment_count' => null, 'task_type_code' => null, 'task_status_code' => null, 'expiration_time' => null, 'reward' => null, 'max_assignments' => null]);
     $table = new Table($output);
     $table->setHeaders(array_keys($keys));
     while ($page < $maxPages) {
         $tasks = $tasksResource->getList(++$page, $perPage, $criteria, [], [], $params);
         $maxPages = $tasks['pages'];
         // if no items, return
         printf("Items: %d of Total: %d, Limit: {$limit}, No: {$no}\n", count($tasks['items']), $tasks['total']);
         if (!count($tasks['items']) || !$tasks['total'] || $limit > 0 && $no > $limit) {
             break;
         }
         foreach ($tasks['items'] as $task) {
             $taskData = [];
             foreach ($keys as $key => $default) {
                 $taskData[$key] = isset($task[$key]) ? $task[$key] : $default;
             }
             $taskData['no'] = $no;
             $table->addRow($taskData);
             $no++;
         }
         $table->render();
     }
 }