-
Notifications
You must be signed in to change notification settings - Fork 1
/
UnsplashImagePicker.php
75 lines (63 loc) · 2.05 KB
/
UnsplashImagePicker.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
// namespace frontend\modules\unsplash;
namespace cbtech\unsplash;
use yii\base\Widget;
use yii\helpers\Html;
use Crew\Unsplash\HttpClient;
use cbtech\unsplash\assets\AppAsset;
class UnsplashImagePicker extends Widget
{
public $message;
public $search;
public $page;
public $per_page;
public $orientation;
public $button_text;
public $button_class;
public $button_style;
public function init()
{
parent::init();
if ($this->message === null) {
$this->message = 'Hello World';
}
if($this->button_text === null){
$this->button_text = "Choose photo from Unsplash";
}
if($this->button_class === null){
$this->button_class = "btn btn-success";
}
if($this->button_style === null){
$this->button_style = "";
}
HttpClient::$utmSource = "LeP Photo Extension";
\Crew\Unsplash\HttpClient::init([
'applicationId' => \Yii::$app->modules["unsplash"]['params']['applicationId'],
'utmSource' => \Yii::$app->modules["unsplash"]['params']['utmSource'],
]);
$connection = HttpClient::$connection;
//Load AppAssets
AppAsset::register($this->view);
}
public function run()
{
// \Yii::error(print_r($this->search()));
$result = $this->search($this->search,$this->page, $this->per_page, $this->orientation);
// return Html::encode($this->message);
return $this->render('picker',[
'pageResult'=>$result,
'search'=>$this->search,
'page'=>$this->page,
'per_page'=>$this->per_page,
'orientation'=>$this->orientation,
'button_text'=>$this->button_text,
'button_class'=>$this->button_class,
'button_style'=>$this->button_style,
]);
}
public function search($search = 'colors', $page = 1, $per_page = 16, $orientation = 'landscape'){
$pageResult = \Crew\Unsplash\Search::photos($search, $page, $per_page, $orientation);
// \Yii::error(print_r($pageResult,true));
return $pageResult;
}
}