public function process()
{
$process = new FeedbackProcess(request()->get('_session'));
- $res=$process->process();
-
- $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($res);
- $tmp = Files::tempnam().".xlsx";
- $writer->setPreCalculateFormulas(false);
- $writer->save($tmp);
+ $process->process();
+ return response()->json(['ok' => true]);
+ }
- $res= response()->download($tmp, 'res.xlsx', ['content-type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'])->deleteFileAfterSend();
- return $res;
+ public function download()
+ {
+ $process = new FeedbackProcess(request()->get('session'));
+ return response()->download($process->getPath() . '/res.xlsx', $process->getFinalFilename(), ['content-type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
}
public function upload()
namespace App\Models;
+use Cubist\Util\Files\Files;
use Cubist\Util\PHP;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx;
use PhpOffice\PhpSpreadsheet\Style\Fill;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
+use PhpOffice\PhpSpreadsheet\Worksheet\Drawing;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use Symfony\Component\HttpFoundation\File\UploadedFile;
{
protected $_path;
protected $_template;
+ protected $_templateName;
protected $_feedbacks = [];
public function __construct($id)
if (file_exists($jsonFile)) {
$json = json_decode(file_get_contents($jsonFile), true);
$this->setTemplate($json['template']);
+ $this->setTemplateName($json['templateName']);
$this->setFeedbacks($json['feedbacks']);
+
}
}
$target = $uploadedFile->move($this->getPath());
if ($name === 'template') {
+ $this->setTemplateName($uploadedFile->getClientOriginalName());
$this->setTemplate($target->getPathname());
} else if ($name === 'feedbacks') {
$this->addFeedback($target->getPathname());
$this->_feedbacks[] = $feedback;
}
+ /**
+ * @return mixed
+ */
+ public function getTemplateName()
+ {
+ return $this->_templateName;
+ }
+
+ /**
+ * @param mixed $templateName
+ */
+ public function setTemplateName($templateName): void
+ {
+ $this->_templateName = $templateName;
+ }
+
public function __destruct()
{
$this->saveSession();
*/
public function saveSession()
{
- file_put_contents($this->_getSessionFile(), json_encode(['template' => $this->getTemplate(), 'feedbacks' => $this->getFeedbacks()], JSON_THROW_ON_ERROR));
+ file_put_contents($this->_getSessionFile(), json_encode(['template' => $this->getTemplate(), 'templateName' => $this->getTemplateName(), 'feedbacks' => $this->getFeedbacks()], JSON_THROW_ON_ERROR));
}
public function process()
}
// Make first sheet active
$template->setActiveSheetIndex(0);
- return $template;
+
+ $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($template);
+ $res = $this->getPath() . "/res.xlsx";
+ $writer->setPreCalculateFormulas(false);
+ $writer->save($res);
}
/**
}
}
+ // Define score coef
+
$coefs = [
'YA' => 100000,
'YB' => 10000,
'NB' => 10,
'NC' => 1];
+ //Compute score by line
$scores = [];
foreach ($rankingData as $row => $data) {
$scores[$row] = 0;
$scores[$row] += $s;
}
}
+
+ // Sort score to define ranks
arsort($scores);
$rank = 1;
foreach ($scores as $row => $score) {
$rank++;
}
+ // Fix images
+ foreach ($templateSheet->getDrawingCollection() as $drawing) {
+ if ($drawing instanceof Drawing) {
+ $dim = getimagesize($drawing->getPath());
+ $drawing->setResizeProportional(false);
+ $drawing->setWidth($dim[0]);
+ $drawing->setHeight($dim[1]);
+ $drawing->setResizeProportional(true);
+ $drawing->setWidth(300);
+ } else {
+ $drawing->setResizeProportional(false);
+ $drawing->setWidth(300);
+ $drawing->setHeight(80);
+ $drawing->setResizeProportional(true);
+ }
+ $drawing->setOffsetX(0);
+ $drawing->setOffsetY(0);
+
+ }
+
+ }
+
+ public function getFinalFilename()
+ {
+ $e = explode('/', $this->getTemplateName());
+ $f = array_pop($e);
+ $e = explode('.', $f);
+ $ext = array_pop($e);
+ return implode('.', $e) . '-rank.' . $ext;
}
}
var token = $('input[name="_token"]').attr('value');
var session = $('input[name="_session"]').attr('value');
+var hasTemplate = false;
+var hasFeedback = false;
+
var myDropzone = new Dropzone(dropzone1, {
dictDefaultMessage: message,
dictRemoveFile: removeFile,
+ acceptedFiles: '.xlsx',
url: '/upload',
autoProcessQueue: true,
autoDiscover: false,
formData.append("_token", token);
formData.append("_session", session);
},
+
+});
+myDropzone.on("success", function (file) {
+ hasTemplate = true;
+ checkFiles();
});
dropzones.push(myDropzone)
myDropzone = new Dropzone(dropzone2, {
dictDefaultMessage: message,
url: '/upload',
+ acceptedFiles: '.xlsx',
autoProcessQueue: true,
autoDiscover: false,
uploadMultiple: false,
formData.append("_session", session);
},
});
+myDropzone.on("success", function (file) {
+ hasFeedback = true;
+ checkFiles();
+});
dropzones.push(myDropzone)
+function checkFiles() {
+ if (hasTemplate && hasFeedback) {
+ $('.submit').addClass('visible');
+ }
+}
+
$(function () {
$("body").append('<div id="wait"></div>');
- $(document).on('click', 'input[type="submit"]', function () {
+ $(document).on('click', '.submit', function () {
$("#wait").show();
- return true;
+ $(this).attr('value', 'Traitement en cours');
+ $.post('/process', {'_token': token, '_session': session}, function (data) {
+ $(".submit").attr('value', 'Envoyer');
+ $("#wait").hide();
+ window.location = '/download?session=' + session;
+ });
+ return false;
});
});