Loading modules/dvg/dvg_datab/dvg_datab.admin.inc +15 −0 Changes for modules/dvg/dvg_datab/dvg_datab.admin.inc: 15 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -51,6 +51,21 @@ function dvg_datab_settings() { '#description' => t('Demo mode will display a list of example files.'), ); $form['dvg_datab']['demo_mode_bsn'] = array( '#title' => t('Demo-BSN to use'), '#type' => 'select', '#description' => t('Select the BSN to load documents for.'), '#options' => DVG_DATAB_DEMO_BSN, '#default_value' => !empty($datab['demo_mode_bsn']) ? $datab['demo_mode_bsn'] : DVG_DATAB_DEMO_BSN[0], ); $form['dvg_datab']['table_display'] = array( '#type' => 'checkbox', '#title' => t('View as table'), '#default_value' => !empty($datab['table_display']) ? $datab['table_display'] : 0, '#description' => t('If checked the files will be presented as a table with more information than the default list.'), ); $form['dvg_datab_test'] = array( '#type' => 'fieldset', '#title' => t('Test connection'), Loading modules/dvg/dvg_datab/dvg_datab.module +105 −19 Changes for modules/dvg/dvg_datab/dvg_datab.module: 105 added lines, 19 removed lines. Original line number Diff line number Diff line <?php define('DVG_DATAB_DEMO_BSN', 200600000279400); define('DVG_DATAB_DEMO_BSN', [200600000279400, 200600000113900, 200600000134700]); define('DVG_DATAB_DEMO_CID', 8888); define('DVG_DATAB_DEMO_SECRET', 'secret'); Loading Loading @@ -117,7 +117,21 @@ function dvg_datab_doclist($bsn) { ))); } return !empty($data['response']['document']) ? $data['response']['document'] : array(); $documents_array = []; if (!empty($data['response']['document'])) { foreach ($data['response']['document'] as $document) { // Assure attachments are always sub-arrays. if (!empty($document['bijlage']) && isset($document['bijlage']['bijlid'])) { $bijlage = $document['bijlage']; unset($document['bijlage']); $document['bijlage'][] = $bijlage; } $documents_array[] = $document; } } return $documents_array; } /** Loading Loading @@ -160,11 +174,24 @@ function dvg_datab_doc_info($bsn, $docid) { $name = $type = ''; $doclist = dvg_datab_doclist($bsn); foreach ($doclist as $doc) { // We are looking for a root doc. if ($doc['docid'] == $docid) { $name = $doc['description']; $type = _dvg_datab_doctype($doc['doctype']); break; } if (strpos($docid, '#') !== false) { // We are looking for an attachment. if (!empty($doc['bijlage'])) { foreach ($doc['bijlage'] as $attachment) { if ($attachment['bijlid'] == $docid) { $name = $attachment['description']; $type = _dvg_datab_doctype($attachment['doctype']); break; } } } } } return array( Loading Loading @@ -321,7 +348,9 @@ function _dvg_datab_sort_doclist($a, $b) { * Generates the Data B doclist. */ function _dvg_datab_generate_doclist() { $bsn = !_dvg_datab_in_demo_mode() ? dvg_authentication_get_external_user_value('bsn') : DVG_DATAB_DEMO_BSN; $datab = variable_get('dvg_datab', array()); $demo_bsn = isset($datab['demo_mode_bsn']) ? DVG_DATAB_DEMO_BSN[$datab['demo_mode_bsn']] : DVG_DATAB_DEMO_BSN[0]; $bsn = !_dvg_datab_in_demo_mode() ? dvg_authentication_get_external_user_value('bsn') : $demo_bsn; $doclist = array(); try { Loading Loading @@ -356,42 +385,68 @@ function _dvg_datab_generate_doclist() { foreach ($all_docs as $docs_year => $docs) { $items_year = array(); foreach ($docs as $doc) { $item = $doc['description']; $type = _dvg_datab_doctype($doc['doctype']); $url = current_path() . '/docid/' . $doc['docid']; $options = array( 'attributes' => array( 'class' => array('link-file'), ), ); $link_to_doc = _dvg_datab_doc_to_link($doc); if ($type) { $options['html'] = TRUE; $item = '<span class="file type-' . drupal_clean_css_identifier($type) . '">' . $type . ' </span>' . $item; if (empty($datab['table_display'])) { // Just add a simple link to the doc. $items_year[] = $link_to_doc; } else { // We add a row to the table, so add an array with doc properties. $amount = t('n.a.'); if (!empty($doc['betaaldata']) && !empty($doc['betaaldata']['bedrag'])) { $amount = '€ ' . $doc['betaaldata']['bedrag']; } $description_text = $link_to_doc; if (!empty($doc['bijlage'])) { foreach ($doc['bijlage'] as $attachment) { $description_text .= t('<br/>- Attachment: !doc_link', ['!doc_link' => _dvg_datab_doc_to_link($attachment)]); } } $items_year[] = [ $description_text, date('d-m-Y', strtotime($doc['startdatum'])), $amount]; } $items_year[] = '<span class="file">' . l($item, $url, $options) . '</span>'; } if (empty($datab['table_display'])) { $items[] = theme('item_list', array( 'items' => $items_year, 'title' => $docs_year, 'class' => array('doclist-year'), )); } else { $items[] = theme('table', array( 'caption' => t('Documents for @year', ['@year' => $docs_year]), 'header' => [t('Description'), t('Date'), t('Amount')], 'rows' => $items_year )); } } $result_docs = ''; if (empty($datab['table_display'])) { $list = array( 'items' => $items, 'class' => array('doclist'), ); $result_docs = theme('item_list', $list); } else { foreach ($items as $item) { $result_docs .= $item; } } $result_text = ''; if ($message = variable_get('dvg_datab_result_text', FALSE)) { $result_text = check_markup($message['value'], $message['format']); } return $result_text . theme('item_list', $list); return $result_text . $result_docs; } /** Loading @@ -400,7 +455,9 @@ function _dvg_datab_generate_doclist() { function dvg_datab_download_doc($node, $docid) { drupal_page_is_cacheable(FALSE); $bsn = !_dvg_datab_in_demo_mode() ? dvg_authentication_get_external_user_value('bsn') : DVG_DATAB_DEMO_BSN; $datab = variable_get('dvg_datab', array()); $demo_bsn = isset($datab['demo_mode_bsn']) ? DVG_DATAB_DEMO_BSN[$datab['demo_mode_bsn']] : DVG_DATAB_DEMO_BSN[0]; $bsn = !_dvg_datab_in_demo_mode() ? dvg_authentication_get_external_user_value('bsn') : $demo_bsn; $doc_info = array(); try { Loading Loading @@ -434,6 +491,35 @@ function dvg_datab_download_doc($node, $docid) { drupal_exit(); } /** * Helper to create a link to a doc. */ function _dvg_datab_doc_to_link($doc) { $item = $doc['description']; $type = _dvg_datab_doctype($doc['doctype']); // DocID for document or attachment. if (!empty($doc['docid'])) { $docid = $doc['docid']; } else { $docid = $doc['bijlid']; } $url = current_path() . '/docid/' . $docid; $options = array( 'attributes' => array( 'class' => array('link-file'), ), ); if ($type) { $options['html'] = TRUE; $item = '<span class="file type-' . drupal_clean_css_identifier($type) . '">' . $type . ' </span>' . $item; } return '<span class="file">' . l($item, $url, $options) . '</span>'; } /** * Helper to determine if the demo content should be dislayed. */ Loading Loading
modules/dvg/dvg_datab/dvg_datab.admin.inc +15 −0 Changes for modules/dvg/dvg_datab/dvg_datab.admin.inc: 15 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -51,6 +51,21 @@ function dvg_datab_settings() { '#description' => t('Demo mode will display a list of example files.'), ); $form['dvg_datab']['demo_mode_bsn'] = array( '#title' => t('Demo-BSN to use'), '#type' => 'select', '#description' => t('Select the BSN to load documents for.'), '#options' => DVG_DATAB_DEMO_BSN, '#default_value' => !empty($datab['demo_mode_bsn']) ? $datab['demo_mode_bsn'] : DVG_DATAB_DEMO_BSN[0], ); $form['dvg_datab']['table_display'] = array( '#type' => 'checkbox', '#title' => t('View as table'), '#default_value' => !empty($datab['table_display']) ? $datab['table_display'] : 0, '#description' => t('If checked the files will be presented as a table with more information than the default list.'), ); $form['dvg_datab_test'] = array( '#type' => 'fieldset', '#title' => t('Test connection'), Loading
modules/dvg/dvg_datab/dvg_datab.module +105 −19 Changes for modules/dvg/dvg_datab/dvg_datab.module: 105 added lines, 19 removed lines. Original line number Diff line number Diff line <?php define('DVG_DATAB_DEMO_BSN', 200600000279400); define('DVG_DATAB_DEMO_BSN', [200600000279400, 200600000113900, 200600000134700]); define('DVG_DATAB_DEMO_CID', 8888); define('DVG_DATAB_DEMO_SECRET', 'secret'); Loading Loading @@ -117,7 +117,21 @@ function dvg_datab_doclist($bsn) { ))); } return !empty($data['response']['document']) ? $data['response']['document'] : array(); $documents_array = []; if (!empty($data['response']['document'])) { foreach ($data['response']['document'] as $document) { // Assure attachments are always sub-arrays. if (!empty($document['bijlage']) && isset($document['bijlage']['bijlid'])) { $bijlage = $document['bijlage']; unset($document['bijlage']); $document['bijlage'][] = $bijlage; } $documents_array[] = $document; } } return $documents_array; } /** Loading Loading @@ -160,11 +174,24 @@ function dvg_datab_doc_info($bsn, $docid) { $name = $type = ''; $doclist = dvg_datab_doclist($bsn); foreach ($doclist as $doc) { // We are looking for a root doc. if ($doc['docid'] == $docid) { $name = $doc['description']; $type = _dvg_datab_doctype($doc['doctype']); break; } if (strpos($docid, '#') !== false) { // We are looking for an attachment. if (!empty($doc['bijlage'])) { foreach ($doc['bijlage'] as $attachment) { if ($attachment['bijlid'] == $docid) { $name = $attachment['description']; $type = _dvg_datab_doctype($attachment['doctype']); break; } } } } } return array( Loading Loading @@ -321,7 +348,9 @@ function _dvg_datab_sort_doclist($a, $b) { * Generates the Data B doclist. */ function _dvg_datab_generate_doclist() { $bsn = !_dvg_datab_in_demo_mode() ? dvg_authentication_get_external_user_value('bsn') : DVG_DATAB_DEMO_BSN; $datab = variable_get('dvg_datab', array()); $demo_bsn = isset($datab['demo_mode_bsn']) ? DVG_DATAB_DEMO_BSN[$datab['demo_mode_bsn']] : DVG_DATAB_DEMO_BSN[0]; $bsn = !_dvg_datab_in_demo_mode() ? dvg_authentication_get_external_user_value('bsn') : $demo_bsn; $doclist = array(); try { Loading Loading @@ -356,42 +385,68 @@ function _dvg_datab_generate_doclist() { foreach ($all_docs as $docs_year => $docs) { $items_year = array(); foreach ($docs as $doc) { $item = $doc['description']; $type = _dvg_datab_doctype($doc['doctype']); $url = current_path() . '/docid/' . $doc['docid']; $options = array( 'attributes' => array( 'class' => array('link-file'), ), ); $link_to_doc = _dvg_datab_doc_to_link($doc); if ($type) { $options['html'] = TRUE; $item = '<span class="file type-' . drupal_clean_css_identifier($type) . '">' . $type . ' </span>' . $item; if (empty($datab['table_display'])) { // Just add a simple link to the doc. $items_year[] = $link_to_doc; } else { // We add a row to the table, so add an array with doc properties. $amount = t('n.a.'); if (!empty($doc['betaaldata']) && !empty($doc['betaaldata']['bedrag'])) { $amount = '€ ' . $doc['betaaldata']['bedrag']; } $description_text = $link_to_doc; if (!empty($doc['bijlage'])) { foreach ($doc['bijlage'] as $attachment) { $description_text .= t('<br/>- Attachment: !doc_link', ['!doc_link' => _dvg_datab_doc_to_link($attachment)]); } } $items_year[] = [ $description_text, date('d-m-Y', strtotime($doc['startdatum'])), $amount]; } $items_year[] = '<span class="file">' . l($item, $url, $options) . '</span>'; } if (empty($datab['table_display'])) { $items[] = theme('item_list', array( 'items' => $items_year, 'title' => $docs_year, 'class' => array('doclist-year'), )); } else { $items[] = theme('table', array( 'caption' => t('Documents for @year', ['@year' => $docs_year]), 'header' => [t('Description'), t('Date'), t('Amount')], 'rows' => $items_year )); } } $result_docs = ''; if (empty($datab['table_display'])) { $list = array( 'items' => $items, 'class' => array('doclist'), ); $result_docs = theme('item_list', $list); } else { foreach ($items as $item) { $result_docs .= $item; } } $result_text = ''; if ($message = variable_get('dvg_datab_result_text', FALSE)) { $result_text = check_markup($message['value'], $message['format']); } return $result_text . theme('item_list', $list); return $result_text . $result_docs; } /** Loading @@ -400,7 +455,9 @@ function _dvg_datab_generate_doclist() { function dvg_datab_download_doc($node, $docid) { drupal_page_is_cacheable(FALSE); $bsn = !_dvg_datab_in_demo_mode() ? dvg_authentication_get_external_user_value('bsn') : DVG_DATAB_DEMO_BSN; $datab = variable_get('dvg_datab', array()); $demo_bsn = isset($datab['demo_mode_bsn']) ? DVG_DATAB_DEMO_BSN[$datab['demo_mode_bsn']] : DVG_DATAB_DEMO_BSN[0]; $bsn = !_dvg_datab_in_demo_mode() ? dvg_authentication_get_external_user_value('bsn') : $demo_bsn; $doc_info = array(); try { Loading Loading @@ -434,6 +491,35 @@ function dvg_datab_download_doc($node, $docid) { drupal_exit(); } /** * Helper to create a link to a doc. */ function _dvg_datab_doc_to_link($doc) { $item = $doc['description']; $type = _dvg_datab_doctype($doc['doctype']); // DocID for document or attachment. if (!empty($doc['docid'])) { $docid = $doc['docid']; } else { $docid = $doc['bijlid']; } $url = current_path() . '/docid/' . $docid; $options = array( 'attributes' => array( 'class' => array('link-file'), ), ); if ($type) { $options['html'] = TRUE; $item = '<span class="file type-' . drupal_clean_css_identifier($type) . '">' . $type . ' </span>' . $item; } return '<span class="file">' . l($item, $url, $options) . '</span>'; } /** * Helper to determine if the demo content should be dislayed. */ Loading