PortfolioController.php
3.48 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace frontend\controllers;
use common\models\Portfolio;
use common\models\Specialization;
use common\models\User;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
/**
* Portfolio AJAX controller
*/
class PortfolioController extends Controller
{
public $enableCsrfValidation = false;
public function behaviors()
{
return [
];
}
/**
* @param int $user_id
* @param null|int $specialization_id
* @param int $start
*
* @return array
* @throws NotFoundHttpException
*/
public function actionPortfolio($user_id, $specialization_id = NULL, $start = 0)
{
/**
* @var Specialization $specialization
* @var User $user
*/
$request = \Yii::$app->request;
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
$user = User::findOne($user_id);
if(empty( $user )) {
throw new NotFoundHttpException('User not found');
}
if(!empty( $specialization_id )) {
$specializations[] = $specialization_id;
$specialization = Specialization::find()
->where([ 'specialization_id' => $specialization_id ])
->one();
if(!empty( $specialization )) {
$specializations = $specialization->stack;
} else {
$specializations = NULL;
}
} else {
$specializations = NULL;
}
$portfolios = $user->getPortfolios()
->asArray()
->joinWith('specializations')
->andWhere([
'not',
[ 'portfolio.lat' => NULL ],
])
->andWhere([
'not',
[ 'portfolio.lng' => NULL ],
])
->andWhere([
'>=',
'portfolio.date_add',
date('Y-m-d', $start),
])
->andFilterWhere([ 'specialization.specialization_id' => $specializations ])
->all();
return [ 'result' => $portfolios ];
}
public function actionPortfolioAll()
{
$request = \Yii::$app->request;
$response = \Yii::$app->response;
$response->format = $response::FORMAT_JSON;
$portfolios = Portfolio::find()
->asArray()
->andWhere([
'not',
[ 'portfolio.lat' => NULL ],
])
->andWhere([
'not',
[ 'portfolio.lng' => NULL ],
])
->all();
return [ 'result' => $portfolios ];
}
}