add products types edition

This commit is contained in:
Simon Vieille 2020-11-20 13:39:12 +01:00
parent bcaca44224
commit 1e76572990
Signed by: deblan
GPG key ID: 03383D15A1D31745

View file

@ -1,59 +1,69 @@
<?php
namespace OCA\Printer\Controller;
use OCP\AppFramework\Controller;
use OCP\IRequest;
use OC\Files\Filesystem;
use OCP\AppFramework\Http\JSONResponse;
use OCP\IRequest;
use Symfony\Component\Process\Process;
class PrinterController extends Controller
{
protected $language;
class PrinterController extends Controller {
public function __construct($appName, IRequest $request)
{
parent::__construct($appName, $request);
protected $language;
$this->language = \OC::$server->getL10N('printer');
}
public function __construct($appName, IRequest $request) {
/**
* callback function to get md5 hash of a file.
*
* @NoAdminRequired
*
* @param (string) $sourcefile - filename
* @param (string) $orientation - Orientation of printed file
*/
public function printfile($sourcefile, $orientation)
{
$filefullpath = \OC\Files\Filesystem::getLocalFile($sourcefile);
parent::__construct($appName, $request);
$options = [
'landscape' => [
'lpr',
$filefullpath,
],
'portrait' => [
'lpr',
'-o',
'orientation-requested=4',
$filefullpath,
],
];
// get i10n
$this->language = \OC::$server->getL10N('printer');
$success = [
'response' => 'success',
'msg' => $this->language->t('Print succeeded!'),
];
}
$error = [
'response' => 'error',
'msg' => $this->language->t('Print failed'),
];
/**
* callback function to get md5 hash of a file
* @NoAdminRequired
* @param (string) $sourcefile - filename
* @param (string) $orientation - Orientation of printed file
*/
public function printfile($sourcefile, $orientation) {
if($orientation === "landscape") {
$filefullpath = \OC\Files\Filesystem::getLocalFile($sourcefile);
exec('lpr "' . $filefullpath . '"');
return new JSONResponse(
array(
'response' => 'success',
'msg' => $this->language->t('Print succeeded!')
)
);
}
if (!isset($options[$orientation])) {
return new JSONResponse($error);
}
if($orientation === "portrait"){
$filefullpath = \OC\Files\Filesystem::getLocalFile($sourcefile);
exec('lpr -o orientation-requested=4 "' . $filefullpath . '"');
return new JSONResponse(
array(
'response' => 'success',
'msg' => $this->language->t('Print succeeded!')
)
);
} else {
return new JSONResponse(
array(
'response' => 'error',
'msg' => $this->language->t('Print failed')
)
);
};
}
$process = new Process($options[$orientation]);
$process->run();
if ($process->isSuccessful()) {
return new JSONResponse($success);
}
return new JSONResponse($error);
}
}