Skip to content

Commit

Permalink
Merge commit 'bcacf1ecc4ae954a6b8000ec42c751cd8f066838' into dev
Browse files Browse the repository at this point in the history
* commit 'bcacf1ecc4ae954a6b8000ec42c751cd8f066838':
  More flexible matching #92
  Added sorting atributes #93
  • Loading branch information
debokshi committed Dec 18, 2024
2 parents aad4cc8 + bcacf1e commit 4cb7480
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 24 deletions.
4 changes: 4 additions & 0 deletions faudir-block/build/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
"showPosts": {
"type": "boolean",
"default": false
},
"sort": {
"type": "string",
"default": "last_name"
}
},
"textdomain": "rrze-faudir",
Expand Down
2 changes: 1 addition & 1 deletion faudir-block/build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-server-side-render'), 'version' => '13b6ab4781c7247da846');
<?php return array('dependencies' => array('react-jsx-runtime', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-element', 'wp-i18n', 'wp-server-side-render'), 'version' => 'f5862cb9b9c365d68754');
2 changes: 1 addition & 1 deletion faudir-block/build/index.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions faudir-block/src/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
"showPosts": {
"type": "boolean",
"default": false
},
"sort": {
"type": "string",
"default": "last_name"
}
},
"textdomain": "rrze-faudir",
Expand Down
30 changes: 26 additions & 4 deletions faudir-block/src/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function Edit({ attributes, setAttributes }) {
url = '',
buttonText = '',
hideFields = [],
sort = 'last_name',
} = attributes;

const availableFields = {
Expand Down Expand Up @@ -319,7 +320,13 @@ export default function Edit({ attributes, setAttributes }) {
setKey(prev => prev + 1);
}, 300); // 300ms debounce
return () => clearTimeout(timer);
}, [attributes]);
}, [...Object.values(attributes), sort]); // Add sort to the dependency array

// Also update the renderKey when sort changes
const handleSortChange = (value) => {
setAttributes({ sort: value });
setRenderKey(prev => prev + 1); // Force re-render
};

// Add debug output to the rendered component
return (
Expand Down Expand Up @@ -463,6 +470,18 @@ export default function Edit({ attributes, setAttributes }) {
placeholder={defaultButtonText}
/>
)}
<SelectControl
label={__('Sort by', 'rrze-faudir')}
value={sort}
options={[
{ value: 'last_name', label: __('Last Name', 'rrze-faudir') },
{ value: 'title_last_name', label: __('Title and Last Name', 'rrze-faudir') },
{ value: 'function_head', label: __('Head of Department First', 'rrze-faudir') },
{ value: 'function_proffesor', label: __('Professors First', 'rrze-faudir') },
{ value: 'identifier_order', label: __('Identifier Order', 'rrze-faudir') },
]}
onChange={handleSortChange} // Use the new handler instead of direct setAttributes
/>
</PanelBody>
</InspectorControls>
<div {...blockProps}>
Expand All @@ -480,7 +499,8 @@ export default function Edit({ attributes, setAttributes }) {
selectedFormat: attributes.selectedFormat,
selectedFields: attributes.selectedFields,
buttonText: attributes.buttonText,
url: attributes.url
url: attributes.url,
sort: attributes.sort
} :
// Case 2: category
attributes.selectedCategory ? {
Expand All @@ -489,7 +509,8 @@ export default function Edit({ attributes, setAttributes }) {
selectedFields: attributes.selectedFields,
buttonText: attributes.buttonText,
url: attributes.url,
groupId: attributes.groupId
groupId: attributes.groupId,
sort: attributes.sort
} :
// Case 3: selectedPersonIds
{
Expand All @@ -498,7 +519,8 @@ export default function Edit({ attributes, setAttributes }) {
selectedFormat: attributes.selectedFormat,
buttonText: attributes.buttonText,
url: attributes.url,
groupId: attributes.groupId
groupId: attributes.groupId,
sort: attributes.sort
})
}}
/>
Expand Down
45 changes: 27 additions & 18 deletions includes/shortcodes/fau_dir_shortcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,32 +308,41 @@ function fetch_and_render_fau_data($atts)
$orgData = fetch_fau_organizations(0, 0, ['lq' => 'disambiguatingDescription[eq]=' . urlencode($orgnr)]);
if (!empty($orgData['data'])) {
$orgIdentifier = $orgData['data'][0]['identifier'];
error_log("Found organization: " . $orgIdentifier);

// Try English function label first
$lq_en = 'contacts.organization.identifier[eq]=' . urlencode($orgIdentifier) .
'&contacts.functionLabel.en[eq]=' . urlencode($function);
$persons = fetch_and_process_persons($lq_en);
// Fetch all persons for this organization first
$lq = 'contacts.organization.identifier[eq]=' . urlencode($orgIdentifier);
$persons = fetch_and_process_persons($lq);

// If no results, try German function label
if (empty($persons)) {
$lq_de = 'contacts.organization.identifier[eq]=' . urlencode($orgIdentifier) .
'&contacts.functionLabel.de[eq]=' . urlencode($function);
$persons = fetch_and_process_persons($lq_de);
}

// Additional filter to ensure function matches for the specific organization
error_log("Total persons found for org: " . count($persons));

// Filter by function with more flexible matching
$persons = array_filter($persons, function($person) use ($function, $orgIdentifier) {
foreach ($person['contacts'] as $contact) {
if ($contact['organization']['identifier'] === $orgIdentifier &&
((isset($contact['functionLabel']['en']) &&
$contact['functionLabel']['en'] === $function) ||
(isset($contact['functionLabel']['de']) &&
$contact['functionLabel']['de'] === $function))) {
return true;
if ($contact['organization']['identifier'] === $orgIdentifier) {
// Log the function labels we're comparing
error_log("Comparing - Required: " . $function);
error_log("Found EN: " . ($contact['functionLabel']['en'] ?? 'none'));
error_log("Found DE: " . ($contact['functionLabel']['de'] ?? 'none'));

// More flexible matching including partial matches
$en_label = strtolower($contact['functionLabel']['en'] ?? '');
$de_label = strtolower($contact['functionLabel']['de'] ?? '');
$search_function = strtolower($function);

// Check for exact or partial matches
if (strpos($en_label, $search_function) !== false ||
strpos($de_label, $search_function) !== false ||
strpos($search_function, $en_label) !== false ||
strpos($search_function, $de_label) !== false) {
return true;
}
}
}
return false;
});

error_log("Filtered persons count: " . count($persons));
}
}
} elseif (!empty($post_id) && empty($identifiers) && empty($category) && empty($groupid) && empty($orgnr)) {
Expand Down
5 changes: 5 additions & 0 deletions rrze-faudir.php
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,11 @@ function register_faudir_block() {
$shortcode_atts['url'] = $attributes['url'];
}

// Add sort parameter to shortcode attributes
if (!empty($attributes['sort'])) {
$shortcode_atts['sort'] = $attributes['sort'];
}

// Build shortcode string
$shortcode = '[faudir';
foreach ($shortcode_atts as $key => $value) {
Expand Down

0 comments on commit 4cb7480

Please sign in to comment.