diff --git a/CRM/Core/BAO/Note.php b/CRM/Core/BAO/Note.php index c93215d23520..b6e7923fa091 100644 --- a/CRM/Core/BAO/Note.php +++ b/CRM/Core/BAO/Note.php @@ -477,6 +477,7 @@ private static function buildNoteTree($parentId, $maxDepth = 0, $snippet = FALSE $contact->fetch(); $tree[$note->id]['createdBy'] = $contact->display_name; $tree[$note->id]['createdById'] = $createdById; + $tree[$note->id]['created_date'] = CRM_Utils_Date::customFormat($tree[$note->id]['created_date']); $tree[$note->id]['modified_date'] = CRM_Utils_Date::customFormat($tree[$note->id]['modified_date']); // paper icon view for attachments part diff --git a/CRM/Core/DAO/Note.php b/CRM/Core/DAO/Note.php index 4ce0f51f2179..91800a0ae758 100644 --- a/CRM/Core/DAO/Note.php +++ b/CRM/Core/DAO/Note.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Core/Note.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:444f6d1cb984753995b61839733abfc8) + * (GenCodeChecksum:eb9cd21da28a1101c6ba13da161fac6c) */ /** @@ -72,6 +72,13 @@ class CRM_Core_DAO_Note extends CRM_Core_DAO { */ public $contact_id; + /** + * When was the note created. + * + * @var datetime + */ + public $created_date; + /** * When was this note last modified/edited * @@ -220,6 +227,22 @@ public static function &fields() { ], 'add' => '1.1', ], + 'created_date' => [ + 'name' => 'created_date', + 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME, + 'title' => ts('Date Created'), + 'description' => ts('When was the note created.'), + 'where' => 'civicrm_note.created_date', + 'table_name' => 'civicrm_note', + 'entity' => 'Note', + 'bao' => 'CRM_Core_BAO_Note', + 'localizable' => 0, + 'html' => [ + 'type' => 'Select Date', + 'formatType' => 'activityDateTime', + ], + 'add' => '5.37', + ], 'modified_date' => [ 'name' => 'modified_date', 'type' => CRM_Utils_Type::T_TIMESTAMP, diff --git a/CRM/Note/Form/Note.php b/CRM/Note/Form/Note.php index 574bb9ecebb3..8e21e29eac22 100644 --- a/CRM/Note/Form/Note.php +++ b/CRM/Note/Form/Note.php @@ -130,6 +130,7 @@ public function buildQuickForm() { } $this->addField('subject'); + $this->addField('created_date', [], FALSE, FALSE); $this->addField('note', [], TRUE); $this->addField('privacy'); $this->add('hidden', 'parent_id'); diff --git a/CRM/Upgrade/Incremental/php/FiveThirtySeven.php b/CRM/Upgrade/Incremental/php/FiveThirtySeven.php index bad13a5b51dd..6d19b9717104 100644 --- a/CRM/Upgrade/Incremental/php/FiveThirtySeven.php +++ b/CRM/Upgrade/Incremental/php/FiveThirtySeven.php @@ -52,21 +52,15 @@ public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) { * (change the x in the function name): */ - // /** - // * Upgrade function. - // * - // * @param string $rev - // */ - // public function upgrade_5_0_x($rev) { - // $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); - // $this->addTask('Do the foo change', 'taskFoo', ...); - // // Additional tasks here... - // // Note: do not use ts() in the addTask description because it adds unnecessary strings to transifex. - // // The above is an exception because 'Upgrade DB to %1: SQL' is generic & reusable. - // } - - // public static function taskFoo(CRM_Queue_TaskContext $ctx, ...) { - // return TRUE; - // } + /** + * Upgrade function. + * + * @param string $rev + */ + public function upgrade_5_37_alpha1($rev) { + $this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev); + $this->addTask('core-issue#2243 - Add created_date to civicrm_note', 'addColumn', + 'civicrm_note', 'created_date', "datetime DEFAULT NULL COMMENT 'When was the note created.'"); + } } diff --git a/templates/CRM/Contact/Page/View/Note.tpl b/templates/CRM/Contact/Page/View/Note.tpl index 8cdf82cfd7a0..77fa07294fc4 100644 --- a/templates/CRM/Contact/Page/View/Note.tpl +++ b/templates/CRM/Contact/Page/View/Note.tpl @@ -13,7 +13,8 @@
- + + @@ -33,7 +34,7 @@ {foreach from=$comments item=comment} - + {/foreach}
{ts}Subject{/ts}{$note.subject}
{ts}Date:{/ts}{$note.modified_date|crmDate}
{ts}Created Date:{/ts}{$note.created_date|crmDate}
{ts}Modified Date:{/ts}{$note.modified_date|crmDate}
{ts}Privacy:{/ts}{$note.privacy}
{ts}Note:{/ts}{$note.note|nl2br}
{ts}Comment{/ts}{ts}Created By{/ts}{ts}Date{/ts}
{$comment.note}{$comment.createdBy}{$comment.modified_date}
{$comment.note}{$comment.createdBy}{$comment.created_date}{$comment.modified_date}
@@ -51,6 +52,10 @@ {$form.subject.html} + + {$form.created_date.label} + {$form.created_date.html} + {$form.privacy.label} @@ -149,6 +154,8 @@ + '' + response['values'][i].subject + '' + + response['values'][i].created_date + + '' + response['values'][i].modified_date + '' + ''+ response['values'][i].createdBy +'' @@ -192,7 +199,8 @@ {ts}Note{/ts} {ts}Subject{/ts} - {ts}Date{/ts} + {ts}Created Date{/ts} + {ts}Modified Date{/ts} {ts}Created By{/ts} {ts}Attachment(s){/ts} @@ -222,6 +230,7 @@ {/if} {$note.subject} + {$note.created_date|crmDate} {$note.modified_date|crmDate} {$note.createdBy} diff --git a/tests/phpunit/api/v3/NoteTest.php b/tests/phpunit/api/v3/NoteTest.php index 8b2021df46fe..5b66f4cdf90d 100644 --- a/tests/phpunit/api/v3/NoteTest.php +++ b/tests/phpunit/api/v3/NoteTest.php @@ -27,12 +27,14 @@ public function setUp() { $this->useTransaction(TRUE); $this->_contactID = $this->organizationCreate(NULL); + $this->_createdDate = date('Y-m-d H:i:s', strtotime('-10 years')); $this->_params = [ 'entity_table' => 'civicrm_contact', 'entity_id' => $this->_contactID, 'note' => 'Hello!!! m testing Note', 'contact_id' => $this->_contactID, + 'created_date' => $this->_createdDate, 'modified_date' => '2011-01-31', 'subject' => 'Test Note', ]; @@ -137,6 +139,7 @@ public function testCreate($version) { $result = $this->callAPIAndDocument('note', 'create', $this->_params, __FUNCTION__, __FILE__); $this->assertEquals($result['values'][$result['id']]['note'], 'Hello!!! m testing Note'); + $this->assertEquals(date('Y-m-d', strtotime($this->_createdDate)), date('Y-m-d', strtotime($result['values'][$result['id']]['created_date']))); $this->assertEquals(date('Y-m-d', strtotime($this->_params['modified_date'])), date('Y-m-d', strtotime($result['values'][$result['id']]['modified_date']))); $this->assertArrayHasKey('id', $result); @@ -153,6 +156,7 @@ public function testCreateWithApostropheInString($version) { 'entity_id' => $this->_contactID, 'note' => "Hello!!! ' testing Note", 'contact_id' => $this->_contactID, + 'created_date' => $this->_createdDate, 'modified_date' => '2011-01-31', 'subject' => "With a '", 'sequential' => 1, @@ -221,6 +225,7 @@ public function testUpdate($version) { 'contact_id' => $this->_contactID, 'note' => 'Note1', 'subject' => 'Hello World', + 'created_date' => date('Y-m-d H:i:s', strtotime('-2 years')), ]; // Update Note. @@ -229,6 +234,7 @@ public function testUpdate($version) { $this->assertEquals($note['id'], $this->_noteID); $this->assertEquals($note['values'][$this->_noteID]['entity_id'], $this->_contactID); $this->assertEquals($note['values'][$this->_noteID]['entity_table'], 'civicrm_contact'); + $this->assertEquals($note['values'][$this->_noteID]['created_date'], $params['created_date']); $this->assertEquals('Hello World', $note['values'][$this->_noteID]['subject']); $this->assertEquals('Note1', $note['values'][$this->_noteID]['note']); } diff --git a/xml/schema/Core/Note.xml b/xml/schema/Core/Note.xml index 4f594b78d45d..6e8bb437d598 100644 --- a/xml/schema/Core/Note.xml +++ b/xml/schema/Core/Note.xml @@ -86,6 +86,17 @@ 1.1 SET NULL + + created_date + Date Created + datetime + 5.37 + When was the note created. + + Select Date + activityDateTime + + modified_date Note Modified By