Commit 1d913f61 authored by jaapjansma's avatar jaapjansma
Browse files

added filter to contact documents

parent cfb5f0d3
......@@ -42,9 +42,12 @@ class CRM_Documents_Entity_DocumentRepository {
*
* @param int $contactId
* @param bool $includeEditted include documents which are editted by the user
* @param bool $includeCaseDocuments
* @param int[] $typeIds
* @param int[] $statusIds
* @return array
*/
public function getDocumentsByContactId($contactId, $includeEditted=true, $includeCaseDocuments=false) {
public function getDocumentsByContactId($contactId, $includeEditted=true, $includeCaseDocuments=false, $typeIds=null, $statusIds=null) {
$documents = array();
$dao = new CRM_Documents_DAO_Document();
......@@ -59,6 +62,12 @@ class CRM_Documents_Entity_DocumentRepository {
if (!$includeCaseDocuments) {
$sql .= " AND `doc`.`id` NOT IN (SELECT `document_id` FROM `civicrm_document_case`)";
}
if (is_array($typeIds) && count($typeIds)) {
$sql .= " AND `doc`.`type_id` IN (" . implode(", ", $typeIds).")";
}
if (is_array($statusIds) && count($statusIds)) {
$sql .= " AND `doc`.`status_id` IN (" . implode(", ", $statusIds).")";
}
$docsDao = $dao->executeQuery(
$sql, array(
......
......@@ -5,34 +5,55 @@ use CRM_Documents_ExtensionUtil as E;
class CRM_Documents_Page_ContactDocuments extends CRM_Core_Page {
protected $_contactId;
function run() {
$this->preProcess();
CRM_Utils_System::setTitle(E::ts('Documents'));
$types = CRM_Core_OptionGroup::values('document_type');
$statuses = CRM_Core_OptionGroup::values('document_status');
$this->assign('document_types', $types);
$this->assign('document_statuses', $statuses);
$snippet = CRM_Utils_Request::retrieve('snippet', 'String');
$filter = CRM_Utils_Request::retrieve('filter', 'String');
$this->assign('snippet', $snippet && $filter ? true : false);
$type_id = CRM_Utils_Request::retrieve('type_id', 'String');
$type_ids = null;
if ($type_id) {
$type_ids = explode(",", $type_id);
}
$status_id = CRM_Utils_Request::retrieve('status_id', 'String');
$status_ids = null;
if ($status_id) {
$status_ids = explode(",", $status_id);
}
$documentRepo = CRM_Documents_Entity_DocumentRepository::singleton();
$documents = $documentRepo->getDocumentsByContactId($this->_contactId, false);
$documents = $documentRepo->getDocumentsByContactId($this->_contactId, false, false, $type_ids, $status_ids);
$this->assign('documents', $documents);
$this->assign('selected_document_types', $type_ids);
$this->assign('selected_document_status', $status_ids);
$this->assign('permission', 'view');
if (CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) {
$this->assign('permission', 'edit');
}
parent::run();
}
protected function preProcess() {
$this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE);
$this->assign('contactId', $this->_contactId);
$this->setUserContext();
}
protected function setUserContext() {
$session = CRM_Core_Session::singleton();
$userContext = CRM_Utils_System::url('civicrm/contact/view', 'cid='.$this->_contactId.'&selectedChild=contact_documents&reset=1');
......
{crmScope extensionKey='org.civicoop.documents'}
{if !$snippet}
<table class="form-layout">
<tbody>
<tr>
<td>
{ts}Type{/ts}<br>
<select id="document_type_id" class="huge crm-select2 crm-form-multiselect" multiple="multiple">
{foreach from=$document_types item=label key=value}
<option value="{$value}" {if (in_array($value, $selected_document_types))}selected="selected"{/if}>{$label}</option>
{/foreach}
</select>
</td>
<td>
{ts}Status{/ts}<br>
<select id="document_status_id" class="huge crm-select2 crm-form-multiselect" multiple="multiple">
{foreach from=$document_statuses item=label key=value}
<option value="{$value}" {if (in_array($value, $selected_document_status))}selected="selected"{/if}>{$label}</option>
{/foreach}
</select>
</td>
</tr>
</tbody>
</table>
{if $permission EQ 'edit'}
{capture assign=newDocumentURL}{crmURL p="civicrm/documents/document" q="reset=1&action=add&cid=`$contactId`"}{/capture}
<div class="action-link">
......@@ -8,7 +32,9 @@
</a>
</div>
{/if}
{/if}
<div id="contact-documents-body">
<table>
<thead>
<tr>
......@@ -39,5 +65,36 @@
{/foreach}
</tbody>
</table>
</div>
{if !$snippet}
<script type="text/javascript">
{literal}
cj(function() {
function loadDocuments() {
var formParams = {
reset: 1,
'cid': '{/literal}{$contactId}{literal}',
'filter': 1
};
if (cj('#document_type_id').val()) {
formParams.type_id = cj('#document_type_id').val().join(',');
}
if (cj('#document_status_id').val()) {
formParams.status_id = cj('#document_status_id').val().join(',');
}
var formUrl = CRM.url('civicrm/contact/view/documents', formParams);
var form = CRM.loadPage(formUrl, {
"target": '#contact-documents-body',
dialog: false
});
}
cj('#document_type_id').on('change', loadDocuments);
cj('#document_status_id').on('change', loadDocuments);
});
{/literal}
</script>
{/if}
{/crmScope}
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