Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/conpherence/xaction/ConpherenceThreadTitleTransaction.php
12256 views
1
<?php
2
3
final class ConpherenceThreadTitleTransaction
4
extends ConpherenceThreadTransactionType {
5
6
const TRANSACTIONTYPE = 'title';
7
8
public function generateOldValue($object) {
9
return $object->getTitle();
10
}
11
12
public function applyInternalEffects($object, $value) {
13
$object->setTitle($value);
14
}
15
16
public function getTitle() {
17
$old = $this->getOldValue();
18
$new = $this->getNewValue();
19
20
if (strlen($old) && strlen($new)) {
21
return pht(
22
'%s renamed this room from %s to %s.',
23
$this->renderAuthor(),
24
$this->renderOldValue(),
25
$this->renderNewValue());
26
} else {
27
return pht(
28
'%s created this room.',
29
$this->renderAuthor());
30
}
31
}
32
33
public function getTitleForFeed() {
34
$old = $this->getOldValue();
35
$new = $this->getNewValue();
36
37
if (strlen($old) && strlen($new)) {
38
return pht(
39
'%s renamed %s from %s to %s.',
40
$this->renderAuthor(),
41
$this->renderObject(),
42
$this->renderOldValue(),
43
$this->renderNewValue());
44
} else {
45
return pht(
46
'%s created %s.',
47
$this->renderAuthor(),
48
$this->renderObject());
49
}
50
}
51
52
53
public function validateTransactions($object, array $xactions) {
54
$errors = array();
55
56
if ($this->isEmptyTextTransaction($object->getTitle(), $xactions)) {
57
$errors[] = $this->newRequiredError(
58
pht('Rooms must have a title.'));
59
}
60
61
$max_length = $object->getColumnMaximumByteLength('title');
62
foreach ($xactions as $xaction) {
63
$new_value = $xaction->getNewValue();
64
$new_length = strlen($new_value);
65
if ($new_length > $max_length) {
66
$errors[] = $this->newInvalidError(
67
pht('The title can be no longer than %s characters.',
68
new PhutilNumber($max_length)));
69
}
70
}
71
72
return $errors;
73
}
74
75
}
76
77