-
Notifications
You must be signed in to change notification settings - Fork 4
/
QrReader.php
53 lines (45 loc) · 1.46 KB
/
QrReader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
namespace odaialali\qrcodereader;
use yii\helpers\Html;
/**
*
*/
class QrReader extends \yii\base\Widget
{
public $readerWidth;
public $readerHeight;
public $name;
public $options;
public $successCallback;
public function init() {
if($this->readerWidth === null){
$this->readerWidth = '300px';
}
if($this->readerHeight === null){
$this->readerHeight = '250px';
}
if($this->successCallback === null){
$this->successCallback = 'function(data){console.log(data)}';
}
QrReaderAsset::register($this->getView());
}
public function run()
{
$this->registerJsOptions();
echo Html::tag('div', '', [
'id' => $this->id."-reader",
'class' => 'qr-reader',
'style' => "width:$this->readerWidth;height:$this->readerHeight;"
]);
$this->options['id'] = $this->id;
echo Html::input('text', $this->name, '', $this->options);
// return Html::tag('div', $reader, [
// 'class' => 'qrcode-reader-container'
// ]);
}
protected function registerJsOptions(){
$view = $this->getView();
$view->registerJs("$('#$this->id').yii2qrcodereader({readerId: '".$this->id."-reader',readerWidth: '".$this->readerWidth."',readerHeight: '".$this->readerHeight."',".
"successCallback: ".$this->successCallback."})");
}
}