Skip to content

Commit

Permalink
add created_date to civicrm_note
Browse files Browse the repository at this point in the history
  • Loading branch information
Jitendra Purohit committed Mar 5, 2021
1 parent 16d5ffe commit cb4c8e4
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 20 deletions.
1 change: 1 addition & 0 deletions CRM/Core/BAO/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 24 additions & 1 deletion CRM/Core/DAO/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Generated from xml/schema/CRM/Core/Note.xml
* DO NOT EDIT. Generated by CRM_Core_CodeGen
* (GenCodeChecksum:444f6d1cb984753995b61839733abfc8)
* (GenCodeChecksum:eb9cd21da28a1101c6ba13da161fac6c)
*/

/**
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions CRM/Note/Form/Note.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
26 changes: 10 additions & 16 deletions CRM/Upgrade/Incremental/php/FiveThirtySeven.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'");
}

}
15 changes: 12 additions & 3 deletions templates/CRM/Contact/Page/View/Note.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<div class="crm-block crm-content-block crm-note-view-block">
<table class="crm-info-panel">
<tr><td class="label">{ts}Subject{/ts}</td><td>{$note.subject}</td></tr>
<tr><td class="label">{ts}Date:{/ts}</td><td>{$note.modified_date|crmDate}</td></tr>
<tr><td class="label">{ts}Created Date:{/ts}</td><td>{$note.created_date|crmDate}</td></tr>
<tr><td class="label">{ts}Modified Date:{/ts}</td><td>{$note.modified_date|crmDate}</td></tr>
<tr><td class="label">{ts}Privacy:{/ts}</td><td>{$note.privacy}</td></tr>
<tr><td class="label">{ts}Note:{/ts}</td><td>{$note.note|nl2br}</td></tr>

Expand All @@ -33,7 +34,7 @@
<tr><th>{ts}Comment{/ts}</th><th>{ts}Created By{/ts}</th><th>{ts}Date{/ts}</th></tr>
</thead>
{foreach from=$comments item=comment}
<tr class="{cycle values='odd-row,even-row'}"><td>{$comment.note}</td><td>{$comment.createdBy}</td><td>{$comment.modified_date}</td></tr>
<tr class="{cycle values='odd-row,even-row'}"><td>{$comment.note}</td><td>{$comment.createdBy}</td><td>{$comment.created_date}</td><td>{$comment.modified_date}</td></tr>
{/foreach}
</table>
</fieldset>
Expand All @@ -51,6 +52,10 @@
{$form.subject.html}
</td>
</tr>
<tr>
<td class="label">{$form.created_date.label}</td>
<td>{$form.created_date.html}</td>
</tr>
<tr>
<td class="label">{$form.privacy.label}</td>
<td>
Expand Down Expand Up @@ -149,6 +154,8 @@
+ '</td><td>'
+ response['values'][i].subject
+ '</td><td>'
+ response['values'][i].created_date
+ '</td><td>'
+ response['values'][i].modified_date
+ '</td><td>'
+ '<a href="'+ urlTemplate + response['values'][i].createdById +'">'+ response['values'][i].createdBy +'</a>'
Expand Down Expand Up @@ -192,7 +199,8 @@
<th data-orderable="false"></th>
<th>{ts}Note{/ts}</th>
<th>{ts}Subject{/ts}</th>
<th>{ts}Date{/ts}</th>
<th>{ts}Created Date{/ts}</th>
<th>{ts}Modified Date{/ts}</th>
<th>{ts}Created By{/ts}</th>
<th data-orderable="false">{ts}Attachment(s){/ts}</th>
<th data-orderable="false"></th>
Expand Down Expand Up @@ -222,6 +230,7 @@
{/if}
</td>
<td class="crm-note-subject crmf-subject crm-editable">{$note.subject}</td>
<td class="crm-note-created_date" data-order="{$note.created_date}">{$note.created_date|crmDate}</td>
<td class="crm-note-modified_date" data-order="{$note.modified_date}">{$note.modified_date|crmDate}</td>
<td class="crm-note-createdBy">
<a href="{crmURL p='civicrm/contact/view' q="reset=1&cid=`$note.contact_id`"}">{$note.createdBy}</a>
Expand Down
6 changes: 6 additions & 0 deletions tests/phpunit/api/v3/NoteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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']);
}
Expand Down
11 changes: 11 additions & 0 deletions xml/schema/Core/Note.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@
<add>1.1</add>
<onDelete>SET NULL</onDelete>
</foreignKey>
<field>
<name>created_date</name>
<title>Date Created</title>
<type>datetime</type>
<add>5.37</add>
<comment>When was the note created.</comment>
<html>
<type>Select Date</type>
<formatType>activityDateTime</formatType>
</html>
</field>
<field>
<name>modified_date</name>
<title>Note Modified By</title>
Expand Down

0 comments on commit cb4c8e4

Please sign in to comment.