Skip to content

Commit b330a4b

Browse files
committed
first commit
0 parents  commit b330a4b

13 files changed

Lines changed: 1846 additions & 0 deletions

composer.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "evolutioncms-services/document-manager",
3+
"license": "MIT",
4+
"authors": [
5+
{
6+
"name": "Alexander Pashkevich",
7+
"email": "sertious2008.wortk3@gmail.com"
8+
}
9+
],
10+
"require": {
11+
12+
},
13+
"autoload": {
14+
"psr-4": {
15+
"EvolutionCMS\\": "src"
16+
}
17+
},
18+
"extra": {
19+
"laravel": {
20+
"providers": [
21+
"EvolutionCMS\\Providers\\UserManagerServiceProvider"
22+
]
23+
24+
}
25+
}
26+
}

src/Facades/DocumentManager.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php namespace EvolutionCMS\Facades;
2+
3+
use Illuminate\Support\Facades\Facade;
4+
5+
class DocumentManager extends Facade
6+
{
7+
/**
8+
* Get the registered name of the component.
9+
*
10+
* @return string
11+
*/
12+
protected static function getFacadeAccessor()
13+
{
14+
return 'DocumentManager';
15+
}
16+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php namespace EvolutionCMS\Providers;
2+
3+
use EvolutionCMS\Services\DocumentManager;
4+
use Illuminate\Support\ServiceProvider;
5+
6+
class DocumentManagerServiceProvider extends ServiceProvider
7+
{
8+
/**
9+
* Register the service provider.
10+
*
11+
* @return void
12+
*/
13+
public function register()
14+
{
15+
$this->app->singleton('DocumentManager', function ($app) {
16+
return new DocumentManager($app);
17+
});
18+
}
19+
}

src/Services/DocumentManager.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php namespace EvolutionCMS\Services;
2+
3+
use EvolutionCMS\Models\SiteContent;
4+
use EvolutionCMS\Services\Documents\DocumentClearCart;
5+
use EvolutionCMS\Services\Documents\DocumentCreate;
6+
use EvolutionCMS\Services\Documents\DocumentDelete;
7+
use EvolutionCMS\Services\Documents\DocumentDuplicate;
8+
use EvolutionCMS\Services\Documents\DocumentEdit;
9+
use EvolutionCMS\Services\Documents\DocumentPublish;
10+
use EvolutionCMS\Services\Documents\DocumentSetGroups;
11+
use EvolutionCMS\Services\Documents\DocumentUndelete;
12+
use EvolutionCMS\Services\Documents\DocumentUnpublish;
13+
14+
class DocumentManager
15+
{
16+
17+
public function get($id)
18+
{
19+
return SiteContent::find($id);
20+
}
21+
22+
public function create(array $userData, bool $events = true, bool $cache = true)
23+
{
24+
$document = new DocumentCreate($userData, $events, $cache);
25+
return $document->process();
26+
}
27+
28+
public function edit(array $userData, bool $events = true, bool $cache = true)
29+
{
30+
$document = new DocumentEdit($userData, $events, $cache);
31+
return $document->process();
32+
}
33+
34+
public function duplicate(array $userData, bool $events = true, bool $cache = true)
35+
{
36+
$document = new DocumentDuplicate($userData, $events, $cache);
37+
return $document->process();
38+
}
39+
40+
public function delete(array $userData, bool $events = true, bool $cache = true)
41+
{
42+
$username = new DocumentDelete($userData, $events, $cache);
43+
return $username->process();
44+
}
45+
46+
public function undelete(array $userData, bool $events = true, bool $cache = true)
47+
{
48+
$username = new DocumentUndelete($userData, $events, $cache);
49+
return $username->process();
50+
}
51+
52+
public function setGroups(array $userData, bool $events = true, bool $cache = true)
53+
{
54+
$user = new DocumentSetGroups($userData, $events, $cache);
55+
return $user->process();
56+
}
57+
58+
59+
public function publish(array $userData, bool $events = true, bool $cache = true)
60+
{
61+
$user = new DocumentPublish($userData, $events, $cache);
62+
return $user->process();
63+
}
64+
65+
public function unpublished(array $userData, bool $events = true, bool $cache = true)
66+
{
67+
$user = new DocumentUnpublish($userData, $events, $cache);
68+
return $user->process();
69+
}
70+
71+
public function clearCart(array $userData = [], bool $events = true, bool $cache = true)
72+
{
73+
$user = new DocumentClearCart($userData, $events, $cache);
74+
return $user->process();
75+
}
76+
77+
}
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?php namespace EvolutionCMS\Services\Documents;
2+
3+
use EvolutionCMS\Exceptions\ServiceActionException;
4+
use EvolutionCMS\Exceptions\ServiceValidationException;
5+
use EvolutionCMS\Interfaces\ServiceInterface;
6+
use EvolutionCMS\Models\SiteContent;
7+
use EvolutionCMS\Models\SiteTmplvarTemplate;
8+
use \EvolutionCMS\Models\User;
9+
use Illuminate\Support\Facades\Lang;
10+
11+
class DocumentClearCart extends DocumentCreate
12+
{
13+
/**
14+
* @var \string[][]
15+
*/
16+
public $validate;
17+
18+
/**
19+
* @var array
20+
*/
21+
public $messages;
22+
23+
/**
24+
* @var array
25+
*/
26+
public $documentData;
27+
28+
/**
29+
* @var bool
30+
*/
31+
public $events;
32+
33+
/**
34+
* @var bool
35+
*/
36+
public $cache;
37+
38+
/**
39+
* @var array $validateErrors
40+
*/
41+
public $validateErrors;
42+
43+
/**
44+
* @var int
45+
*/
46+
public $currentDate;
47+
48+
/**
49+
* @var array
50+
*/
51+
public $tvs = [];
52+
53+
/**
54+
* UserRegistration constructor.
55+
* @param array $documentData
56+
* @param bool $events
57+
* @param bool $cache
58+
*/
59+
public function __construct(array $documentData, bool $events = true, bool $cache = true)
60+
{
61+
$this->validate = $this->getValidationRules();
62+
$this->messages = $this->getValidationMessages();
63+
$this->documentData = $documentData;
64+
$this->events = $events;
65+
$this->cache = $cache;
66+
67+
}
68+
69+
/**
70+
* @return \string[][]
71+
*/
72+
public function getValidationRules(): array
73+
{
74+
return [
75+
];
76+
}
77+
78+
/**
79+
* @return array
80+
*/
81+
public function getValidationMessages(): array
82+
{
83+
return [
84+
];
85+
86+
}
87+
88+
/**
89+
* @return \Illuminate\Database\Eloquent\Model
90+
* @throws ServiceActionException
91+
* @throws ServiceValidationException
92+
*/
93+
public function process(): \Illuminate\Database\Eloquent\Model
94+
{
95+
if (!$this->checkRules()) {
96+
throw new ServiceActionException(\Lang::get('global.error_no_privileges'));
97+
}
98+
99+
100+
if (!$this->validate()) {
101+
$exception = new ServiceValidationException();
102+
$exception->setValidationErrors($this->validateErrors);
103+
throw $exception;
104+
}
105+
106+
107+
$ids = \EvolutionCMS\Models\SiteContent::query()->withTrashed()->where('deleted', 1)->pluck('id')->toArray();
108+
if ($this->events) {
109+
// invoke OnBeforeEmptyTrash event
110+
EvolutionCMS()->invokeEvent("OnBeforeEmptyTrash",
111+
array(
112+
"ids" => $ids
113+
));
114+
}
115+
// remove the document groups link.
116+
\EvolutionCMS\Models\DocumentGroup::query()->whereIn('document', $ids)->delete();
117+
118+
// remove the TV content values.
119+
\EvolutionCMS\Models\SiteTmplvarContentvalue::query()->whereIn('contentid', $ids)->delete();
120+
121+
//'undelete' the document.
122+
\EvolutionCMS\Models\SiteContent::query()->where('deleted', 1)->forceDelete();
123+
124+
// invoke OnEmptyTrash event
125+
if ($this->events) {
126+
EvolutionCMS()->invokeEvent("OnEmptyTrash",
127+
array(
128+
"ids" => $ids
129+
));
130+
}
131+
if ($this->cache) {
132+
EvolutionCMS()->clearCache('full');
133+
}
134+
return SiteContent::query()->first();
135+
}
136+
137+
/**
138+
* @return bool
139+
*/
140+
public function checkRules(): bool
141+
{
142+
return EvolutionCMS()->hasPermission('delete_document');
143+
}
144+
145+
/**
146+
* @return bool
147+
*/
148+
public function validate(): bool
149+
{
150+
return true;
151+
}
152+
153+
154+
}

0 commit comments

Comments
 (0)