Completed
Push — master ( 971f99...10707b )
by Peter
07:20 queued 02:39
created

TrashItem::getCollectionName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL or Commercial license.
5
 *
6
 * @package maslosoft/mangan
7
 * @licence AGPL or Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]>
9
 * @copyright Copyright (c) Maslosoft
10
 * @copyright Copyright (c) Others as mentioned in code
11
 * @link http://maslosoft.com/mangan/
12
 */
13
14
namespace Maslosoft\Mangan\Model;
15
16
use Maslosoft\Mangan\Document;
17
use Maslosoft\Mangan\Interfaces\TrashInterface;
18
use Maslosoft\Mangan\Sanitizers\DateSanitizer;
19
use MongoDate;
20
21
/**
22
 * TrashItem
23
 *
24
 * @Label('Trashed item')
25
 * @author Piotr
26
 */
27
class TrashItem extends Document implements TrashInterface
28
{
29
30
	use \Maslosoft\Mangan\Traits\Model\TrashableTrait;
31
32
	/**
33
	 * Element name
34
	 * @Label('Name')
35
	 * @var string
36
	 */
37
	public $name = '';
38
39
	/**
40
	 * Type of trashed item
41
	 * @Label('Type')
42
	 * @var string
43
	 */
44
	public $type = '';
45
46
	/**
47
	 * When it was trashed.
48
	 * @Sanitizer(DateSanitizer)
49
	 * @see DateSanitizer
50
	 * @var MongoDate
51
	 */
52
	public $createDate = '';
53
54 4
	public function getCollectionName()
55
	{
56 4
		return 'Mangan.Trash';
57
	}
58
59
	/**
60
	 * Purge all items from trash. Returns number of removed items.
61
	 * @return int
62
	 */
63 3
	public function purge()
64
	{
65 3
		$removed = 0;
66
		// Remove with loop to fire before/afterDelete events
67 3
		foreach ($this->findAll() as $trash)
68
		{
69 2
			if ($trash->delete())
70
			{
71 2
				$removed++;
72
			}
73
		}
74 3
		return $removed;
75
	}
76
77
}
78