Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
CiviCRM Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Development
CiviCRM Core
Commits
6921a820
Commit
6921a820
authored
5 years ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Add EntityPageTrait
parent
de629018
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Contact/Page/View/Relationship.php
+69
-65
69 additions, 65 deletions
CRM/Contact/Page/View/Relationship.php
CRM/Core/Page/EntityPageTrait.php
+189
-0
189 additions, 0 deletions
CRM/Core/Page/EntityPageTrait.php
with
258 additions
and
65 deletions
CRM/Contact/Page/View/Relationship.php
+
69
−
65
View file @
6921a820
...
...
@@ -32,12 +32,7 @@
*/
class
CRM_Contact_Page_View_Relationship
extends
CRM_Core_Page
{
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
public
static
$_links
=
NULL
;
use
CRM_Core_Page_EntityPageTrait
;
/**
* Casid set if called from case context.
...
...
@@ -46,83 +41,112 @@ class CRM_Contact_Page_View_Relationship extends CRM_Core_Page {
*/
public
$_caseId
=
NULL
;
public
$_permission
=
NULL
;
public
$_contactId
=
NULL
;
/**
* @param int $caseId
*/
public
function
setCaseId
(
$caseId
)
{
$this
->
_caseId
=
$caseId
;
}
/**
* @return int
*/
public
function
getCaseId
()
{
return
$this
->
_caseId
;
}
/**
* Explicitly declare the entity api name.
*
* @return string
*/
public
function
getDefaultEntity
()
{
return
'Relationship'
;
}
/**
* Explicitly declare the form context.
*
* @return string|null
*/
public
function
getDefaultContext
()
{
return
'search'
;
}
/**
* View details of a relationship.
*/
public
function
view
()
{
$viewRelationship
=
CRM_Contact_BAO_Relationship
::
getRelationship
(
$this
->
_c
ontactId
,
NULL
,
NULL
,
NULL
,
$this
->
_id
);
$viewRelationship
=
CRM_Contact_BAO_Relationship
::
getRelationship
(
$this
->
getC
ontactId
()
,
NULL
,
NULL
,
NULL
,
$this
->
getEntityId
()
);
//To check whether selected contact is a contact_id_a in
//relationship type 'a_b' in relationship table, if yes then
//revert the permissionship text in template
$relationship
=
new
CRM_Contact_DAO_Relationship
();
$relationship
->
id
=
$viewRelationship
[
$this
->
_id
][
'id'
];
$relationship
->
id
=
$viewRelationship
[
$this
->
getEntityId
()
][
'id'
];
if
(
$relationship
->
find
(
TRUE
))
{
if
((
$viewRelationship
[
$this
->
_id
][
'rtype'
]
==
'a_b'
)
&&
(
$this
->
_c
ontactId
==
$relationship
->
contact_id_a
))
{
if
((
$viewRelationship
[
$this
->
getEntityId
()
][
'rtype'
]
==
'a_b'
)
&&
(
$this
->
getC
ontactId
()
==
$relationship
->
contact_id_a
))
{
$this
->
assign
(
"is_contact_id_a"
,
TRUE
);
}
}
$relType
=
$viewRelationship
[
$this
->
_id
][
'civicrm_relationship_type_id'
];
$relType
=
$viewRelationship
[
$this
->
getEntityId
()
][
'civicrm_relationship_type_id'
];
$this
->
assign
(
'viewRelationship'
,
$viewRelationship
);
$employerId
=
CRM_Core_DAO
::
getFieldValue
(
'CRM_Contact_DAO_Contact'
,
$this
->
_c
ontactId
,
'employer_id'
);
$employerId
=
CRM_Core_DAO
::
getFieldValue
(
'CRM_Contact_DAO_Contact'
,
$this
->
getC
ontactId
()
,
'employer_id'
);
$this
->
assign
(
'isCurrentEmployer'
,
FALSE
);
$relTypes
=
CRM_Utils_Array
::
index
(
array
(
'name_a_b'
),
CRM_Core_PseudoConstant
::
relationshipType
(
'name'
));
if
(
$viewRelationship
[
$this
->
_id
][
'employer_id'
]
==
$this
->
_c
ontactId
)
{
if
(
$viewRelationship
[
$this
->
getEntityId
()
][
'employer_id'
]
==
$this
->
getC
ontactId
()
)
{
$this
->
assign
(
'isCurrentEmployer'
,
TRUE
);
}
elseif
(
$relType
==
$relTypes
[
'Employee of'
][
'id'
]
&&
(
$viewRelationship
[
$this
->
_id
][
'cid'
]
==
$employerId
)
(
$viewRelationship
[
$this
->
getEntityId
()
][
'cid'
]
==
$employerId
)
)
{
// make sure we are viewing employee of relationship
$this
->
assign
(
'isCurrentEmployer'
,
TRUE
);
}
$viewNote
=
CRM_Core_BAO_Note
::
getNote
(
$this
->
_id
);
$viewNote
=
CRM_Core_BAO_Note
::
getNote
(
$this
->
getEntityId
()
);
$this
->
assign
(
'viewNote'
,
$viewNote
);
$groupTree
=
CRM_Core_BAO_CustomGroup
::
getTree
(
'Relationship'
,
NULL
,
$this
->
_id
,
0
,
$relType
);
CRM_Core_BAO_CustomGroup
::
buildCustomDataView
(
$this
,
$groupTree
,
FALSE
,
NULL
,
NULL
,
NULL
,
$this
->
_id
);
$groupTree
=
CRM_Core_BAO_CustomGroup
::
getTree
(
'Relationship'
,
NULL
,
$this
->
getEntityId
()
,
0
,
$relType
);
CRM_Core_BAO_CustomGroup
::
buildCustomDataView
(
$this
,
$groupTree
,
FALSE
,
NULL
,
NULL
,
NULL
,
$this
->
getEntityId
()
);
$rType
=
CRM_Utils_Array
::
value
(
'rtype'
,
$viewRelationship
[
$this
->
_id
]);
$rType
=
CRM_Utils_Array
::
value
(
'rtype'
,
$viewRelationship
[
$this
->
getEntityId
()
]);
// add viewed contribution to recent items list
$url
=
CRM_Utils_System
::
url
(
'civicrm/contact/view/rel'
,
"action=view&reset=1&id=
{
$viewRelationship
[
$this
->
_id
][
'id'
]
}
&cid=
{
$this
->
_c
ontactId
}
&context=home"
"action=view&reset=1&id=
{
$viewRelationship
[
$this
->
getEntityId
()
][
'id'
]
}
&cid=
{
$this
->
getC
ontactId
()
}
&context=home"
);
$session
=
CRM_Core_Session
::
singleton
();
$recentOther
=
array
();
if
((
$session
->
get
(
'userID'
)
==
$this
->
_c
ontactId
)
||
CRM_Contact_BAO_Contact_Permission
::
allow
(
$this
->
_c
ontactId
,
CRM_Core_Permission
::
EDIT
)
if
((
$session
->
get
(
'userID'
)
==
$this
->
getC
ontactId
()
)
||
CRM_Contact_BAO_Contact_Permission
::
allow
(
$this
->
getC
ontactId
()
,
CRM_Core_Permission
::
EDIT
)
)
{
$recentOther
=
array
(
'editUrl'
=>
CRM_Utils_System
::
url
(
'civicrm/contact/view/rel'
,
"action=update&reset=1&id=
{
$viewRelationship
[
$this
->
_id
][
'id'
]
}
&cid=
{
$this
->
_c
ontactId
}
&rtype=
{
$rType
}
&context=home"
"action=update&reset=1&id=
{
$viewRelationship
[
$this
->
getEntityId
()
][
'id'
]
}
&cid=
{
$this
->
getC
ontactId
()
}
&rtype=
{
$rType
}
&context=home"
),
'deleteUrl'
=>
CRM_Utils_System
::
url
(
'civicrm/contact/view/rel'
,
"action=delete&reset=1&id=
{
$viewRelationship
[
$this
->
_id
][
'id'
]
}
&cid=
{
$this
->
_c
ontactId
}
&rtype=
{
$rType
}
&context=home"
"action=delete&reset=1&id=
{
$viewRelationship
[
$this
->
getEntityId
()
][
'id'
]
}
&cid=
{
$this
->
getC
ontactId
()
}
&rtype=
{
$rType
}
&context=home"
),
);
}
$displayName
=
CRM_Contact_BAO_Contact
::
displayName
(
$this
->
_c
ontactId
);
$displayName
=
CRM_Contact_BAO_Contact
::
displayName
(
$this
->
getC
ontactId
()
);
$this
->
assign
(
'displayName'
,
$displayName
);
CRM_Utils_System
::
setTitle
(
ts
(
'View Relationship for'
)
.
' '
.
$displayName
);
$title
=
$displayName
.
' ('
.
$viewRelationship
[
$this
->
_id
][
'relation'
]
.
' '
.
CRM_Contact_BAO_Contact
::
displayName
(
$viewRelationship
[
$this
->
_id
][
'cid'
])
.
')'
;
$title
=
$displayName
.
' ('
.
$viewRelationship
[
$this
->
getEntityId
()
][
'relation'
]
.
' '
.
CRM_Contact_BAO_Contact
::
displayName
(
$viewRelationship
[
$this
->
getEntityId
()
][
'cid'
])
.
')'
;
// add the recently viewed Relationship
CRM_Utils_Recent
::
add
(
$title
,
$url
,
$viewRelationship
[
$this
->
_id
][
'id'
],
$viewRelationship
[
$this
->
getEntityId
()
][
'id'
],
'Relationship'
,
$this
->
_c
ontactId
,
$this
->
getC
ontactId
()
,
NULL
,
$recentOther
);
...
...
@@ -141,70 +165,59 @@ class CRM_Contact_Page_View_Relationship extends CRM_Core_Page {
*
*/
public
function
edit
()
{
$controller
=
new
CRM_Core_Controller_Simple
(
'CRM_Contact_Form_Relationship'
,
ts
(
'Contact Relationships'
),
$this
->
_a
ction
);
$controller
=
new
CRM_Core_Controller_Simple
(
'CRM_Contact_Form_Relationship'
,
ts
(
'Contact Relationships'
),
$this
->
getA
ction
()
);
$controller
->
setEmbedded
(
TRUE
);
// set the userContext stack
$session
=
CRM_Core_Session
::
singleton
();
// if this is called from case view, we need to redirect back to same page
if
(
$this
->
_c
aseId
)
{
$url
=
CRM_Utils_System
::
url
(
'civicrm/contact/view/case'
,
"action=view&reset=1&cid=
{
$this
->
_c
ontactId
}
&id=
{
$this
->
_c
aseId
}
"
);
if
(
$this
->
getC
aseId
()
)
{
$url
=
CRM_Utils_System
::
url
(
'civicrm/contact/view/case'
,
"action=view&reset=1&cid=
{
$this
->
getC
ontactId
()
}
&id=
{
$this
->
getC
aseId
()
}
"
);
}
else
{
$url
=
CRM_Utils_System
::
url
(
'civicrm/contact/view'
,
"action=browse&selectedChild=rel&reset=1&cid=
{
$this
->
_c
ontactId
}
"
);
$url
=
CRM_Utils_System
::
url
(
'civicrm/contact/view'
,
"action=browse&selectedChild=rel&reset=1&cid=
{
$this
->
getC
ontactId
()
}
"
);
}
$session
->
pushUserContext
(
$url
);
if
(
CRM_Utils_Request
::
retrieve
(
'confirmed'
,
'Boolean'
))
{
if
(
$this
->
_c
aseId
)
{
if
(
$this
->
getC
aseId
()
)
{
//create an activity for case role removal.CRM-4480
CRM_Case_BAO_Case
::
createCaseRoleActivity
(
$this
->
_c
aseId
,
$this
->
_id
);
CRM_Case_BAO_Case
::
createCaseRoleActivity
(
$this
->
getC
aseId
()
,
$this
->
getEntityId
()
);
CRM_Core_Session
::
setStatus
(
ts
(
'Case Role has been deleted successfully.'
),
ts
(
'Record Deleted'
),
'success'
);
}
// delete relationship
CRM_Contact_BAO_Relationship
::
del
(
$this
->
_id
);
CRM_Contact_BAO_Relationship
::
del
(
$this
->
getEntityId
()
);
CRM_Utils_System
::
redirect
(
$url
);
}
$controller
->
set
(
'contactId'
,
$this
->
_c
ontactId
);
$controller
->
set
(
'id'
,
$this
->
_id
);
$controller
->
set
(
'contactId'
,
$this
->
getC
ontactId
()
);
$controller
->
set
(
'id'
,
$this
->
getEntityId
()
);
$controller
->
process
();
$controller
->
run
();
}
public
function
preProcess
()
{
$this
->
_id
=
CRM_Utils_Request
::
retrieve
(
'id'
,
'Positive'
,
$this
);
$this
->
_contactId
=
CRM_Utils_Request
::
retrieve
(
'cid'
,
'Positive'
,
$this
,
TRUE
);
$this
->
assign
(
'contactId'
,
$this
->
_contactId
);
// check logged in url permission
CRM_Contact_Page_View
::
checkUserPermission
(
$this
);
$this
->
_action
=
CRM_Utils_Request
::
retrieve
(
'action'
,
'String'
,
$this
,
FALSE
,
'browse'
);
$this
->
assign
(
'action'
,
$this
->
_action
);
}
/**
* the main function that is called when the page loads,
* it decides the which action has to be taken for the page.
*
* @return null
* @throws \CRM_Core_Exception
*/
public
function
run
()
{
$this
->
preProcess
();
$this
->
preProcess
QuickEntityPage
();
$this
->
setContext
();
$this
->
_c
aseId
=
CRM_Utils_Request
::
retrieve
(
'caseID'
,
'Integer'
,
$this
);
$this
->
setC
aseId
(
CRM_Utils_Request
::
retrieve
(
'caseID'
,
'Integer'
,
$this
)
)
;
if
(
$this
->
_action
&
CRM_Core_Action
::
VIEW
)
{
if
(
$this
->
isViewContext
()
)
{
$this
->
view
();
}
elseif
(
$this
->
_action
&
(
CRM_Core_Action
::
UPDATE
|
CRM_Core_Action
::
ADD
|
CRM_Core_Action
::
DELETE
))
{
elseif
(
$this
->
isEditContext
()
||
$this
->
isDeleteContext
(
))
{
$this
->
edit
();
}
...
...
@@ -217,17 +230,8 @@ class CRM_Contact_Page_View_Relationship extends CRM_Core_Page {
}
public
function
setContext
()
{
$context
=
CRM_Utils_Request
::
retrieve
(
'context'
,
'Alphanumeric'
,
$this
,
FALSE
,
'search'
);
if
(
$context
==
'dashboard'
)
{
$cid
=
CRM_Utils_Request
::
retrieve
(
'cid'
,
'Integer'
,
$this
,
FALSE
);
$url
=
CRM_Utils_System
::
url
(
'civicrm/user'
,
"reset=1&id=
{
$cid
}
"
);
if
(
$this
->
getContext
()
==
'dashboard'
)
{
$url
=
CRM_Utils_System
::
url
(
'civicrm/user'
,
"reset=1&id=
{
$this
->
getContactId
()
}
"
);
}
else
{
$url
=
CRM_Utils_System
::
url
(
'civicrm/contact/view'
,
'action=browse&selectedChild=rel'
);
...
...
@@ -242,7 +246,7 @@ class CRM_Contact_Page_View_Relationship extends CRM_Core_Page {
*/
public
function
delete
()
{
// calls a function to delete relationship
CRM_Contact_BAO_Relationship
::
del
(
$this
->
_id
);
CRM_Contact_BAO_Relationship
::
del
(
$this
->
getEntityId
()
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
CRM/Core/Page/EntityPageTrait.php
0 → 100644
+
189
−
0
View file @
6921a820
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 5 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2019 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2019
*/
trait
CRM_Core_Page_EntityPageTrait
{
/**
* Pages MUST declare the following functions:
* public function getDefaultEntity() {
*/
/**
* Page MAY want to override the following functions:
* public function getDefaultContext()
*/
/**
* The id of the contact.
*
* @var int
*/
protected
$_id
;
/**
* The mode of operation for this page
*
* @var int
*/
protected
$_action
;
/**
* The context that we are working on.
*
* @var string
*/
protected
$_context
;
/**
* Contact ID of the contact on the page.
*
* @var int
*/
public
$_contactID
=
NULL
;
/**
* Contact ID of the contact on the page.
*
* @var int
* @deprecated Historically pages alternate between $_contactID and $_contactId. We'll standardise on one
*/
public
$_contactId
=
NULL
;
/**
* @var int
*/
public
$_permission
=
NULL
;
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
public
static
$_links
=
NULL
;
/**
* Get the entity id being edited.
*
* @return int|null
*/
public
function
getEntityId
()
{
return
$this
->
_id
;
}
/**
* Get the context we are working in
*
* @return string
*/
public
function
getContext
()
{
return
$this
->
_context
;
}
/**
* Get the contact ID
*
* @return int
*/
public
function
getContactId
()
{
return
$this
->
_contactID
;
}
/**
* Set the contact ID
*
* @param $contactId
*/
public
function
setContactId
(
$contactId
)
{
$this
->
_contactID
=
$contactId
;
$this
->
_contactId
=
$contactId
;
}
public
function
getAction
()
{
return
$this
->
_action
;
}
/**
* Explicitly declare the form context.
*
* @return string|null
*/
public
function
getDefaultContext
()
{
return
NULL
;
}
public
function
preProcessQuickEntityPage
()
{
$this
->
_action
=
CRM_Utils_Request
::
retrieve
(
'action'
,
'String'
,
$this
,
FALSE
,
'browse'
);
$this
->
assign
(
'action'
,
$this
->
getAction
());
$this
->
_id
=
CRM_Utils_Request
::
retrieve
(
'id'
,
'Positive'
,
$this
);
$this
->
setContactId
(
CRM_Utils_Request
::
retrieve
(
'cid'
,
'Positive'
,
$this
,
TRUE
));
$this
->
assign
(
'contactId'
,
$this
->
getContactId
());
$this
->
_context
=
CRM_Utils_Request
::
retrieve
(
'context'
,
'Alphanumeric'
,
$this
,
FALSE
,
$this
->
getDefaultContext
());
$this
->
assign
(
'context'
,
$this
->
_context
);
// check logged in url permission
CRM_Contact_Page_View
::
checkUserPermission
(
$this
);
$this
->
assign
(
'entityInClassFormat'
,
strtolower
(
str_replace
(
'_'
,
'-'
,
$this
->
getDefaultEntity
())));
}
/**
* Is the form being used in the context of a deletion.
*
* (For some reason rather than having separate forms Civi overloads one form).
*
* @return bool
*/
protected
function
isDeleteContext
()
{
return
(
$this
->
getAction
()
&
CRM_Core_Action
::
DELETE
);
}
/**
* Is the form being used in the context of a view.
*
* @return bool
*/
protected
function
isViewContext
()
{
return
(
$this
->
getAction
()
&
CRM_Core_Action
::
VIEW
);
}
/**
* Is the form being used in the context of a edit.
*
* @return bool
*/
protected
function
isEditContext
()
{
return
(
$this
->
getAction
()
&
(
CRM_Core_Action
::
UPDATE
|
CRM_Core_Action
::
ADD
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment