示例#1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $isVerbose = $output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE;
     $sourceProjectCode = $input->getOption('source-project-code');
     $targetProjectCode = $input->getOption('target-project-code');
     $targetSurveyCode = $input->getOption('target-survey-code');
     $sourceProjectResource = new ProjectResource($this->sourceClient);
     $projectResource = new ProjectResource($this->client);
     $sourceProject = $sourceProjectResource->getByCode($sourceProjectCode);
     $targetProject = $projectResource->getByCode($targetProjectCode);
     if (!$sourceProject) {
         $output->writeln("<error>Project '{$sourceProjectCode}' not found</error>");
         exit;
     }
     if (!$targetProject) {
         $output->writeln("<error>Project '{$targetProjectCode}' not found</error>");
         exit;
     }
     $sourceSurveyId = $input->getOption('source-survey-id');
     /** @type SurveyResource $fromSurveyResource */
     $fromSurveyResource = new SurveyResource($this->sourceClient);
     $toSurveyResource = new SurveyResource($this->client);
     $survey = $fromSurveyResource->getById($sourceSurveyId);
     $surveyJson = $fromSurveyResource->getExportJson($survey['id']);
     if ($targetSurveyCode) {
         $surveyJson['code'] = $targetSurveyCode;
     }
     $result = $toSurveyResource->importSurvey(['import_data' => $surveyJson, 'name' => $survey['name'], 'code' => $survey['code'], 'project_id' => $targetProject['id'], 'category_code' => $survey['category_code'], 'description' => $survey['description']]);
     $output->writeln("Survey {$result['code']} #{$result['id']} transferred");
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $isVerbose = $output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE;
     $sourceProjectCode = $input->getOption('source-project-code');
     $targetProjectCode = $input->getOption('target-project-code');
     $sourceProjectResource = new ProjectResource($this->sourceClient);
     $projectResource = new ProjectResource($this->client);
     $sourceProject = $sourceProjectResource->getByCode($sourceProjectCode);
     $targetProject = $projectResource->getByCode($targetProjectCode);
     if (!$sourceProject) {
         $output->writeln("<error>Project '{$sourceProjectCode}' not found</error>");
         exit;
     }
     if (!$targetProject) {
         $output->writeln("<error>Project '{$targetProjectCode}' not found</error>");
         exit;
     }
     if (!$targetProjectCode) {
         $targetProjectCode = $sourceProjectCode;
     }
     $sourceWaveId = $input->getOption('source-wave-id');
     $targetJobCode = $input->getOption('target-job-code');
     $jobResource = new JobResource($this->client);
     /** @type WaveResource $fromWaveResource */
     $fromWaveResource = new WaveResource($this->sourceClient);
     /** @type WaveResource $toWaveResource */
     $toWaveResource = new WaveResource($this->client);
     try {
         $wave = $fromWaveResource->getById($sourceWaveId);
     } catch (\Exception $e) {
         if (!isset($wave)) {
             $output->writeln("<error>Wave #{$sourceWaveId} not found</error>");
             exit;
         }
     }
     // if no target job code set - use current job
     if (!$targetJobCode) {
         $targetJobCode = $wave['job_code'];
     }
     $job = $jobResource->getOneBy(['code' => $targetJobCode], ['project_code' => $targetProject['code']]);
     if (!$job) {
         throw new \Exception("job '{$targetJobCode}' not found in project '{$targetProject['code']}'");
     }
     // update target job ID
     // find job ID, then update wave data
     $this->processWaveFields($wave, $job);
     $response = $toWaveResource->save($wave);
     $output->writeln("Wave {$response['code']} #{$response['id']} transferred");
 }
示例#3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     //        $output->writeln("<error>Command not implemented yet</error>");
     //        die();
     $isVerbose = $output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE;
     $sourceProject = $input->getOption('source-project-code');
     $targetProject = $input->getOption('target-project-code');
     $fromData = new DataImageResource($this->sourceClient);
     $toData = new DataImageResource($this->client);
     $projectResource = new ProjectResource($this->client);
     $userResource = new UserResource($this->client);
     $project = $projectResource->getOneBy(['code' => $targetProject]);
     if (!$project) {
         $output->writeln("<error>Target project {$targetProject} not found</error>");
         die;
     }
     $page = 0;
     $perPage = 10;
     $maxPages = 1;
     while ($page < $maxPages) {
         $dataImages = $fromData->getList(++$page, $perPage, [], [], [], ['project_code' => $sourceProject]);
         $maxPages = $dataImages['pages'];
         // if no items, return
         if (!count($dataImages['items']) || !$dataImages['total']) {
             break;
         }
         foreach ($dataImages['items'] as $key => $dataImage) {
             if ($isVerbose) {
                 $no = ($page - 1) * $perPage + $key + 1;
                 $output->writeln("{$no} - Reading member #{$dataImage['id']}");
             }
             $this->processDataFields($dataImage, $project);
             try {
                 $res = $toData->save($dataImage);
                 if ($isVerbose) {
                     $output->writeln("New member  #{$res['id']} saved");
                 }
             } catch (\Exception $e) {
                 $output->writeln("<error>Problem saving data: {$e->getMessage()} </error>");
                 var_dump($dataImage);
             }
         }
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $projectResource = new ProjectResource($this->sourceClient);
     $memberResource = new MemberResource($this->sourceClient);
     $surveyResource = new SurveyResource($this->sourceClient);
     $result = $projectResource->getList();
     foreach ($result['items'] as $idx => $project) {
         $projectCode = $project['code'];
         $result = $memberResource->getList(1, 1000, ['project_id' => $project['id'], 'permission_type_code' => 'owner']);
         $owners = implode(', ', array_map(function ($member) {
             return isset($member['code']) ? $member['code'] : '#' . $member['id'];
         }, $result['items']));
         $result = $surveyResource->getList(1, 1000, ['project_id' => $project['id']]);
         $surveys = implode("\n", array_map(function ($survey) {
             return '"' . $survey['name'] . '"';
         }, $result['items']));
         $data[] = ['code' => $projectCode, 'owners' => $owners, 'surveys' => $surveys];
     }
     $table = new Table($output);
     $table->setHeaders(['code', 'owners', 'surveys'])->setRows($data);
     $table->render();
 }
示例#5
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $name = $input->getArgument('filename');
     $projectResource = new ProjectResource($this->client);
     $userResource = new UserResource($this->client);
     $memberResource = new MemberResource($this->client);
     $reader = new \EasyCSV\Reader('new_members.csv');
     while ($row = $reader->getRow()) {
         $project = $projectResource->getByCode($row['project_code']);
         // we ned that user for admins, maybe it should be separate field
         $user = $userResource->getOneBy(['username' => $row['username']]);
         if (!$user) {
             print "user '{$row['username']}' not found\n";
         }
         try {
             $res = $memberResource->save(['code' => $row['code'], 'project_id' => $project['id'], 'user_id' => $user['id'], 'permission_type_code' => $row['permission_type_code']]);
         } catch (Exception $e) {
             print "Error importing member {$row['code']}:" . $e->getMessage() . "\n";
         }
     }
     $output->writeln($text);
 }
示例#6
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     //        $output->writeln("<error>Command not implemented yet</error>");
     //        die();
     $isVerbose = $output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE;
     $targetProject = $input->getOption('target-project-code');
     $waveId = $input->getOption('import-wave-id');
     $projectResource = new ProjectResource($this->client);
     $project = $projectResource->getByCode($targetProject);
     $sourceCsv = $input->getOption('source-csv-file');
     $csvData = str_getcsv(file_get_contents($sourceCsv), "\n");
     //parse the rows
     $columns = str_getcsv(array_shift($csvData), ',');
     $i = 0;
     foreach ($csvData as &$row) {
         $dataResource = new DataResource($this->client);
         $dataArray = str_getcsv($row, ",");
         $dataArray = array_combine($columns, $dataArray);
         $dataTypeResource = new DataTypeResource($this->client);
         $dataType = $dataTypeResource->getByCode($dataArray['DataTypeCode']);
         $data = ['code' => $dataArray['Code'], 'name' => $dataArray['Name'], 'project' => $project['@id'], 'dataTypeCode' => $dataType['@id'], 'isActive' => $dataArray['IsActive'], 'createdAt' => $dataArray['CreatedAt']];
         if ($dataArray['DataTypeCode'] == 'place') {
             $data = array_merge($data, ['latitude' => $dataArray['Latitude'], 'longitude' => $dataArray['Longitude'], 'zip' => $dataArray['Zip'], 'address' => $dataArray['Address']]);
         } elseif ($dataArray['DataTypeCode'] == 'image') {
             $data = array_merge($data, ['questionCode' => $dataArray['QuestionCode'], 'height' => intval($dataArray['Height']), 'width' => intval($dataArray['Width']), 'orientation' => intval($dataArray['Orientation']), 'tag' => $dataArray['Tag']]);
         }
         try {
             $dataResource->addForImportWave($waveId, $data);
             $i++;
         } catch (\Exception $e) {
             $output->writeln('<err>' . $e->getMessage() . '</err>');
         }
         if ($i > 10) {
             break;
         }
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $isVerbose = $output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE;
     $sourceProject = $input->getOption('source-project-code');
     $targetProject = $input->getOption('target-project-code');
     $fromMemberResource = new MemberResource($this->sourceClient);
     $toMemberResource = new MemberResource($this->client);
     $projectResource = new ProjectResource($this->client);
     $userResource = new UserResource($this->client);
     $project = $projectResource->getOneBy(['code' => $targetProject]);
     if (!$project) {
         $output->writeln("<error>Target project {$targetProject} not found</error>");
         die;
     }
     $page = 0;
     $perPage = 10;
     //        $members = $fromMemberResource->getList($page, $perPage, [], [], [], ['project_code' => $sourceProject]);
     $maxPages = 1;
     while ($page < $maxPages) {
         $members = $fromMemberResource->getList(++$page, $perPage, [], [], [], ['project_code' => $sourceProject]);
         $maxPages = $members['pages'];
         // if no items, return
         if (!count($members['items']) || !$members['total']) {
             break;
         }
         foreach ($members['items'] as $key => $member) {
             if ($isVerbose) {
                 $no = ($page - 1) * $perPage + $key + 1;
                 $output->writeln("{$no} - Reading member #{$member['id']}");
             }
             /*
              * try to find if member is already there
              * if yes - ignore. if not - import.
              * if current member doesn't have any of the $uniqueFields set
              * then ignore as we won't be able to find it later
              */
             $uniqueFields = ['code', 'email_within_project', 'phone_within_project'];
             $findByField = false;
             $findByValue = false;
             foreach ($uniqueFields as $field) {
                 if (isset($member[$field])) {
                     $findByField = $field;
                     $findByValue = $member[$field];
                     break;
                 }
             }
             if ($findByField && $findByValue) {
                 $findMember = $toMemberResource->getOneBy([$findByField => $findByValue, 'project_id' => $project['id']]);
                 if ($findMember) {
                     $output->writeln("<error>Member {$findByField}:{$findByValue} already exists for project {$project['code']}</error>");
                     continue;
                 }
             } else {
                 // ignore no-codes for now
                 $output->writeln("<error>Member #{$member['id']} doesn't have any of the required fields: " . implode(',', $uniqueFields) . "</error>");
                 continue;
             }
             if (array_search($member['permission_type_code'], ['owner']) !== false) {
                 // save admin only if user found
                 // @todo - create user first
                 $user = $userResource->getOneBy(['username' => $member['code']]);
                 if (!$user) {
                     $output->writeln("<error>Couldn't find user record for admin member {$member['code']} </error>");
                     continue;
                 }
                 $member['user_id'] = $user['id'];
             }
             $this->processMemberFields($member, $project);
             try {
                 $res = $toMemberResource->save($member);
                 if ($isVerbose) {
                     $output->writeln("New member  #{$res['id']} saved");
                 }
             } catch (\Exception $e) {
                 $output->writeln("<error>Problem saving {$findByField}:{$findByValue}:{$e->getMessage()} </error>");
                 var_dump($member);
             }
         }
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $filename = $input->getArgument('filename');
     $serverCode = $input->getOption('server-code');
     $timezoneId = $input->getOption('timezone-id');
     $projectCode = $input->getOption('project-code');
     $userResource = new UserResource($this->client);
     /** @type MemberResource $memberResource */
     $memberResource = new MemberResource($this->client);
     $projectResource = new ProjectResource($this->client);
     /** @type ProjectResource $resource */
     $resource = new ProjectResource($this->client);
     $reader = new \EasyCSV\Reader($filename, 'r', true);
     while ($row = $reader->getRow()) {
         //code,name,description,timezone_id
         $code = $row['code'];
         if ($projectCode && $code != $projectCode) {
             continue;
         }
         $params = [];
         if ($project = $resource->getOneBy(['code' => $code])) {
             $params['id'] = $project['id'];
         }
         try {
             /*
             $res = $resource->save(
                 array_merge(
                     $params,
                     [
                         'title'                  => $name = $row['name'],
                         'code'                   => $code,
                         'timezone_id'            => $timezoneId,
                         'description'            => $name." Project",
                         'background_server_code' => $serverCode,
                     ]
                 )
             );
             */
         } catch (\Exception $e) {
             printf("Error saving project: %s\n", $e->getMessage());
             printf("Project {$code} already exists\n");
         }
         $project = $projectResource->getByCode($code);
         $res = $resource->addModule($code, 'turk');
         $staffAdmins = ['tac', 'ho449'];
         try {
             foreach (array_merge([$code], $staffAdmins) as $idx => $username) {
                 $user = $userResource->getOneBy(['username' => $username]);
                 if (!$user) {
                     print "user '{$username}' not found\n";
                     continue;
                 }
                 $params = ['code' => $username, 'project_id' => $project['id'], 'user_id' => $user['id'], 'permission_type_code' => 'owner', 'enrollment_status_code' => 'notenrolled'];
                 $member = $memberResource->getOneBy(['code' => $username, 'project_id' => $project['id']]);
                 if ($member) {
                     $output->writeln("<error>Member '{$username}' already exists for project " . $project['code'] . "</error>");
                     continue;
                 }
                 print "Saving member '{$username}' for project " . $project['code'] . "\n";
                 $res = $memberResource->save($params);
             }
         } catch (Exception $e) {
             var_dump($params);
             $output->writeln("<error>Error importing member: {$e->getMessage()}</error>");
         }
     }
 }
示例#9
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Survos\Client\SurvosClient;
use Survos\Client\Resource\MemberResource;
use Survos\Client\Resource\ProjectResource;
$config = json_decode(file_get_contents(__DIR__ . '/config.json'), true);
$client = new SurvosClient($config['endpoint']);
if (!$client->authorize($config['username'], $config['password'])) {
    throw new \Exception('Wrong credentials!');
}
// get all projects
$userResource = new \Survos\Client\Resource\UserResource($client);
//$user= $userResource->getOneBy('username', 'tac');
$pResource = new ProjectResource($client);
$project = $pResource->getByCode('demo');
$resource = new MemberResource($client);
$resource->save(['code' => "new_project_code5", 'phone_within_project' => '+447834274472', 'email_within_project' => '*****@*****.**', 'project_id' => $project['id']]);
$res = $pResource->addModule('demo', 'field');
echo $res;
示例#10
0
<?php

require __DIR__ . '/../vendor/autoload.php';
use Survos\Client\SurvosClient;
use Survos\Client\Resource\ProjectResource;
$config = json_decode(file_get_contents(__DIR__ . '/config.json'), true);
$client = new SurvosClient($config['endpoint']);
if (!$client->authorize($config['username'], $config['password'])) {
    throw new \Exception('Wrong credentials!');
}
// get all projects
$resource = new ProjectResource($client);
$res = $resource->save(['title' => "new poject", 'code' => "new_project_code", 'timezone_id' => 1]);