|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (c) 2019 Joas Schilling <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* @license GNU AGPL version 3 or any later version |
|
7
|
|
|
* |
|
8
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
9
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
10
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
11
|
|
|
* License, or (at your option) any later version. |
|
12
|
|
|
* |
|
13
|
|
|
* This program is distributed in the hope that it will be useful, |
|
14
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16
|
|
|
* GNU Affero General Public License for more details. |
|
17
|
|
|
* |
|
18
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
19
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
20
|
|
|
* |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
namespace OCA\AnnouncementCenter\Model; |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
use OCP\AppFramework\Db\Entity; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @method void setTime(int $time) |
|
30
|
|
|
* @method int getTime() |
|
31
|
|
|
* @method void setUser(string $user) |
|
32
|
|
|
* @method string getUser() |
|
33
|
|
|
* @method void setSubject(string $subject) |
|
34
|
|
|
* @method void setMessage(string $message) |
|
35
|
|
|
* @method string getMessage() |
|
36
|
|
|
* @method void setAllowComments(int $allowComments) |
|
37
|
|
|
* @method int getAllowComments() |
|
38
|
|
|
*/ |
|
39
|
|
|
class Announcement extends Entity { |
|
40
|
|
|
|
|
41
|
|
|
/** @var int */ |
|
42
|
|
|
protected $time; |
|
43
|
|
|
|
|
44
|
|
|
/** @var string */ |
|
45
|
|
|
protected $user; |
|
46
|
|
|
|
|
47
|
|
|
/** @var string */ |
|
48
|
|
|
protected $subject; |
|
49
|
|
|
|
|
50
|
|
|
/** @var string */ |
|
51
|
|
|
protected $message; |
|
52
|
|
|
|
|
53
|
|
|
/** @var int */ |
|
54
|
|
|
protected $allowComments; |
|
55
|
|
|
|
|
56
|
12 |
|
public function __construct() { |
|
57
|
12 |
|
$this->addType('time', 'int'); |
|
58
|
12 |
|
$this->addType('user', 'string'); |
|
59
|
12 |
|
$this->addType('subject', 'string'); |
|
60
|
12 |
|
$this->addType('message', 'string'); |
|
61
|
12 |
|
$this->addType('allowComments', 'int'); |
|
62
|
12 |
|
} |
|
63
|
|
|
|
|
64
|
3 |
|
public function getSubject(): string { |
|
65
|
3 |
|
return trim(str_replace("\n", ' ', parent::getSubject())); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
public function getParsedMessage(): string { |
|
69
|
|
|
return str_replace(['<', '>', "\n"], ['<', '>', '<br />'], parent::getMessage()); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* @param string $columnName the name of the column |
|
74
|
|
|
* @return string the property name |
|
75
|
|
|
*/ |
|
76
|
|
|
public function columnToProperty($columnName): string { |
|
77
|
|
|
// Strip off announcement_ |
|
78
|
|
|
if (strpos($columnName, 'announcement_') === 0) { |
|
79
|
|
|
$columnName = substr($columnName, strlen('announcement_')); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return parent::columnToProperty($columnName); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @param string $property the name of the property |
|
87
|
|
|
* @return string the column name |
|
88
|
|
|
*/ |
|
89
|
|
|
public function propertyToColumn($property): string { |
|
90
|
|
|
if ($property !== 'allowComments') { |
|
91
|
|
|
$property = 'announcement' . ucfirst($property); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return parent::propertyToColumn($property); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.