Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set weight on Note Form #27106

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions CRM/Contact/Page/View/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public function view() {
/**
* called when action is browse.
*/
public function browse() {
public function browse(): void {
$note = new CRM_Core_DAO_Note();
$note->entity_table = 'civicrm_contact';
$note->entity_id = $this->_contactId;
$note->entity_id = $this->getContactID();

$note->orderBy('modified_date desc');

Expand All @@ -80,7 +80,7 @@ public function browse() {
$action,
[
'id' => $note->id,
'cid' => $this->_contactId,
'cid' => $this->getContactID(),
],
ts('more'),
FALSE,
Expand Down Expand Up @@ -123,7 +123,7 @@ public function browse() {
);
$this->assign('commentAction', $commentAction);

$this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('note', $this->_contactId);
$this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent('note', $this->getContactID());
}

/**
Expand All @@ -135,8 +135,9 @@ public function edit() {

// set the userContext stack
$session = CRM_Core_Session::singleton();
$contactID = $this->getContactID();
$url = CRM_Utils_System::url('civicrm/contact/view',
'action=browse&selectedChild=note&cid=' . $this->_contactId
'action=browse&selectedChild=note&cid=' . $contactID
);
$session->pushUserContext($url);

Expand Down Expand Up @@ -250,6 +251,7 @@ public static function links() {
'url' => 'civicrm/contact/view/note',
'qs' => 'action=add&reset=1&cid=%%cid%%&parentId=%%id%%&selectedChild=note',
'title' => ts('Add Comment'),
'weight' => -5,
],
CRM_Core_Action::DELETE => [
'name' => ts('Delete'),
Expand All @@ -266,7 +268,7 @@ public static function links() {
*
* @return array[]
*/
public static function commentLinks() {
public static function commentLinks(): array {
return [
CRM_Core_Action::VIEW => [
'name' => ts('View'),
Expand All @@ -292,4 +294,18 @@ public static function commentLinks() {
];
}

/**
* Get the relevant contact ID.
*
* @api supported to be accessed from outside of core.
*
* @return int
*
* @noinspection PhpUnhandledExceptionInspection
* @noinspection PhpDocMissingThrowsInspection
*/
public function getContactID(): int {
return (int) CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
}

}
20 changes: 10 additions & 10 deletions tests/phpunit/CRM/Contact/Page/View/NoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@
*/
class CRM_Contact_Page_View_NoteTest extends CiviUnitTestCase {

public function testNoContactIdNote() {
$contactId = $this->individualCreate();
public function testNoContactIDNote(): void {
$contactID = $this->individualCreate();
foreach ([1, 2, 3, 4, 5] as $noteID) {
$note = new CRM_Core_DAO_Note();
$note->entity_id = $contactId;
$note->entity_id = $contactID;
$note->subject = 'Test Note ' . $noteID;
$note->note = 'Test Note from Tests';
$note->entity_table = 'civicrm_contact';
if ($noteID == 5) {
$note->contact_id = $contactId;
if ($noteID === 5) {
$note->contact_id = $contactID;
}
$note->save();
}
$_REQUEST['cid'] = $contactID;
$page = new CRM_Contact_Page_View_Note();
$page->_contactId = $contactId;
$page->_permission = CRM_Core_Permission::EDIT;
$page->browse();
$this->assertEquals(count($page->values), 5);
$this->assertCount(5, $page->values);
foreach ($page->values as $note) {
$this->assertEquals($note['entity_id'], $contactId);
if ($note['id'] == 5) {
$this->assertEquals($note['createdBy'], 'Mr. Anthony Anderson II');
$this->assertEquals($note['entity_id'], $contactID);
if ((int) $note['id'] === 5) {
$this->assertEquals('Mr. Anthony Anderson II', $note['createdBy']);
}
}
}
Expand Down