Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2992388
LegalpadDocumentEditor.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
5 KB
Referenced Files
None
Subscribers
None
LegalpadDocumentEditor.php
View Options
<?php
final
class
LegalpadDocumentEditor
extends
PhabricatorApplicationTransactionEditor
{
public
function
getEditorApplicationClass
(
)
{
return
PhabricatorLegalpadApplication
::
class
;
}
public
function
getEditorObjectsDescription
(
)
{
return
pht
(
'Legalpad Documents'
)
;
}
public
function
getTransactionTypes
(
)
{
$types
=
parent
::
getTransactionTypes
(
)
;
$types
[
]
=
PhabricatorTransactions
::
TYPE_COMMENT
;
$types
[
]
=
PhabricatorTransactions
::
TYPE_VIEW_POLICY
;
$types
[
]
=
PhabricatorTransactions
::
TYPE_EDIT_POLICY
;
return
$types
;
}
public
function
getCreateObjectTitle
(
$author
,
$object
)
{
return
pht
(
'%s created this document.'
,
$author
)
;
}
public
function
getCreateObjectTitleForFeed
(
$author
,
$object
)
{
return
pht
(
'%s created %s.'
,
$author
,
$object
)
;
}
protected
function
applyFinalEffects
(
PhabricatorLiskDAO
$object
,
array
$xactions
)
{
$is_contribution
=
false
;
foreach
(
$xactions
as
$xaction
)
{
switch
(
$xaction
->
getTransactionType
(
)
)
{
case
LegalpadDocumentTitleTransaction
::
TRANSACTIONTYPE
:
case
LegalpadDocumentTextTransaction
::
TRANSACTIONTYPE
:
$is_contribution
=
true
;
break
;
}
}
if
(
$is_contribution
)
{
$text
=
$object
->
getDocumentBody
(
)
->
getText
(
)
;
$title
=
$object
->
getDocumentBody
(
)
->
getTitle
(
)
;
$object
->
setVersions
(
$object
->
getVersions
(
)
+
1
)
;
$body
=
new
LegalpadDocumentBody
(
)
;
$body
->
setCreatorPHID
(
$this
->
getActingAsPHID
(
)
)
;
$body
->
setText
(
$text
)
;
$body
->
setTitle
(
$title
)
;
$body
->
setVersion
(
$object
->
getVersions
(
)
)
;
$body
->
setDocumentPHID
(
$object
->
getPHID
(
)
)
;
$body
->
save
(
)
;
$object
->
setDocumentBodyPHID
(
$body
->
getPHID
(
)
)
;
$type
=
PhabricatorContributedToObjectEdgeType
::
EDGECONST
;
id
(
new
PhabricatorEdgeEditor
(
)
)
->
addEdge
(
$this
->
getActingAsPHID
(
)
,
$type
,
$object
->
getPHID
(
)
)
->
save
(
)
;
$type
=
PhabricatorObjectHasContributorEdgeType
::
EDGECONST
;
$contributors
=
PhabricatorEdgeQuery
::
loadDestinationPHIDs
(
$object
->
getPHID
(
)
,
$type
)
;
$object
->
setRecentContributorPHIDs
(
array_slice
(
$contributors
,
0
,
3
)
)
;
$object
->
setContributorCount
(
count
(
$contributors
)
)
;
$object
->
save
(
)
;
}
return
$xactions
;
}
protected
function
validateAllTransactions
(
PhabricatorLiskDAO
$object
,
array
$xactions
)
{
$errors
=
array
(
)
;
$is_required
=
(bool)
$object
->
getRequireSignature
(
)
;
$document_type
=
$object
->
getSignatureType
(
)
;
$individual
=
LegalpadDocument
::
SIGNATURE_TYPE_INDIVIDUAL
;
foreach
(
$xactions
as
$xaction
)
{
switch
(
$xaction
->
getTransactionType
(
)
)
{
case
LegalpadDocumentRequireSignatureTransaction
::
TRANSACTIONTYPE
:
$is_required
=
(bool)
$xaction
->
getNewValue
(
)
;
break
;
case
LegalpadDocumentSignatureTypeTransaction
::
TRANSACTIONTYPE
:
$document_type
=
$xaction
->
getNewValue
(
)
;
break
;
}
}
if
(
$is_required
&&
(
$document_type
!=
$individual
)
)
{
$errors
[
]
=
new
PhabricatorApplicationTransactionValidationError
(
LegalpadDocumentRequireSignatureTransaction
::
TRANSACTIONTYPE
,
pht
(
'Invalid'
)
,
pht
(
'Only documents with signature type "individual" may '
.
'require signing to log in.'
)
,
null
)
;
}
return
$errors
;
}
/* -( Sending Mail )------------------------------------------------------- */
protected
function
shouldSendMail
(
PhabricatorLiskDAO
$object
,
array
$xactions
)
{
return
true
;
}
protected
function
buildReplyHandler
(
PhabricatorLiskDAO
$object
)
{
return
id
(
new
LegalpadReplyHandler
(
)
)
->
setMailReceiver
(
$object
)
;
}
protected
function
buildMailTemplate
(
PhabricatorLiskDAO
$object
)
{
$id
=
$object
->
getID
(
)
;
$title
=
$object
->
getDocumentBody
(
)
->
getTitle
(
)
;
return
id
(
new
PhabricatorMetaMTAMail
(
)
)
->
setSubject
(
"L{$id}: {$title}"
)
;
}
protected
function
getMailTo
(
PhabricatorLiskDAO
$object
)
{
return
array
(
$object
->
getCreatorPHID
(
)
,
$this
->
requireActor
(
)
->
getPHID
(
)
,
)
;
}
protected
function
shouldImplyCC
(
PhabricatorLiskDAO
$object
,
PhabricatorApplicationTransaction
$xaction
)
{
switch
(
$xaction
->
getTransactionType
(
)
)
{
case
LegalpadDocumentTextTransaction
::
TRANSACTIONTYPE
:
case
LegalpadDocumentTitleTransaction
::
TRANSACTIONTYPE
:
case
LegalpadDocumentPreambleTransaction
::
TRANSACTIONTYPE
:
case
LegalpadDocumentRequireSignatureTransaction
::
TRANSACTIONTYPE
:
return
true
;
}
return
parent
::
shouldImplyCC
(
$object
,
$xaction
)
;
}
protected
function
buildMailBody
(
PhabricatorLiskDAO
$object
,
array
$xactions
)
{
$body
=
parent
::
buildMailBody
(
$object
,
$xactions
)
;
$body
->
addLinkSection
(
pht
(
'DOCUMENT DETAIL'
)
,
PhabricatorEnv
::
getProductionURI
(
'/legalpad/view/'
.
$object
->
getID
(
)
.
'/'
)
)
;
return
$body
;
}
protected
function
getMailSubjectPrefix
(
)
{
return
pht
(
'[Legalpad]'
)
;
}
protected
function
shouldPublishFeedStory
(
PhabricatorLiskDAO
$object
,
array
$xactions
)
{
return
false
;
}
protected
function
supportsSearch
(
)
{
return
false
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Feb 23, 08:15 (1 d, 16 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1181232
Default Alt Text
LegalpadDocumentEditor.php (5 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment