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