Completed
Push — master ( 32d536...4c755f )
by Peter
08:17
created

TrashItem::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 1
b 0
f 1
cc 1
eloc 2
nc 1
nop 0
crap 2
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
	public function __toString()
78
	{
79
		return 'Trashed';
80
	}
81
82
}
83