Skip to content

Commit

Permalink
Yii::$app->getModule('pdfjs')
Browse files Browse the repository at this point in the history
  • Loading branch information
sugeng-sulistiyawan committed Sep 16, 2020
1 parent 905b5ba commit 6ece5db
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 104 deletions.
90 changes: 45 additions & 45 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,49 @@
*/
class Module extends \yii\base\Module
{
/**
*
* @var array $buttons
*/
public $buttons = [];

/**
*
* @var array $waterMark
*/
public $waterMark = [];

/**
* @inheritdoc
*/
public $controllerNamespace = 'diecoding\pdfjs\controllers';

/**
* @inheritdoc
*/
public function init()
{
parent::init();

$waterMarkDefault = [
'text' => '',
'alpha' => '0.5',
'color' => 'red'
];

if (!empty($this->waterMark)) {
$this->waterMark = ArrayHelper::merge($waterMarkDefault, $this->waterMark);
} else {
$this->waterMark = $waterMarkDefault;
}

$this->buttons = ArrayHelper::merge([
'presentationMode' => true,
'openFile' => true,
'print' => true,
'download' => true,
'viewBookmark' => true,
'secondaryToolbarToggle' => true,
], $this->buttons);
}
/**
*
* @var array $buttons
*/
public $buttons = [];

/**
*
* @var array $waterMark
*/
public $waterMark = [];

/**
* @inheritdoc
*/
public $controllerNamespace = 'diecoding\pdfjs\controllers';

/**
* @inheritdoc
*/
public function init()
{
parent::init();

$waterMarkDefault = [
'text' => '',
'alpha' => '0.5',
'color' => 'red'
];

if (!empty($this->waterMark)) {
$this->waterMark = ArrayHelper::merge($waterMarkDefault, $this->waterMark);
} else {
$this->waterMark = $waterMarkDefault;
}

$this->buttons = ArrayHelper::merge([
'presentationMode' => true,
'openFile' => true,
'print' => true,
'download' => true,
'viewBookmark' => true,
'secondaryToolbarToggle' => true,
], $this->buttons);
}
}
82 changes: 41 additions & 41 deletions src/PdfJs.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,51 @@
*/
class PdfJs extends \yii\base\Widget
{
/**
*
* @var string $url
*/
public $url;
/**
*
* @var string $url
*/
public $url;

/**
*
* @var array $options
*/
public $options = [];
/**
*
* @var array $options
*/
public $options = [];

/**
*
* @var array $buttons
*/
public $buttons = [];
/**
*
* @var array $buttons
*/
public $buttons = [];

/**
* @inheritdoc
*/
public function init()
{
parent::init();
$this->view->registerAssetBundle(PdfJsAsset::className());
/**
* @inheritdoc
*/
public function init()
{
parent::init();
$this->view->registerAssetBundle(PdfJsAsset::className());

$module = new Module();
$buttons = $module->buttons;
$this->buttons = ArrayHelper::merge($buttons, $this->buttons);
}
$module = Yii::$app->getModule('pdfjs');
$buttons = $module->buttons;
$this->buttons = ArrayHelper::merge($buttons, $this->buttons);
}

/**
* @inheritdoc
*/
public function run()
{
if (!array_key_exists('style', $this->options)) {
$this->options['style'] = 'border:solid 2px #404040; width:' . $this->width . '; height:' . $this->height . ';';
}
/**
* @inheritdoc
*/
public function run()
{
if (!array_key_exists('style', $this->options)) {
$this->options['style'] = 'border:solid 2px #404040; width:' . $this->width . '; height:' . $this->height . ';';
}

return $this->render('viewer', [
'options' => $this->options,
'url' => $this->url,
'buttons' => $this->buttons,
'id' => $this->id
]);
}
return $this->render('viewer', [
'options' => $this->options,
'url' => $this->url,
'buttons' => $this->buttons,
'id' => $this->id
]);
}
}
3 changes: 1 addition & 2 deletions src/controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace diecoding\pdfjs\controllers;

use diecoding\pdfjs\Module;
use Yii;
use yii\helpers\ArrayHelper;
use yii\web\Controller;
Expand All @@ -29,7 +28,7 @@ class DefaultController extends Controller
*/
public function actionIndex()
{
$module = new Module();
$module = Yii::$app->getModule('pdfjs');
$buttons = $module->buttons;
$waterMark = $module->waterMark;
if (Yii::$app->request->isPost) {
Expand Down
35 changes: 19 additions & 16 deletions src/views/viewer.php
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use yii\widgets\ActiveForm;
$url = Url::to(['/pdfjs','file'=>Url::to($url)]);

$url = Url::to(['/pdfjs', 'file' => Url::to($url)]);
$this->registerJs('
$("#pdfjs-form-'.$id.'").submit();
$("#pdfjs-'.$id.'").css("background-color","#404040");
$("#pdfjs-form-' . $id . '").submit();
$("#pdfjs-' . $id . '").css("background-color","#404040");
');

?>

<?php $form = ActiveForm::begin([
'id'=>'pdfjs-form-'.$id,
'options' => [
'class' => 'form-horizontal',
'target'=> 'pdfjs-'.$id
],
'action'=>$url
'id' => 'pdfjs-form-' . $id,
'options' => [
'class' => 'form-horizontal',
'target' => 'pdfjs-' . $id
],
'action' => $url
]) ?>
<?php foreach ($buttons as $btn => $value):?>
<?= $value == false ? Html::hiddenInput($btn,0) : null;?>
<?php foreach ($buttons as $btn => $value) : ?>
<?= $value == false ? Html::hiddenInput($btn, 0) : null; ?>
<?php endforeach; ?>
<?php ActiveForm::end() ?>

<?= Html::tag('iframe','',ArrayHelper::merge([
'id'=>'pdfjs-'.$id,
'name'=>'pdfjs-'.$id
],$options));
?>
<?= Html::tag('iframe', '', ArrayHelper::merge([
'id' => 'pdfjs-' . $id,
'name' => 'pdfjs-' . $id
], $options));
?>

0 comments on commit 6ece5db

Please sign in to comment.