1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of EC-CUBE |
4
|
|
|
* |
5
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
6
|
|
|
* |
7
|
|
|
* http://www.lockon.co.jp/ |
8
|
|
|
* |
9
|
|
|
* This program is free software; you can redistribute it and/or |
10
|
|
|
* modify it under the terms of the GNU General Public License |
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
12
|
|
|
* of the License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License |
20
|
|
|
* along with this program; if not, write to the Free Software |
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace Eccube\Repository; |
25
|
|
|
|
26
|
|
|
use Doctrine\ORM\EntityRepository; |
27
|
|
|
use Eccube\Entity\PluginEventHandler; |
28
|
|
|
use Eccube\Exception\PluginException; |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* PluginEventHandlerRepository |
33
|
|
|
* |
34
|
|
|
* This class was generated by the Doctrine ORM. Add your own custom |
35
|
|
|
* repository methods below. |
36
|
|
|
*/ |
37
|
|
|
class PluginEventHandlerRepository extends EntityRepository |
38
|
|
|
{ |
39
|
|
|
|
40
|
1189 |
|
public function getHandlers() |
41
|
|
|
{ |
42
|
1189 |
|
$qb = $this->createQueryBuilder('e') |
43
|
1189 |
|
->innerJoin('e.Plugin', 'p') |
44
|
1189 |
|
->andWhere('e.del_flg = 0 ') |
45
|
1189 |
|
->Orderby('e.event','ASC') |
46
|
1189 |
|
->addOrderby('e.priority','DESC'); |
47
|
|
|
; |
48
|
|
|
|
49
|
1189 |
|
return $qb->getQuery()->getResult(); |
50
|
|
|
} |
51
|
|
|
|
52
|
3 |
|
public function getPriorityRange($type) |
53
|
|
|
{ |
54
|
|
|
|
55
|
3 |
|
if(PluginEventHandler::EVENT_HANDLER_TYPE_FIRST==$type){ |
|
|
|
|
56
|
1 |
|
$range_start=PluginEventHandler::EVENT_PRIORITY_FIRST_START; |
57
|
1 |
|
$range_end=PluginEventHandler::EVENT_PRIORITY_FIRST_END; |
58
|
3 |
|
}elseif(PluginEventHandler::EVENT_HANDLER_TYPE_LAST==$type){ |
|
|
|
|
59
|
1 |
|
$range_start=PluginEventHandler::EVENT_PRIORITY_LAST_START; |
60
|
1 |
|
$range_end=PluginEventHandler::EVENT_PRIORITY_LAST_END; |
61
|
|
|
}else{ |
62
|
3 |
|
$range_start=PluginEventHandler::EVENT_PRIORITY_NORMAL_START; |
63
|
3 |
|
$range_end=PluginEventHandler::EVENT_PRIORITY_NORMAL_END; |
64
|
|
|
} |
65
|
3 |
|
return array($range_start,$range_end); |
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
3 |
|
public function calcNewPriority($event , $type) |
70
|
|
|
{ |
71
|
|
|
|
72
|
3 |
|
list($range_start,$range_end) = $this->getPriorityRange($type); |
73
|
|
|
|
74
|
3 |
|
$qb = $this->createQueryBuilder('e'); |
75
|
3 |
|
$qb->andWhere("e.priority >= $range_end ") |
76
|
3 |
|
->andWhere("e.priority <= $range_start ") |
77
|
3 |
|
->andWhere('e.event = :event') |
78
|
3 |
|
->setParameter('event',$event) |
79
|
3 |
|
->setMaxResults(1) |
80
|
3 |
|
->orderBy('e.priority','ASC'); |
81
|
|
|
|
82
|
3 |
|
$result=$qb->getQuery()->getResult(); |
83
|
3 |
|
if(count($result)){ |
84
|
|
|
return $result[0]->getPriority() -1; |
85
|
|
|
}else{ |
86
|
3 |
|
return $range_start; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function upPriority($pluginEventHandler,$up=true) |
92
|
|
|
{ |
93
|
|
|
|
94
|
|
|
list($range_start,$range_end) = $this->getPriorityRange($pluginEventHandler->getHandlerType()); |
95
|
|
|
|
96
|
|
|
$qb = $this->createQueryBuilder('e'); |
97
|
|
|
|
98
|
|
|
$qb->andWhere("e.priority >= $range_end ") |
99
|
|
|
->andWhere("e.priority <= $range_start ") |
100
|
|
|
->andWhere("e.del_flg = 0 ") |
101
|
|
|
->andWhere('e.priority '.($up ? '>' : '<' ).' :pri') |
102
|
|
|
->andWhere('e.event = :event') |
103
|
|
|
->setParameter('event',$pluginEventHandler->getEvent()) |
104
|
|
|
->setParameter('pri', $pluginEventHandler->getPriority() ) |
105
|
|
|
->setMaxResults(1) |
106
|
|
|
->orderBy('e.priority', ($up ? 'ASC':'DESC' ) ); |
107
|
|
|
|
108
|
|
|
$result=$qb->getQuery()->getResult(); |
109
|
|
|
|
110
|
|
|
if(count($result)){ |
111
|
|
|
$em =$this->getEntityManager(); |
112
|
|
|
$em->getConnection()->beginTransaction(); |
113
|
|
|
// 2個のentityのprioriryを入れ替える |
114
|
|
|
$tmp=$pluginEventHandler->getPriority(); |
115
|
|
|
$pluginEventHandler->setPriority($result[0]->getPriority()); |
116
|
|
|
$result[0]->setPriority($tmp); |
117
|
|
|
$em->persist($result[0]); |
118
|
|
|
$em->persist($pluginEventHandler); |
119
|
|
|
$em->flush(); |
120
|
|
|
$em->getConnection()->commit(); |
121
|
|
|
# 移動する |
122
|
|
|
}else{ |
123
|
|
|
# 移動しない |
124
|
|
|
throw new PluginException("Can't swap"); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
|
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
} |
131
|
|
|
|