Commit 768a8dc3 authored by ZeMKI's avatar ZeMKI

export for new sorting

* now the export can export the new values for the new sorting.
* optimized export.
* optimized models for phpstorm.
parent 1417de50
......@@ -9,7 +9,9 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/arietimmerman/laravel-url-shortener" />
<excludeFolder url="file://$MODULE_DIR$/vendor/barryvdh/laravel-debugbar" />
<excludeFolder url="file://$MODULE_DIR$/vendor/barryvdh/laravel-dompdf" />
<excludeFolder url="file://$MODULE_DIR$/vendor/barryvdh/laravel-ide-helper" />
<excludeFolder url="file://$MODULE_DIR$/vendor/barryvdh/laravel-translation-manager" />
<excludeFolder url="file://$MODULE_DIR$/vendor/barryvdh/reflection-docblock" />
<excludeFolder url="file://$MODULE_DIR$/vendor/binarytorch/larecipe" />
<excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/dnoegel/php-xdg-base-dir" />
......
......@@ -170,6 +170,8 @@
<path value="$PROJECT_DIR$/vendor/phenx/php-svg-lib" />
<path value="$PROJECT_DIR$/vendor/phpstan/phpdoc-parser" />
<path value="$PROJECT_DIR$/vendor/fzaninotto/faker" />
<path value="$PROJECT_DIR$/vendor/barryvdh/laravel-ide-helper" />
<path value="$PROJECT_DIR$/vendor/barryvdh/reflection-docblock" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="7.2" />
......
This diff is collapsed.
This diff is collapsed.
......@@ -5,6 +5,31 @@ namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* App\Action
*
* @property int $id
* @property string $name
* @property string|null $description
* @property string $url
* @property int|null $user_id
* @property string $time
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\User|null $user
* @method static \Illuminate\Database\Eloquent\Builder|\App\Action newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Action newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Action query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Action whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Action whereDescription($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Action whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Action whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Action whereTime($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Action whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Action whereUrl($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Action whereUserId($value)
* @mixin \Eloquent
*/
class Action extends Model
{
/**
......
......@@ -6,24 +6,30 @@ use App\InterviewTokens;
use App\Study;
use App\Token;
use Illuminate\Support\Collection;
use Image;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Storage;
class AllInterviewTokenExport implements FromCollection, WithMapping, WithHeadings
{
use Exportable;
private $id;
/**
* @var array
*/
private $head;
/**
* AllInterviewTokenExport constructor.
* @param $id
* @param $id
* @param array $headings
*/
public function __construct($id)
public function __construct($id, $headings = [])
{
$this->id = $id;
$this->head = $headings;
}
/**
......@@ -31,16 +37,22 @@ class AllInterviewTokenExport implements FromCollection, WithMapping, WithHeadin
*/
public function headings(): array
{
return [
'#',
'token name',
'circle',
'distance from center (pixels)',
'sorting number',
'position (pixels)',
'% percentage position',
'classifiers'
];
$columnNames = ["token id"];
array_push($columnNames, "token_name");
array_push($columnNames, "interview id");
array_push($columnNames, "interviewee");
array_push($columnNames, "circle");
array_push($columnNames, "distance from center (pixels)");
array_push($columnNames, "sorting number");
array_push($columnNames, "position (pixels)");
array_push($columnNames, "% percentage position");
array_push($columnNames, "classifiers");
foreach ($this->head as $column)
{
array_push($columnNames, $column);
}
return $columnNames;
}
/**
......@@ -51,14 +63,18 @@ class AllInterviewTokenExport implements FromCollection, WithMapping, WithHeadin
{
$printArray = [];
foreach ($study->interviews as $emptyInterview) {
foreach ($study->interviews as $emptyInterview)
{
$allinterviews = InterviewTokens::where('interview_id', $emptyInterview->id)->get();
array_push($printArray, [$emptyInterview->interviewed]);
foreach ($allinterviews as $interview) {
foreach ($allinterviews as $token)
{
if ($this->invalidData($interview)) continue;
$this->formatTokenValuesForExport($interview, $toprint);
array_push($printArray, $toprint);
if ($this->invalidData($token)) continue;
$this->formatTokenValuesForExport($token, $toPrint, $emptyInterview->interviewed);
array_push($printArray, $toPrint);
}
}
return $printArray;
......@@ -75,37 +91,56 @@ class AllInterviewTokenExport implements FromCollection, WithMapping, WithHeadin
}
/**
* @param $interview
* @param $toprint
* @param $token
* @param $toPrint
* @param $interviewee
*/
private function formatTokenValuesForExport($interview, &$toprint): void
private function formatTokenValuesForExport($token, &$toPrint,$interviewee): void
{
if (isset($interview->valutation->percentagePosition)) {
$percentagePosition = "x: " . $interview->valutation->percentagePosition->x . " y:" . $interview->valutation->percentagePosition->y;
} else {
if (isset($token->valutation->percentagePosition))
{
$percentagePosition = "x: " . $token->valutation->percentagePosition->x . " y:" . $token->valutation->percentagePosition->y;
} else
{
$percentagePosition = '';
}
if (is_object($interview->valutation->position)) {
$position = "x: " . $interview->valutation->position->x . " y:" . $interview->valutation->position->y;
} else {
$position = $interview->valutation->position;
if (is_object($token->valutation->position))
{
$position = "x: " . $token->valutation->position->x . " y:" . $token->valutation->position->y;
} else
{
$position = $token->valutation->position;
}
if (is_array($interview->valutation->classifiers)) {
if (is_array($token->valutation->classifiers))
{
$classifiers = "";
foreach ($interview->valutation->classifiers as $classifier) {
foreach ($token->valutation->classifiers as $classifier)
{
$classifiers .= $classifier->basename . " - ";
}
}
$toprint = [
$interview->token_id,
Token::where('id', $interview->token_id)->first()->name,
$interview->valutation->circle,
$interview->valutation->distance,
$interview->valutation->sorting,
$position,
$percentagePosition,
$classifiers
];
$toPrint["token id"] = $token->token_id;
$toPrint["token_name"] = Token::where('id', $token->token_id)->first()->name;
$toPrint['interview id'] = $token->interview_id;
$toPrint['interviewee'] = $interviewee;
$toPrint["circle"] = $token->valutation->circle;
$toPrint["distance from center (pixels)"] = $token->valutation->distance;
$toPrint["sorting number"] = $token->valutation->sorting;
$toPrint["position (pixels)"] = $position;
$toPrint["% percentage position"] = $percentagePosition;
$toPrint["classifiers"] = $classifiers;
if ($token->interview->study->sortings[0]->id === 2)
{
$toPrint['section number'] = $token->valutation->section;
$toPrint['section name'] = $token->valutation->sectionName;
}
}
/**
......
......@@ -5,6 +5,27 @@ namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
/**
* App\Answer
*
* @property int $id
* @property int|null $question_id
* @property array $answer
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Interview[] $interviews
* @property-read int|null $interviews_count
* @property-read \App\Question|null $question
* @method static \Illuminate\Database\Eloquent\Builder|\App\Answer newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Answer newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Answer query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Answer whereAnswer($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Answer whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Answer whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Answer whereQuestionId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Answer whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Answer extends Model
{
/**
......
......@@ -9,6 +9,29 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Image;
/**
* App\Files
*
* @property int $id
* @property string $type
* @property string $path
* @property string $size
* @property int|null $interview_id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \App\Interview|null $interview
* @method static \Illuminate\Database\Eloquent\Builder|\App\Files newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Files newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Files query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Files whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Files whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Files whereInterviewId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Files wherePath($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Files whereSize($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Files whereType($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Files whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Files extends Model
{
/**
......
......@@ -16,8 +16,10 @@ use Exception;
use File;
use Helper;
use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Routing\ResponseFactory;
use Illuminate\Contracts\View\Factory;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\View\View;
......@@ -162,12 +164,12 @@ class InterviewController extends Controller
/**
* @param Interview $interview
* @param Request $request
* @return ResponseFactory|Response
* @return JsonResponse
* @throws Exception
*/
public function destroy(Interview $interview, Request $request)
{
if (!auth()->user()->can('delete-interviews', $interview->study->id)) return response('You are not authorized to delete this study.', 403);
if (!auth()->user()->can('delete-interviews', $interview->study->id)) return response()->json('You are not authorized to delete this study.', 403);
$id = $interview->id;
$interview->files()->delete();
$interview->answers()->detach();
......@@ -188,9 +190,25 @@ class InterviewController extends Controller
public function export(Interview $interview)
{
if (!auth()->user()->can('read-studies', $interview->study_id)) abort(403, "You are not authorized to download these data.");
return (new InterviewTokenExport($interview->id))->download($interview->interviewed . ' tokens.xlsx');
$headings = $this->getHeadings($interview->study);
return (new InterviewTokenExport($interview->id, $headings))->download($interview->interviewed . ' tokens.xlsx');
}
public function getHeadings($study)
{
if($study->sortings[0]->id == 2)
{
return ["section number","section name"];
}else return [];
}
/**
* @return Application|Factory|View
*/
public function done()
{
return view('interview.done');
......
......@@ -40,6 +40,19 @@ class StudyInterviewController extends Controller
public function exportall(Study $study)
{
if (!auth()->user()->can('read-studies', $study->id)) abort(403, "You are not authorized to download these data.");
return (new AllInterviewTokenExport($study->id))->download('Interviews from study' . $study->name . '.xlsx');
$headings = $this->getHeadings($study);
return (new AllInterviewTokenExport($study->id, $headings))->download('Interviews from study' . $study->name . '.xlsx');
}
public function getHeadings($study)
{
if($study->sortings[0]->id == 2)
{
return ["section number","section name"];
}else return [];
}
}
......@@ -4,6 +4,37 @@ namespace App;
use Illuminate\Database\Eloquent\Model;
/**
* App\Interview
*
* @property int $id
* @property \App\User $author
* @property string $interviewed
* @property int|null $study_id
* @property string $start
* @property string $end
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Answer[] $answers
* @property-read int|null $answers_count
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Files[] $files
* @property-read int|null $files_count
* @property-read \App\Study|null $study
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Token[] $tokens
* @property-read int|null $tokens_count
* @method static \Illuminate\Database\Eloquent\Builder|\App\Interview newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Interview newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Interview query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Interview whereAuthor($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Interview whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Interview whereEnd($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Interview whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Interview whereInterviewed($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Interview whereStart($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Interview whereStudyId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Interview whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Interview extends Model
{
/* protected $casts = [
......
......@@ -2,83 +2,95 @@
namespace App\Exports;
use App\Interview;
use App\InterviewTokens;
use App\Token;
use Illuminate\Support\Collection;
use Image;
use Maatwebsite\Excel\Concerns\Exportable;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Storage;
class InterviewTokenExport implements FromCollection, WithMapping, WithHeadings
{
use Exportable;
/**
* @var array
*/
private $head;
private $id;
/**
* InterviewTokenExport constructor.
* @param $id
* @param $id
* @param array $headings
*/
public function __construct($id)
public function __construct($id,$headings = [])
{
$this->id = $id;
$this->head = $headings;
}
/**
* @return array
*/
public function headings(): array
{
return [
'#',
'token name',
'circle',
'distance from center (pixels)',
'sorting number',
'position (pixels)',
'% percentage position',
'classifiers'
];
$columnNames = ["#"];
array_push($columnNames, "token_name");
array_push($columnNames, "circle");
array_push($columnNames, "distance from center (pixels)");
array_push($columnNames, "sorting number");
array_push($columnNames, "position (pixels)");
array_push($columnNames, "% percentage position");
array_push($columnNames, "classifiers");
foreach ($this->head as $column) {
array_push($columnNames, $column);
}
return $columnNames;
}
/**
* @return array
* @var Interview $interview
* @var Token $token
*/
public function map($interview): array
public function map($token): array
{
if ($this->invalidData($interview)) return [];
if (isset($interview->valutation->percentagePosition)) {
$percentagePosition = "x: " . $interview->valutation->percentagePosition->x . " y:" . $interview->valutation->percentagePosition->y;
} else {
$percentagePosition = '';
}
if (is_object($interview->valutation->position)) {
$position = "x: " . $interview->valutation->position->x . " y:" . $interview->valutation->position->y;
} else {
$position = $interview->valutation->position;
}
if (is_array($interview->valutation->classifiers)) {
if ($this->invalidData($token)) return [];
$percentagePosition = isset($token->valutation->percentagePosition) ? "x: " . $token->valutation->percentagePosition->x . " y:" . $token->valutation->percentagePosition->y : '';
$position = is_object($token->valutation->position) ? "x: " . $token->valutation->position->x . " y:" . $token->valutation->position->y : $token->valutation->position;
if (is_array($token->valutation->classifiers))
{
$classifiers = "";
foreach ($interview->valutation->classifiers as $classifier) {
foreach ($token->valutation->classifiers as $classifier)
{
$classifiers .= $classifier->basename . " - ";
}
}
return [
$interview->token_id,
Token::where('id', $interview->token_id)->first()->name,
$interview->valutation->circle,
$interview->valutation->distance,
$interview->valutation->sorting,
$position,
$percentagePosition,
$classifiers
];
$tempValuesArray = [];
$tempValuesArray["#"] = $token->token_id;
$tempValuesArray["token_name"] = Token::where('id', $token->token_id)->first()->name;
$tempValuesArray["circle"] = $token->valutation->circle;
$tempValuesArray["distance from center (pixels)"] = $token->valutation->distance;
$tempValuesArray["sorting number"] = $token->valutation->sorting;
$tempValuesArray["position (pixels)"] = $position;
$tempValuesArray["% percentage position"] = $percentagePosition;
$tempValuesArray["classifiers"] = $classifiers;
if ($token->interview->study->sortings[0]->id === 2)
{
$tempValuesArray['section number'] = $token->valutation->section;
$tempValuesArray['section name'] = $token->valutation->sectionName;
}
return $tempValuesArray;
}
/**
* @param $interview
* @param $token
* @return bool
*/
private function invalidData($interview): bool
......@@ -94,3 +106,5 @@ class InterviewTokenExport implements FromCollection, WithMapping, WithHeadings
return InterviewTokens::where('interview_id', $this->id)->get();
}
}
......@@ -4,6 +4,29 @@ namespace App;
use Illuminate\Database\Eloquent\Model;
/**
* App\InterviewTokens
*
* @property int $id
* @property int|null $interview_id
* @property int|null $token_id
* @property string $valutation
* @property int|null $sorting_id
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @method static \Illuminate\Database\Eloquent\Builder|\App\InterviewTokens newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\InterviewTokens newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\InterviewTokens query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\InterviewTokens whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\InterviewTokens whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\InterviewTokens whereInterviewId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\InterviewTokens whereSortingId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\InterviewTokens whereTokenId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\InterviewTokens whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\InterviewTokens whereValutation($value)
* @mixin \Eloquent
* @property-read \App\Interview|null $interview
*/
class InterviewTokens extends Model
{
/**
......@@ -22,4 +45,9 @@ class InterviewTokens extends Model
return json_decode($value);
}
public function interview()
{
return $this->belongsTo(Interview::class);
}
}
......@@ -4,6 +4,28 @@ namespace App;
use Laratrust\Models\LaratrustPermission;
/**
* App\Permission
*
* @property int $id
* @property string $name
* @property string|null $display_name
* @property string|null $description
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Role[] $roles
* @property-read int|null $roles_count
* @method static \Illuminate\Database\Eloquent\Builder|\App\Permission newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Permission newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Permission query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\Permission whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Permission whereDescription($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Permission whereDisplayName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Permission whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Permission whereName($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Permission whereUpdatedAt($value)
* @mixin \Eloquent
*/
class Permission extends LaratrustPermission
{
}
......@@ -4,6 +4,22 @@ namespace App;
use Illuminate\Database\Eloquent\Model;
/**
* App\PermissionUser
*
* @property int $permission_id
* @property int $user_id
* @property string $user_type
* @property int|null $study_id
* @method static \Illuminate\Database\Eloquent\Builder|\App\PermissionUser newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\PermissionUser newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|\App\PermissionUser query()
* @method static \Illuminate\Database\Eloquent\Builder|\App\PermissionUser wherePermissionId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\PermissionUser whereStudyId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\PermissionUser whereUserId($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\PermissionUser whereUserType($value)
* @mixin \Eloquent
*/
class PermissionUser extends Model
{
/**
......
......@@ -4,6 +4,35 @@ namespace App;
use Illuminate\Database\Eloquent\Model;
/**
* App\Profile