|
1
|
|
|
<?php |
|
2
|
|
|
class ShopController extends GameController |
|
3
|
|
|
{ |
|
4
|
|
|
public function actionIndex($page = 0) |
|
5
|
|
|
{ |
|
6
|
|
|
$this->room(Shop::TYPE_ITEM, $page, 'buy'); |
|
7
|
|
|
} |
|
8
|
|
|
|
|
9
|
|
|
public function actionBuyBaits($page = 0) |
|
10
|
|
|
{ |
|
11
|
|
|
$this->room(Shop::TYPE_BAIT, $page, 'buy'); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
public function actionSellItems($page = 0) |
|
15
|
|
|
{ |
|
16
|
|
|
$this->room(Shop::TYPE_ITEM, $page, 'sell'); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function actionSellBaits($page = 0) |
|
20
|
|
|
{ |
|
21
|
|
|
$this->room(Shop::TYPE_BAIT, $page, 'sell'); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function actionMakeSets() |
|
25
|
|
|
{ |
|
26
|
|
|
$item_id = Yii::app()->request->getPost('item_id', 0); |
|
27
|
|
|
|
|
28
|
|
|
$shop = new Shop; |
|
|
|
|
|
|
29
|
|
|
$shop->item_type = Shop::TYPE_PART; |
|
|
|
|
|
|
30
|
|
|
$shop->fetchSets(); |
|
31
|
|
|
|
|
32
|
|
|
try { |
|
33
|
|
|
if ($item_id) { |
|
34
|
|
|
$shop->constructItem($item_id); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
if ($shop->success['setSold']) { |
|
|
|
|
|
|
38
|
|
|
Yii::app()->user->setFlash('success', 'A felszerelés elkészült!'); |
|
39
|
|
|
} |
|
40
|
|
|
} catch (CFlashException $e) { |
|
41
|
|
|
Yii::app()->user->setFlash('error', $e->getMessage()); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
$this->render('makesets', [ |
|
45
|
|
|
'list' => $shop->items, |
|
|
|
|
|
|
46
|
|
|
]); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param integer $page |
|
51
|
|
|
* @param string $transaction |
|
52
|
|
|
*/ |
|
53
|
|
|
private function room($type, $page, $transaction) |
|
54
|
|
|
{ |
|
55
|
|
|
$item_id = Yii::app()->request->getPost('item_id', 0); |
|
56
|
|
|
$amount = Yii::app()->request->getPost('amount', 0); |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
$shop = new Shop; |
|
|
|
|
|
|
59
|
|
|
$shop->item_type = $type; |
|
|
|
|
|
|
60
|
|
|
$shop->page = $page; |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
if ($transaction == 'buy') { |
|
63
|
|
|
$shop->fetchItems(); |
|
64
|
|
|
//buy selected item |
|
65
|
|
|
$shop->buyItem($item_id, $amount); |
|
66
|
|
|
} elseif ($transaction == 'sell') { |
|
67
|
|
|
$shop->fetchPlayersItems(); |
|
68
|
|
|
//sell selected item |
|
69
|
|
|
$shop->sellItem($item_id, $amount); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
$this->render($transaction.$type.'s', [ |
|
73
|
|
|
'list' => $shop->items, |
|
|
|
|
|
|
74
|
|
|
'pagination' => $shop->pagination, |
|
|
|
|
|
|
75
|
|
|
'count' => $shop->count, |
|
|
|
|
|
|
76
|
|
|
'page_size' => Yii::app()->params['shopItemsPerPage'], |
|
77
|
|
|
'owned_baits' => $shop->owned_baits, |
|
78
|
|
|
'owned_items' => $shop->owned_items, |
|
79
|
|
|
'nextItemsLevel' => $shop->nextItemsLevel, |
|
80
|
|
|
'page'=>$page, |
|
81
|
|
|
'transactionId'=>$shop->transactionId, |
|
|
|
|
|
|
82
|
|
|
]); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
|
|
|
|
|
85
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.