-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplugin.php
More file actions
901 lines (772 loc) · 33.7 KB
/
plugin.php
File metadata and controls
901 lines (772 loc) · 33.7 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
<?php
/**
* Plugin.php
*
* PHP version 7
*
* @category Point
* @package Xpressengine\Plugins\Point
* @author XE Team (developers) <developers@xpressengine.com>
* @copyright 2019 Copyright XEHub Corp. <https://www.xehub.io>
* @license http://www.gnu.org/licenses/lgpl-3.0-standalone.html LGPL
* @link https://xpressengine.io
*/
namespace Xpressengine\Plugins\Point;
use Carbon\Carbon;
use Illuminate\Database\Schema\Blueprint;
use Route;
use Schema;
use Xpressengine\Config\ConfigEntity;
use Xpressengine\Menu\Models\MenuItem;
use Xpressengine\Permission\Instance as PermissionInstance;
use Xpressengine\Plugin\AbstractPlugin;
use Xpressengine\Plugins\Board\BoardPermissionHandler;
use Xpressengine\Plugins\Board\Models\Board;
use Xpressengine\Plugins\Board\Modules\BoardModule;
use Xpressengine\Plugins\Comment\Models\Comment;
use Xpressengine\Plugins\Point\Models\Point;
use Xpressengine\Presenter\Html\HtmlPresenter;
use Xpressengine\User\UserInterface;
use XeToggleMenu;
/**
* Class Plugin
*
* @category Point
* @package Xpressengine\Plugins\Point\Controllers
* @author XE Team (developers) <developers@xpressengine.com>
* @copyright 2019 Copyright XEHub Corp. <https://www.xehub.io>
* @license http://www.gnu.org/licenses/lgpl-3.0-standalone.html LGPL
* @link https://xpressengine.io
*/
class Plugin extends AbstractPlugin
{
public function register()
{
app()->singleton(Handler::class, function ($app) {
$proxyClass = app('xe.interception')->proxy(Handler::class, 'Point');
return new $proxyClass($this, app('xe.config'));
});
app()->alias(Handler::class, 'point::handler'); // deprecated
app()->alias(Handler::class, 'xe.point.handler');
$key = static::getId();
$config = app('config')->get($key, []);
app('config')->set($key, array_merge(require __DIR__.'/config/config.php', $config));
}
/**
* 이 메소드는 활성화(activate) 된 플러그인이 부트될 때 항상 실행됩니다.
*
* @return void
*/
public function boot()
{
if ( app('xe.point.handler')->isUse() ) {
$this->registerEvent();
}
$this->registerUserMacro();
$this->registerDocumentMacro();
$this->route();
intercept(
sprintf('%s@render', HtmlPresenter::class),
$this->getId() . '::html_presenter_render',
function ($func) {
if (request()->session()->has('received_point'))
{
$receivedPoint = request()->session()->get('received_point') ['point'];
$jsonPath = self::asset('assets/jsons/reward-recieved.json');
$renderHtml = view('point::views.action', compact('jsonPath', 'receivedPoint'))->render();
\XeFrontend::html('received_point')->content($renderHtml)->appendTo('body')->load();
}
return $func();
}
);
}
/**
* 플러그인의 설정페이지 주소를 반환한다.
* 플러그인 목록에서 플러그인의 '관리' 버튼을 누를 경우 이 페이지에서 반환하는 주소로 연결된다.
*
* @return string
*/
public function getSettingsURI()
{
return route('point::setting.index');
}
protected function registerUserMacro()
{
\Xpressengine\User\Models\User::macro('point', function() {
return $this->belongsTo( Point::class, 'id', 'user_id');
});
\Xpressengine\User\Models\User::macro('point_level', function() {
$level = 0;
if ($this->point != null) {
$level = $this->point->level;
}
return $level;
});
\Xpressengine\User\Models\User::macro('point_level_icon', function() {
$handler = app('xe.point.handler');
return $handler->getIcon($this->point_level);
});
if(app('config')->get('point')['specific_group']) {
\Xpressengine\User\Models\User::macro('specific', function (){
if($this->groups->pluck('id')->contains(app('xe.config')->get('point')->get('specific_group_id'))) {
return true;
}
return false;
});
}
}
protected function registerDocumentMacro()
{
// for document
\Xpressengine\Document\Models\Document::macro('point', function() {
return $this->belongsTo( Point::class, 'id', 'user_id');
});
\Xpressengine\Document\Models\Document::macro('point_level', function() {
$level = 0;
if ($this->point != null) {
$level = $this->point->level;
}
return $level;
});
\Xpressengine\Document\Models\Document::macro('point_level_icon', function() {
$handler = app('xe.point.handler');
return $handler->getIcon($this->point_level);
});
// for board
\Xpressengine\Plugins\Board\Models\Board::macro('point', function() {
return $this->belongsTo( Point::class, 'id', 'user_id');
});
\Xpressengine\Plugins\Board\Models\Board::macro('point_level', function() {
$level = 0;
if ($this->point != null) {
$level = $this->point->level;
}
return $level;
});
\Xpressengine\Plugins\Board\Models\Board::macro('point_level_icon', function() {
$handler = app('xe.point.handler');
return $handler->getIcon($this->point_level);
});
// for comment
\Xpressengine\Plugins\Comment\Models\Comment::macro('point', function() {
return $this->belongsTo( Point::class, 'id', 'user_id');
});
\Xpressengine\Plugins\Comment\Models\Comment::macro('point_level', function() {
$level = 0;
if ($this->point != null) {
$level = $this->point->level;
}
return $level;
});
\Xpressengine\Plugins\Comment\Models\Comment::macro('point_level_icon', function() {
$handler = app('xe.point.handler');
return $handler->getIcon($this->point_level);
});
}
protected function registerEvent()
{
// user
EventListeners\UserActions::listenRegister();
EventListeners\UserActions::listenLogin();
// board - write document
intercept(
'\Xpressengine\Plugins\Board\Handler@add',
'point.board-write-document',
function ($func, array $args, UserInterface $user, ConfigEntity $config) {
\XeDB::beginTransaction();
/** @var Board $board */
$board = $func($args, $user, $config);
$pointHandler = app('point::handler');
$instanceId = $args['instance_id'];
$user = \Auth::user();
if(app('config')->get('point')['specific_group']) {
if ($user->specific !== true) {
\XeDB::commit();
return $board;
}
}
$action = 'board.write-document.'.$instanceId;
if ($pointHandler->checkAction($action, $user) == false) {
$exception = new \Xpressengine\Support\Exceptions\HttpXpressengineException(
[], 500
);
$exception->setMessage('[포인트 부족] 글을 등록할 수 없습니다.');
throw $exception;
}
$pointHandler->executeAction(
$action,
$user,
['instance_id' => $args['instance_id'], 'type' => 'create']
);
// check file count, upload file point
$fileCount = 0;
if (isset($args['_files'])) {
$fileCount = count($args['_files']);
}
if ($fileCount > 0) {
$action = 'board.upload-file.'.$instanceId;
if ($pointHandler->checkAction($action, $user) == false) {
$exception = new \Xpressengine\Support\Exceptions\HttpXpressengineException(
[], 500
);
$exception->setMessage('[포인트 부족] 업로드할 수 없습니다.');
throw $exception;
}
$pointHandler->executeAction(
$action,
$user,
['instance_id' => $args['instance_id'], 'file_count' => $fileCount]
);
}
\XeDB::commit();
return $board;
}
);
// board - restore document, @deprecated
intercept(
'\Xpressengine\Plugins\Board\Handler@restore',
'point.board-restore-document',
function ($func, Board $board, ConfigEntity $config) {
\XeDB::beginTransaction();
/** @var Board $boardDoc */
$func($board, $config);
if(app('config')->get('point')['specific_group']) {
$user = app('xe.user')->find($board->getUserId());
if ($user->specific !== true) {
\XeDB::commit();
return;
}
}
app('point::handler')->executeAction(
'board.write-document.'.$board->getInstanceId(),
$board->getUserId(),
['document_id' => $board->id, 'type' => 'restore']
);
\XeDB::commit();
}
);
// board - delete document
intercept(
['\Xpressengine\Plugins\Board\Handler@remove', '\Xpressengine\Plugins\Board\Handler@trash'],
'point.board-delete-document',
function ($func, Board $board, ConfigEntity $config) {
\XeDB::beginTransaction();
$pointHandler = app('point::handler');
// 작성된 글의 타입이 `module/board@board` 가 아닌 경우.
$isNotBoardType = $board->type !== 'module/board@board';
// 게시글글이 작성된 게시판의 manage 권한을 가지고 있는 경우.
$boardPermission = app('xe.board.permission');
$boardPermissionInstance = new PermissionInstance($boardPermission->name($board->instance_id));
$hasManagingPermission = \Gate::allows(BoardPermissionHandler::ACTION_MANAGE, $boardPermissionInstance);
if($isNotBoardType || $hasManagingPermission) {
$func($board, $config);
\XeDB::commit();
return;
}
$instanceId = $board->instance_id;
$user = \Auth::user();
if(app('config')->get('point')['specific_group']) {
if ($user->specific !== true) {
$func($board, $config);
\XeDB::commit();
return;
}
}
$action = 'board.delete-document.'.$instanceId;
if ($pointHandler->checkAction($action, $user) == false) {
$exception = new \Xpressengine\Support\Exceptions\HttpXpressengineException(
[], 500
);
$exception->setMessage('[포인트 부족] 글을 삭제할 수 없습니다.');
throw $exception;
}
$pointHandler->executeAction(
$action,
$user,
['document_id' => $board->id, 'type' => 'remove']
);
$func($board, $config);
\XeDB::commit();
}
);
// board - read document
intercept(
'\Xpressengine\Plugins\Board\Handler@incrementReadCount',
'point.read-document',
function ($func, Board $board, UserInterface $user) {
\XeDB::beginTransaction();
$currentReadCount = $board->read_count;
$func($board, $user);
// 공지사항을 열람하는 경우.
$isNotice = $board->getAttribute('status') === Board::STATUS_NOTICE;
// 조회수 변경되지 않음, 이미 읽은 글
$isAlreadyRead = $currentReadCount == $board->read_count;
// 자신이 작성한 글을 열람하는 경우.
$isOwner = $board->getUserId() === $user->getId();
// 작성된 글의 타입이 `module/board@board` 가 아닌 경우.
$isNotBoardType = $board->type !== 'module/board@board';
if ($isNotice || $isAlreadyRead || $isOwner || $isNotBoardType) {
\XeDB::commit();
return;
}
$pointHandler = app('point::handler');
$instanceId = $board->instance_id;
// check url
$route = \Route::getCurrentRoute();
$parts = [];
if ($route != null) {
$parts = explode('@', $route->getActionName());
$parts = explode('\\', array_shift($parts));
}
if (array_pop($parts) == 'BoardModuleController') {
$user = \Auth::user();
if(app('config')->get('point')['specific_group']) {
if ($user->specific !== true) {
\XeDB::commit();
return;
}
}
$action = 'board.read-document.'.$instanceId;
if ($pointHandler->checkAction($action, $user) == false) {
$exception = new \Xpressengine\Support\Exceptions\HttpXpressengineException(
[], 500
);
$exception->setMessage('[포인트 부족] 글을 조회할 수 없습니다.');
throw $exception;
}
$pointHandler->executeAction(
$action,
$user,
['document_id' => $board->id, 'type' => 'read']
);
}
\XeDB::commit();
}
);
// board - vote 추천, 비추천
intercept(
'\Xpressengine\Plugins\Board\Handler@incrementVoteCount',
'point.vote-increment-document',
function ($func, Board $board, UserInterface $user, $option, $point) {
\XeDB::beginTransaction();
$func($board, $user, $option, $point);
if(app('config')->get('point')['specific_group']) {
$user = app('xe.user')->find($board->user_id);
if ($user->specific !== true) {
\XeDB::commit();
return;
}
}
$pointHandler = app('point::handler');
if($board->type != 'module/board@board') {
\XeDB::commit();
return;
}
$instanceId = $board->instance_id;
// check url
$route = \Route::getCurrentRoute();
$parts = [];
if ($route != null) {
$parts = explode('@', $route->getActionName());
$parts = explode('\\', array_shift($parts));
}
if (array_pop($parts) == 'BoardModuleController') {
if ($option == 'assent') {
$action = 'board.receive-assent-document.'.$instanceId;
} elseif ($option == 'dissent') {
$action = 'board.receive-dissent-document.'.$instanceId;
}
$pointHandler->executeAction(
$action,
$board->user_id,
['document_id' => $board->id]
);
}
\XeDB::commit();
}
);
// comment - write comment
intercept(
['Xpressengine\Plugins\Comment\Handler@create', 'Xpressengine\Plugins\Comment\Handler@restore'],
'point.write-comment',
function ($target, $inputs, $user = null) {
\XeDB::beginTransaction();
/** @var Comment $comment */
$comment = $target($inputs, $user);
$boardDoc = Board::find($inputs['target_id']);
$pointHandler = app('point::handler');
if ($boardDoc == null) {
\XeDB::commit();
return $comment;
} elseif($boardDoc->type != 'module/board@board') {
\XeDB::commit();
return $comment;
}
$instanceId = $boardDoc->instance_id;
$user = \Auth::user();
if(app('config')->get('point')['specific_group']) {
if ($user->specific !== true) {
\XeDB::commit();
return $comment;
}
}
if(app('config')->get('point')['comment_limit_hour']) {
$diffHours = $boardDoc->created_at->diffInHours(Carbon::now());
$commentTimeLimitConfig = $pointHandler->getCommentLimitHourConfig();
if ($diffHours > $commentTimeLimitConfig) {
\XeDB::commit();
return $comment;
}
}
if(app('config')->get('point')['comment_limit_count']) {
$commentLimitCountConfig = $pointHandler->getCommentLimitCountConfig();
$docToComments = $boardDoc->comments->filter(function ($comment) use ($user){
return $comment->user_id === $user->getId();
});
$docToCommentCount = $docToComments->count();
if ($docToCommentCount > $commentLimitCountConfig) {
\XeDB::commit();
return $comment;
}
}
$action = 'board.write-comment.'.$instanceId;
if ($pointHandler->checkAction($action, $user) == false) {
$exception = new \Xpressengine\Support\Exceptions\HttpXpressengineException(
[], 500
);
$exception->setMessage('[포인트 부족] 댓글을 등록할 수 없습니다.');
throw $exception;
}
$pointHandler->executeAction(
$action,
$user,
['document_id' => $boardDoc->id, 'comment_id' => $comment->id, 'type' => 'create']
);
\XeDB::commit();
return $comment;
}
);
// comment - trash comment, 코멘트에서 trash 하고 delete 함.. 중복 처리하기 때문에 remove 는 처리 안함
intercept(
'Xpressengine\Plugins\Comment\Handler@trash',
'point.trash-comment',
function ($func, Comment $comment) {
\XeDB::beginTransaction();
$targetId = $comment->target->target_id;
$result = $func($comment);
$board = Board::find($targetId);
$pointHandler = app('point::handler');
if ($board != null && $board->type == 'module/board@board') {
$instanceId = $board->instance_id;
$user = \Auth::user();
if(app('config')->get('point')['specific_group']) {
if ($user->specific !== true) {
\XeDB::commit();
return $result;
}
}
$action = 'board.delete-comment.'.$instanceId;
if ($pointHandler->checkAction($action, $user) == false) {
$exception = new \Xpressengine\Support\Exceptions\HttpXpressengineException(
[], 500
);
$exception->setMessage('[포인트 부족] 댓글을 삭제할 수 없습니다.');
throw $exception;
}
$pointHandler->executeAction(
$action,
$user,
['document_id' => $board->id, 'comment_id' => $comment->id]
);
}
\XeDB::commit();
return $result;
}
);
// board - upload file when upload from editor @deprecated
intercept(
['Xpressengine\Storage\Storage@upload'],
'point.board-upload-file-editor',
function ($func, $uploadedFile, $path) {
\XeDB::beginTransaction();
$result = $func($uploadedFile, $path);
// start point
$pointHandler = app('point::handler');
// get instance id
$instanceId = request()->segment(3);
$menuItem = MenuItem::where('id', $instanceId)->first();
if ($menuItem != null && $menuItem->type == 'board@board') {
$user = \Auth::user();
if(app('config')->get('point')['specific_group']) {
if ($user->specific !== true) {
\XeDB::commit();
return $result;
}
}
$action = 'board.upload-file.'.$instanceId;
if ($pointHandler->checkAction($action, $user) == false) {
$exception = new \Xpressengine\Support\Exceptions\HttpXpressengineException(
[], 500
);
$exception->setMessage('[포인트 부족] 업로드 할 수 없습니다.');
throw $exception;
}
$pointHandler->executeAction(
$action,
$user,
['instance_id' => $instanceId]
);
}
\XeDB::commit();
return $result;
}
);
// board - download file
intercept(
['Xpressengine\Storage\Storage@download'],
'point.board-download-file',
function ($func, $file) {
\XeDB::beginTransaction();
$result = $func($file);
// start point
$pointHandler = app('point::handler');
// get instance id
$instanceId = request()->segment(3);
$menuItem = MenuItem::where('id', $instanceId)->first();
$isImage = false;
if ($file != null && explode('/', $file->mime)[0] == 'image') {
$isImage = true;
}
// 이미지는 제외
if ($menuItem != null && $menuItem->type == 'board@board' && $isImage == false) {
$user = \Auth::user();
if(app('config')->get('point')['specific_group']) {
if ($user->specific !== true) {
\XeDB::commit();
return $result;
}
}
$action = 'board.download-file.'.$instanceId;
if ($pointHandler->checkAction($action, $user) == false) {
$exception = new \Xpressengine\Support\Exceptions\HttpXpressengineException(
[], 500
);
$exception->setMessage('[포인트 부족] 다운로드 할 수 없습니다.');
throw $exception;
}
$pointHandler->executeAction(
$action,
$user,
['instance_id' => $instanceId, 'file_id' => $file->id, 'mime' => $file->mime,]
);
}
\XeDB::commit();
return $result;
}
);
}
protected function route()
{
// settings menu 등록
$menus = [
'user.point' => [
'title' => 'point::point',
'display' => true,
'description' => '',
'ordering' => 1000
],
'user.point.log' => [
'title' => 'point::pointEarnUseLog',
'display' => true,
'description' => '',
'ordering' => 10001
],
'user.point.config' => [
'title' => 'point::pointSetup',
'display' => true,
'description' => '',
'ordering' => 10003
],
];
foreach ($menus as $id => $menu) {
app('xe.register')->push('settings/menu', $id, $menu);
}
Route::settings(
$this->getId(),
function () {
Route::group(
['namespace' => 'Xpressengine\Plugins\Point\Controllers'],
function () {
Route::get(
'/',
[
'as' => 'point::setting.index',
'uses' => 'SettingController@index',
'settings_menu' => 'user.point.config',
]
);
Route::get('/instance', ['as' => 'point::setting.instance', 'uses' => 'SettingController@instance',]);
Route::get('/user', ['as' => 'point::setting.user', 'uses' => 'SettingController@user',]);
Route::post('/user/point/update', ['as' => 'point::setting.user.point.update', 'uses' => 'SettingController@updateUserPoint',]);
Route::get(
'/logs',
[
'as' => 'point::setting.logs',
'uses' => 'SettingController@logs',
'settings_menu' => 'user.point.log',
]
);
Route::put('/config/update', ['as' => 'point::config.update', 'uses' => 'SettingController@updateConfig',]);
Route::put('/section/update', ['as' => 'point::section.update', 'uses' => 'SettingController@updateSection',]);
Route::put('/group/update', ['as' => 'point::group.update', 'uses' => 'SettingController@updateGroup',]);
Route::put('/level_point/update', ['as' => 'point::level_point.update', 'uses' => 'SettingController@updateLevelPoint',]);
Route::post('/user_point/update', ['as' => 'point::user_point.update', 'uses' => 'SettingController@updateUserPoint',]);
Route::get('/{userId}', ['as' => 'point::setting.show', 'uses' => 'SettingController@show',]);
}
);
}
);
}
/**
* 플러그인이 활성화될 때 실행할 코드를 여기에 작성한다.
*
* @param string|null $installedVersion 현재 XpressEngine에 설치된 플러그인의 버전정보
*
* @return void
*/
public function activate($installedVersion = null)
{
app('xe.config')->set('point', []);
// user
app('point::handler')->storeActionInfo('user_login', ['point'=> 0, 'title'=>'xe::login']);
app('point::handler')->storeActionInfo('user_register', ['point'=> 0, 'title'=>'xe::signUp']);
// board
app('point::handler')->storeActionInfo('board', ['point'=> 0, 'title'=>'board::board']);
app('point::handler')->storeActionInfo('board.write-document', ['title'=>'point::articleStore']);
app('point::handler')->storeActionInfo('board.delete-document', ['title'=>'point::articleDestroy']);
app('point::handler')->storeActionInfo('board.write-comment', ['title'=>'point::commentStore']);
app('point::handler')->storeActionInfo('board.delete-comment', ['title'=>'point::commentDestroy']);
// version 1.0.2
app('xe.config')->set('point.group', []);
app('xe.config')->set('point.level_point', []);
app('point::handler')->storeActionInfo('board.upload-file', ['title'=>'point::uploadFile']);
app('point::handler')->storeActionInfo('board.download-file', ['title'=>'point::downloadFile']);
app('point::handler')->storeActionInfo('board.read-document', ['title'=>'point::readDocument']);
app('point::handler')->storeActionInfo('board.receive-assent-document', ['title'=>'point::receiveAssentDocument']);
app('point::handler')->storeActionInfo('board.receive-dissent-document', ['title'=>'point::receiveDissentDocument']);
}
/**
* 플러그인을 설치한다. 플러그인이 설치될 때 실행할 코드를 여기에 작성한다
*
* @return void
*/
public function install()
{
if (!Schema::hasTable('point')) {
Schema::create(
'point',
function (Blueprint $table) {
$table->engine = "InnoDB";
$table->string('user_id', 36);
$table->bigInteger('point');
$table->bigInteger('level')->default(0);
$table->timestamp('created_at')->index();
$table->timestamp('updated_at')->index();
$table->primary('user_id');
}
);
}
if (!Schema::hasTable('point_log')) {
Schema::create(
'point_log',
function (Blueprint $table) {
$table->engine = "InnoDB";
$table->increments('id');
$table->string('user_id', 36);
$table->string('action', 200);
$table->bigInteger('point');
$table->string('content');
$table->timestamp('created_at')->index();
$table->timestamp('updated_at');
$table->index('user_id');
}
);
}
$toggleMenuType = 'user';
$activates = XeToggleMenu::getActivated($toggleMenuType);
if (array_key_exists(UserMenus\PointItem::getId(), $activates) == false) {
$activates[UserMenus\PointItem::getId()] = UserMenus\PointItem::class;
}
/** @var \Xpressengine\Translation\Translator $trans */
$trans = app('xe.translator');
$trans->putFromLangDataSource('point', base_path('plugins/point/langs/lang.php'));
}
/**
* 해당 플러그인이 설치된 상태라면 true, 설치되어있지 않다면 false를 반환한다.
* 이 메소드를 구현하지 않았다면 기본적으로 설치된 상태(true)를 반환한다.
*
* @return boolean 플러그인의 설치 유무
*/
public function checkInstalled()
{
if (!Schema::hasTable('point')) {
return false;
}
if (!Schema::hasTable('point_log')) {
return false;
}
return true;
}
/**
* 플러그인을 업데이트한다.
*
* @return void
*/
public function update()
{
// implement code
if ($this->hasLevelFunction() == false) {
$this->updateLevelFunction();
}
}
/**
* 해당 플러그인이 최신 상태로 업데이트가 된 상태라면 true, 업데이트가 필요한 상태라면 false를 반환함.
* 이 메소드를 구현하지 않았다면 기본적으로 최신업데이트 상태임(true)을 반환함.
*
* @return boolean 플러그인의 설치 유무,
*/
public function checkUpdated()
{
if ($this->hasLevelFunction() == false) {
return false;
}
return parent::checkUpdated();
}
/**
* 1.0.2 에서 레벨 기능 추가
*
* @return bool
*/
protected function hasLevelFunction()
{
if (!Schema::hasColumn('point', 'level')) {
return false;
}
return true;
}
protected function updateLevelFunction()
{
if (!Schema::hasColumn('point', 'level')) {
Schema::table('point', function (Blueprint $table) {
$table->bigInteger('level')->default(0);
});
}
app('xe.config')->set('point.group', []);
app('xe.config')->set('point.level_point', []);
app('point::handler')->storeActionInfo('board.upload-file', ['point'=> 0, 'title'=>'point::uploadFile']);
app('point::handler')->storeActionInfo('board.download-file', ['point'=> 0, 'title'=>'point::downloadFile']);
app('point::handler')->storeActionInfo('board.read-document', ['point'=> 0, 'title'=>'point::readDocument']);
app('point::handler')->storeActionInfo('board.receive-assent-document', ['point'=> 0, 'title'=>'point::receiveAssentDocument']);
app('point::handler')->storeActionInfo('board.receive-dissent-document', ['point'=> 0, 'title'=>'point::receiveDissentDocument']);
}
}