Commit 2cdb70ef authored by jaapjansma's avatar jaapjansma
Browse files

solved issue with backwards compatibility and solved issue with new case documents

parent 2bc3cf5f
......@@ -9,38 +9,35 @@ use CRM_Documents_ExtensionUtil as E;
* @see http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference
*/
class CRM_Documents_Form_Document extends CRM_Core_Form {
protected $document;
protected $cid;
protected $documentId = false;
protected $context;
protected $entity = false;
function preProcess() {
parent::preProcess();
$this->assign('is44', CRM_Documents_Utils_CiviVersion::is44());
$session = CRM_Core_Session::singleton();
$entityRefs = CRM_Documents_Utils_EntityRef::singleton();
$this->context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'contact');
$this->add('hidden', 'context', $this->context);
$this->documentId = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE);
$this->add('hidden', 'id', $this->documentId);
$this->cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE);
$this->add('hidden', 'cid', $this->cid);
//retrieve action
$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this);
$this->assign('action', $this->_action);
if ($this->documentId) {
$documentsRepo = CRM_Documents_Entity_DocumentRepository::singleton();
try {
......@@ -52,10 +49,10 @@ class CRM_Documents_Form_Document extends CRM_Core_Form {
}
} else {
$this->document = new CRM_Documents_Entity_Document();
//if it is a case set the caseID and set the clients as contactId's
if ($this->context == 'case') {
$caseId = CRM_Utils_Request::retrieve('case_id', 'Positive', $this, TRUE);
$caseId = CRM_Utils_Request::retrieve('case_id', 'Positive', $this, TRUE);
$this->add('hidden', 'case_id', $caseId);
$case = civicrm_api3('Case', 'getsingle', array("case_id"=>$caseId ));
$this->document->addCaseid($caseId);
......@@ -63,11 +60,11 @@ class CRM_Documents_Form_Document extends CRM_Core_Form {
} else {
//set the contactId
$this->document->setContactIds(array($this->cid));
}
}
}
$this->assign('document', $this->document);
$this->entity = false;
$entity = CRM_Utils_Request::retrieve('entity', 'String', $this, FALSE);
$entity_id = CRM_Utils_Request::retrieve('entity_id', 'Positive', $this, FALSE);
......@@ -80,12 +77,12 @@ class CRM_Documents_Form_Document extends CRM_Core_Form {
$this->document->addNewEntity($ref->getEntityTableName(), $entity_id);
}
}
//if there is no link to anything not even a contact throw an error
if ($ref === false && !$this->cid) {
throw new Exception('Could find valid value for cid');
}
if ($ref) {
$active_entities = array(' -- Select '.$ref->getHumanName().' --') + $ref->getActiveEntities();
$attributes = array();
......@@ -94,17 +91,17 @@ class CRM_Documents_Form_Document extends CRM_Core_Form {
}
$this->add('select', $ref->getSystemName(), $ref->getHumanName(), $active_entities, false, $attributes);
}
$this->assign('selectedContacts', implode(",", $this->document->getContactIds()));
//Set page title based on action
$this->setPageTitleBasedOnAction();
}
function setDefaultValues() {
$return = parent::setDefaultValues();
$entityRefs = CRM_Documents_Utils_EntityRef::singleton();
foreach($this->document->getEntities() as $entity) {
$ref = $entityRefs->getRefByTableName($entity->getEntityTable());
......@@ -117,13 +114,11 @@ class CRM_Documents_Form_Document extends CRM_Core_Form {
}
}
if (!CRM_Documents_Utils_CiviVersion::is44()) {
$return['contacts'] = $this->document->getContactIds();
}
$return['contacts'] = $this->document->getContactIds();
return $return;
}
function buildQuickForm() {
if ($this->_action == CRM_Core_Action::DELETE) {
$this->addButtons(array(
......@@ -141,8 +136,8 @@ class CRM_Documents_Form_Document extends CRM_Core_Form {
return;
}
$this->add(
'text',
'subject',
'text',
'subject',
E::ts('Subject'),
array(
'value' => $this->document->getSubject(),
......@@ -150,8 +145,8 @@ class CRM_Documents_Form_Document extends CRM_Core_Form {
'size' => CRM_Utils_Type::HUGE,
),
true
);
);
$this->addButtons(array(
array(
'type' => 'upload',
......@@ -167,15 +162,10 @@ class CRM_Documents_Form_Document extends CRM_Core_Form {
// export form elements
$this->assign('elementNames', $this->getRenderableElementNames());
if (CRM_Documents_Utils_CiviVersion::is44()) {
CRM_Contact_Form_NewContact::buildQuickForm($this);
} else {
$this->addEntityRef('contacts', E::ts('Contacts'), array('multiple' => TRUE, 'create' => TRUE), true);
}
$this->addEntityRef('contacts', E::ts('Contacts'), array('multiple' => TRUE, 'create' => TRUE), true);
CRM_Core_BAO_File::buildAttachment($this, 'civicrm_document_version', $this->document->getCurrentVersion()->getId(), 1, TRUE);
parent::buildQuickForm();
}
......@@ -184,24 +174,20 @@ class CRM_Documents_Form_Document extends CRM_Core_Form {
if ($this->_action & CRM_Core_Action::DELETE) {
//delete the document
$documentsRepo->remove($this->document);
CRM_Core_Session::setStatus(E::ts("Selected document has been successfully deleted."), E::ts('Record Deleted'), 'success');
return;
}
$values = $this->controller->exportValues();
$contact_ids = array();
// format with contact (target contact) values
if (isset($values['contact'][1])) {
$contact_ids = explode(',', $values['contact'][1]);
} elseif (!CRM_Documents_Utils_CiviVersion::is44()) {
$contact_ids = explode(",", $values['contacts']);
}
$contact_ids = explode(",", $values['contacts']);
$this->document->setSubject($this->exportValue('subject'));
$this->document->setContactIds($contact_ids);
$entityRefs = CRM_Documents_Utils_EntityRef::singleton();
$refs = $entityRefs->getRefs();
foreach($refs as $ref) {
......@@ -212,7 +198,7 @@ class CRM_Documents_Form_Document extends CRM_Core_Form {
$this->document->removeEntity($entity);
}
}
if (is_array($values[$ref->getSystemName()])) {
foreach($values[$ref->getSystemName()] as $entity_id) {
$this->document->addNewEntity($ref->getEntityTableName(), $entity_id);
......@@ -222,7 +208,7 @@ class CRM_Documents_Form_Document extends CRM_Core_Form {
}
}
}
foreach($this->document->getEntities() as $entity) {
$ref = $entityRefs->getRefByTableName($entity->getEntityTable());
if ($ref) {
......@@ -246,9 +232,9 @@ class CRM_Documents_Form_Document extends CRM_Core_Form {
//save document
$documentsRepo->persist($this->document);
CRM_Core_BAO_File::processAttachment($params, 'civicrm_document_version', $this->document->getCurrentVersion()->getId());
parent::postProcess();
}
/**
......@@ -270,7 +256,7 @@ class CRM_Documents_Form_Document extends CRM_Core_Form {
}
return $elementNames;
}
protected function setPageTitleBasedOnAction() {
CRM_Utils_System::setTitle(E::ts('Add new document'));
if ($this->_action == CRM_Core_Action::DELETE) {
......
<?php
/*
/*
* This class is used to display the documents which belongs to a case
*
*
*/
class CRM_Documents_Page_CaseDocuments extends CRM_Core_Page {
protected $caseId;
protected $clientId;
protected $context;
protected $action;
public function __construct($caseId) {
parent::__construct();
$this->caseId = $caseId;
}
public function run() {
$this->preProcess();
//get template file name
$pageTemplateFile = $this->getHookedTemplateFileName();
//do the magic
//do the magic
$documentRepo = CRM_Documents_Entity_DocumentRepository::singleton();
$documents = $documentRepo->getDocumentsByCaseId($this->caseId);
$this->assign('caseId', $this->caseId);
$this->assign('clientId', $this->clientId);
$this->assign('documents', $documents);
$this->assign('documents', $documents);
$this->assign('permission', 'edit');
$this->assign('isCivi44', CRM_Documents_Utils_CiviVersion::is44());
//render the template
$content = self::$_template->fetch($pageTemplateFile);
CRM_Utils_System::appendTPLFile($pageTemplateFile, $content);
//its time to call the hook.
CRM_Utils_Hook::alterContent($content, 'page', $pageTemplateFile, $this);
return $content;
return $content;
}
protected function preProcess() {
//retrieve the client contactId
$case = civicrm_api3('Case', 'getsingle', array("case_id"=>$this->caseId ));
$this->clientId = reset($case['client_id']);
$this->context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'home');
$this->action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, CRM_Core_Action::VIEW);
$this->assign('context', $this->context);
$this->setUserContext();
}
protected function setUserContext() {
protected function setUserContext() {
$action = CRM_Core_Action::description($this->action);
$session = CRM_Core_Session::singleton();
$userContext = CRM_Utils_System::url('civicrm/contact/view/case', 'action='.$action.'&cid='.$this->clientId.'&&reset=1&id='.$this->caseId.'&context='.$this->context);
......
<?php
/**
* @author Jaap Jansma (CiviCooP) <jaap.jansma@civicoop.org>
* @license http://www.gnu.org/licenses/agpl-3.0.html
*/
class CRM_Documents_Utils_CiviVersion {
/**
* Returns whether the civi version is less or eq to 4.4
* @return bool
*/
public static function is44() {
$civiVersion = CRM_Core_BAO_Domain::version();
if (version_compare($civiVersion, '4.5', '<')) {
return true;
}
return false;
}
}
\ No newline at end of file
......@@ -15,10 +15,10 @@
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2021-10-12</releaseDate>
<version>1.12</version>
<version>1.13-dev</version>
<develStage>stable</develStage>
<compatibility>
<ver>4.7</ver>
<ver>5.41</ver>
</compatibility>
<comments>Extension is live at several clients</comments>
<classloader>
......
......@@ -23,13 +23,7 @@
{/if}
<tr>
<td class="label">{ts}Contacts{/ts}</td>
<td>
{if ($is44)}
{include file="CRM/Contact/Form/NewContact.tpl" noLabel=true skipBreak=true multiClient=true parent="document" showNewSelect=false}
{else}
{$form.contacts.html}
{/if}
</td>
<td>{$form.contacts.html}</td>
</tr>
{foreach from=$elementNames item=elementName}
......@@ -46,20 +40,6 @@
</tr>
</table>
<script type="ẗext/javascript">
{literal}
CRM.$(function($) {
var $contactField = $("#contacts[type=text]");
var api = {params: {}};
$contactField.val('')
.prop('disabled', false)
.data('api-params', api)
.data('user-filter', {})
.attr('placeholder', '')
.change();
});
{/literal}
</script>
{/if}
{* FOOTER *}
......
......@@ -30,7 +30,7 @@
</tr>
</thead>
<tbody>
{foreach from=$documents item=doc}
<tr class="{cycle values="odd,even"}">
<td><i class="crm-i {$doc->getIcon()}"></i> {$doc->getSubject()}</td>
......@@ -52,11 +52,7 @@
{literal}
cj(function() {
var caseDocs = cj('#case-documents').detach();
{/literal}{if ($isCivi44)}{literal}
cj('#view-related-cases').after(caseDocs);
{/literal}{else}{literal}
cj('#case_custom_edit').after(caseDocs);
{/literal}{/if}{literal}
});
{/literal}
</script>
......
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