Commit 58439a1c authored by jaapjansma's avatar jaapjansma
Browse files

Added custom fields

parent 10de5963
......@@ -76,6 +76,8 @@ class CRM_Documents_Entity_Document {
protected $status_id;
protected $customData;
public function __construct() {
$this->setDefaults();
}
......@@ -98,6 +100,14 @@ class CRM_Documents_Entity_Document {
$this->removedEntities = array();
}
public function setCustomData($customData) {
$this->customData = $customData;
}
public function getCustomData() {
return $this->customData;
}
public function getId() {
if (!empty($this->id)) {
return $this->id;
......
......@@ -389,6 +389,9 @@ class CRM_Documents_Entity_DocumentRepository {
//pre hook: copy values into array
$params = array();
CRM_Documents_DAO_Document::storeValues($dao, $params);
if ($document->getCustomData()) {
$params['custom'] = $document->getCustomData();
}
//call pre hook
CRM_Utils_Hook::pre($op, 'Document', $dao->id, $params);
//pre hook: copy array back to dao
......@@ -396,6 +399,12 @@ class CRM_Documents_Entity_DocumentRepository {
//do the actuall save
$dao->save();
if (!empty($params['custom']) &&
is_array($params['custom'])
) {
CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_document', $dao->id);
}
$document->setId($dao->id);
$this->persistContacts($document);
......
<?php
/*
/*
* This class holds information about the different document versions
*
*
*/
class CRM_Documents_Entity_DocumentVersion {
/**
*
* @var int
* @var int
*/
protected $id;
/**
*
* @var int the version number
*/
protected $version;
/**
*
* @var String description of the new version
*/
protected $description;
/**
*
* @var DateTime date updated
* @var DateTime date updated
*/
protected $dateUpdated;
/**
*
* @var int updatedBy
* @var int updatedBy
*/
protected $updatedBy;
/**
*
* @var CRM_Documents_Entity_DocumentFile the attached file
* @var CRM_Documents_Entity_DocumentFile the attached file
*/
protected $attachment;
/**
*
* @var CRM_Documents_Entity_Document
* @var CRM_Documents_Entity_Document
*/
protected $document;
protected $customData;
public function __construct(CRM_Documents_Entity_Document $document) {
$this->document = $document;
$this->attachment = new CRM_Documents_Entity_DocumentFile();
$this->dateUpdated = new DateTime();
}
public function getDocument() {
return $this->document;
}
public function setId($id) {
$this->id = $id;
}
public function getId() {
return $this->id;
}
public function setDescription($description) {
$this->description = $description;
}
public function getDescription() {
return $this->description;
}
public function setDateUpdated(DateTime $date) {
$this->dateUpdated = $date;
}
public function getDateUpdated() {
return $this->dateUpdated;
}
public function getUpdatedBy() {
return $this->updatedBy;
}
public function setUpdatedBy($updatedBy) {
$this->updatedBy = $updatedBy;
}
public function setVersion($version) {
$this->version = $version;
}
public function getVersion() {
return $this->version;
}
public function setAttachment(CRM_Documents_Entity_DocumentFile $file) {
$this->attachment = $file;
}
public function getAttachment() {
return $this->attachment;
}
public function getFormattedUpdatedBy($link=TRUE) {
$formatter = CRM_Documents_Utils_Formatter::singleton();
return $formatter->formatContact($this->getUpdatedBy(), $link);
}
public function getFormattedDateUpdated() {
$formatter = CRM_Documents_Utils_Formatter::singleton();
return $formatter->formateDate($this->getDateUpdated());
}
}
\ No newline at end of file
}
......@@ -40,6 +40,8 @@ class CRM_Documents_Form_CaseDocuments extends CRM_Core_Form {
$documentRepo = CRM_Documents_Entity_DocumentRepository::singleton();
$documents = $documentRepo->getDocumentsByCaseId($this->caseId, $type_ids, $status_ids);
$this->assign('documents', $documents);
$this->assign('clientId', $this->clientId);
$this->assign('permission', 'edit');
}
public function buildQuickForm() {
......
......@@ -20,6 +20,10 @@ class CRM_Documents_Form_Document extends CRM_Core_Form {
protected $entity = false;
public function getEntityId() {
return $this->documentId;
}
function preProcess() {
parent::preProcess();
$session = CRM_Core_Session::singleton();
......@@ -29,6 +33,7 @@ class CRM_Documents_Form_Document extends CRM_Core_Form {
$this->add('hidden', 'context', $this->context);
$this->documentId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
$this->assign('id', $this->documentId);
$this->add('hidden', 'id', $this->documentId);
$this->cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
......@@ -97,6 +102,13 @@ class CRM_Documents_Form_Document extends CRM_Core_Form {
//Set page title based on action
$this->setPageTitleBasedOnAction();
if (!empty($_POST['hidden_custom'])) {
$type_id = $this->getSubmitValue('type_id');
CRM_Custom_Form_CustomData::preProcess($this, NULL, $type_id, 1, 'Document', $this->getEntityId());
CRM_Custom_Form_CustomData::buildQuickForm($this);
CRM_Custom_Form_CustomData::setDefaultValues($this);
}
}
function setDefaultValues() {
......@@ -237,6 +249,8 @@ class CRM_Documents_Form_Document extends CRM_Core_Form {
$this->document->getCurrentVersion()->getId()
);
$this->document->setCustomData(\CRM_Core_BAO_CustomField::postProcess($values, $this->document->getId(), 'Document'));
//save document
$documentsRepo->persist($this->document);
CRM_Core_BAO_File::processAttachment($params, 'civicrm_document_version', $this->document->getCurrentVersion()->getId());
......
......@@ -19,14 +19,7 @@ class CRM_Documents_Upgrader extends CRM_Documents_Upgrader_Base {
'label' => E::ts('Document'),
'value' => 'Document',
'name' => 'civicrm_document',
'description' => 'CRM_Document_Utils_Type::getTypes;',
]);
civicrm_api3('OptionValue', 'create', [
'option_group_id' => "cg_extend_objects",
'label' => E::ts('Document Version'),
'value' => 'DocumentVersion',
'name' => 'civicrm_document_version',
'description' => 'CRM_Document_Utils_Type::getTypes;',
'description' => 'CRM_Documents_Utils_Type::getTypes;',
]);
$statusOptionGroupId = civicrm_api3('OptionGroup', 'create', ['name' => 'document_status', 'title' => E::ts('Document Status')]);
......@@ -42,7 +35,6 @@ class CRM_Documents_Upgrader extends CRM_Documents_Upgrader_Base {
}
public function uninstall() {
$this->removeCustomExtend('DocumentVersion');
$this->removeCustomExtend('Document');
$this->removeOptionGroup('document_status');
$this->removeOptionGroup('document_type');
......@@ -117,14 +109,7 @@ class CRM_Documents_Upgrader extends CRM_Documents_Upgrader_Base {
'label' => E::ts('Document'),
'value' => 'Document',
'name' => 'civicrm_document',
'description' => 'CRM_Document_Utils_Type::getTypes;',
]);
civicrm_api3('OptionValue', 'create', [
'option_group_id' => "cg_extend_objects",
'label' => E::ts('Document Version'),
'value' => 'DocumentVersion',
'name' => 'civicrm_document_version',
'description' => 'CRM_Document_Utils_Type::getTypes;',
'description' => 'CRM_Documents_Utils_Type::getTypes;',
]);
$statusOptionGroupId = civicrm_api3('OptionGroup', 'create', ['name' => 'document_status', 'title' => E::ts('Document Status')]);
......@@ -141,6 +126,13 @@ class CRM_Documents_Upgrader extends CRM_Documents_Upgrader_Base {
return TRUE;
}
public function upgrade_1006() {
$this->ctx->log->info('Applying update 1006');
// this path is relative to the extension base dir
$this->executeSqlFile('sql/upgrade_1006.sql');
return TRUE;
}
protected function removeOptionGroup($name) {
$optionGroupId = civicrm_api3('OptionGroup', 'getvalue', ['return' => 'id', 'name' => $name]);
$optionValues = civicrm_api3('OptionValue', 'get', ['option_group_id' => $optionGroupId, 'options' => ['limit' => 0]]);
......
......@@ -4,7 +4,7 @@
* @license AGPL-3.0
*/
class CRM_Document_Utils_Type {
class CRM_Documents_Utils_Type {
public static function getTypes() {
$optionValues = civicrm_api3('OptionValue', 'get', ['option_group_id' => 'document_type', 'options' => ['limit' => 0]]);
......
ALTER TABLE `civicrm_document`
CHANGE `id` `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique Document ID';
ALTER TABLE `civicrm_document_version`
CHANGE `id` `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique Document ID';
ALTER TABLE `civicrm_document_case`
CHANGE `id` `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique Document ID';
ALTER TABLE `civicrm_document_contact`
CHANGE `id` `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique Document ID';
ALTER TABLE `civicrm_document_entity`
CHANGE `id` `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique Document ID';
......@@ -40,6 +40,8 @@
</tr>
</table>
{include file="CRM/Documents/common/customDataBlock.tpl" customDataType='Document' entityID=$id}
{/if}
{* FOOTER *}
......
{*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*}
{literal}
<script type="text/javascript">
(function($) {
CRM.buildCustomData = function (type, subType, subName, cgCount, groupID, isMultiple, onlySubtype, cid) {
var dataUrl = CRM.url('civicrm/custom', {type: type}),
prevCount = 1,
fname = '#customData_'+type,
storage = {};
if (subType) {
dataUrl += '&subType=' + subType;
}
if (onlySubtype) {
dataUrl += '&onlySubtype=' + onlySubtype;
}
if (subName) {
dataUrl += '&subName=' + subName;
$('#customData' + subName).show();
}
else {
$('#customData').show();
}
if (groupID) {
dataUrl += '&groupID=' + groupID;
}
{/literal}
{if $groupID}
dataUrl += '&groupID=' + '{$groupID}';
{/if}
{if $entityID}
dataUrl += '&entityID=' + '{$entityID}';
{/if}
{if $qfKey}
dataUrl += '&qf=' + '{$qfKey}';
{/if}
{if $action}
dataUrl += '&action=' + '{$action}';
{/if}
{literal}
if (cid) {
dataUrl += '&cid=' + cid;
}
if (!cgCount) {
cgCount = 1;
}
else if (cgCount >= 1) {
prevCount = cgCount;
cgCount++;
}
dataUrl += '&cgcount=' + cgCount;
if (isMultiple) {
fname = '#custom_group_' + groupID + '_' + prevCount;
if ($(".add-more-link-" + groupID + "-" + prevCount).length) {
$(".add-more-link-" + groupID + "-" + prevCount).hide();
}
else {
$("#add-more-link-" + prevCount).hide();
}
}
else if (subName && subName != 'null') {
fname += subName;
}
return CRM.loadPage(dataUrl, {target: fname});
};
})(CRM.$);
</script>
{/literal}
{if $customDataType}
<div id="customData_{$customDataType}"></div>
{*include custom data js file*}
{include file="CRM/Expenses/common/customData.tpl"}
{assign var='cid' value=$cid|default:'false'}
{literal}
<script type="text/javascript">
CRM.$(function($) {
function updateCustomData{/literal}{$customDataType}{literal}() {
var subType = '{/literal}{$expense_type_id}{literal}';
if ($('#type_id').length) {
subType = $('#type_id').val();
}
CRM.buildCustomData('{/literal}{$customDataType}{literal}', subType, false, false, false, false, false, {/literal}{$cid}{literal});
}
if ($('#type_id').length) {
$('#type_id').on('change', updateCustomData{/literal}{$customDataType}{literal});
}
updateCustomData{/literal}{$customDataType}{literal}();
});
</script>
{/literal}
{/if}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment