fix: 修复加入我们-结果查询的条目无法被正确查询的问题
This commit is contained in:
@@ -568,30 +568,27 @@ function itstudio_join_parse_result_rows_to_records($rows) {
|
||||
$records = array();
|
||||
|
||||
$is_header_row = static function ($name, $qq, $email, $student_id, $phone, $passed_raw) {
|
||||
$joined = implode(',', array($name, $qq, $email, $student_id, $phone, $passed_raw));
|
||||
$joined = preg_replace('/^\xEF\xBB\xBF/', '', (string) $joined);
|
||||
$joined = preg_replace('/\s+/u', '', (string) $joined);
|
||||
$joined_lower = function_exists('mb_strtolower') ? mb_strtolower($joined, 'UTF-8') : strtolower($joined);
|
||||
|
||||
$is_cn_header = (
|
||||
strpos($joined_lower, '姓名') !== false
|
||||
|| strpos($joined_lower, 'qq') !== false
|
||||
|| strpos($joined_lower, '邮箱') !== false
|
||||
|| strpos($joined_lower, '学号') !== false
|
||||
|| strpos($joined_lower, '手机') !== false
|
||||
|| strpos($joined_lower, '是否通过') !== false
|
||||
$normalize_header = static function ($value) {
|
||||
$value = preg_replace('/^\xEF\xBB\xBF/', '', trim((string) $value));
|
||||
$value = preg_replace('/[\s_-]+/u', '', (string) $value);
|
||||
return function_exists('mb_strtolower') ? mb_strtolower($value, 'UTF-8') : strtolower($value);
|
||||
};
|
||||
$values = array_map($normalize_header, array($name, $qq, $email, $student_id, $phone, $passed_raw));
|
||||
$header_names = array(
|
||||
array('姓名', 'name'),
|
||||
array('qq', 'qq号', 'qq号码'),
|
||||
array('邮箱', '电子邮箱', 'email'),
|
||||
array('学号', 'studentid', 'studentnumber'),
|
||||
array('手机', '手机号', '手机号码', '电话', 'phone'),
|
||||
array('是否通过', '通过', 'pass', 'passed'),
|
||||
);
|
||||
|
||||
$is_en_header = (
|
||||
strpos($joined_lower, 'name') !== false
|
||||
|| strpos($joined_lower, 'qq') !== false
|
||||
|| strpos($joined_lower, 'email') !== false
|
||||
|| strpos($joined_lower, 'student') !== false
|
||||
|| strpos($joined_lower, 'phone') !== false
|
||||
|| strpos($joined_lower, 'pass') !== false
|
||||
);
|
||||
|
||||
return $is_cn_header || $is_en_header;
|
||||
$matched_columns = 0;
|
||||
foreach ($values as $index => $value) {
|
||||
if ($value !== '' && in_array($value, $header_names[$index], true)) {
|
||||
$matched_columns++;
|
||||
}
|
||||
}
|
||||
return $matched_columns >= 2;
|
||||
};
|
||||
|
||||
foreach ($rows as $idx => $row) {
|
||||
@@ -599,7 +596,7 @@ function itstudio_join_parse_result_rows_to_records($rows) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$name = trim((string) ($row[0] ?? ''));
|
||||
$name = preg_replace('/^\xEF\xBB\xBF/', '', trim((string) ($row[0] ?? '')));
|
||||
$qq = trim((string) ($row[1] ?? ''));
|
||||
$email = trim((string) ($row[2] ?? ''));
|
||||
$student_id = trim((string) ($row[3] ?? ''));
|
||||
@@ -771,9 +768,38 @@ function itstudio_join_is_truthy_result_value($value) {
|
||||
), true);
|
||||
}
|
||||
|
||||
function itstudio_join_expand_progress_query_candidates($query) {
|
||||
$query = is_array($query) ? $query : array();
|
||||
$alternatives = isset($query['_alternatives']) && is_array($query['_alternatives']) ? $query['_alternatives'] : array();
|
||||
if (empty($alternatives)) {
|
||||
unset($query['_alternatives']);
|
||||
return array($query);
|
||||
}
|
||||
|
||||
$candidates = array();
|
||||
foreach ($alternatives as $candidate) {
|
||||
if (!is_array($candidate)) {
|
||||
continue;
|
||||
}
|
||||
unset($candidate['_alternatives']);
|
||||
$candidates[] = $candidate;
|
||||
}
|
||||
|
||||
return !empty($candidates) ? $candidates : array($query);
|
||||
}
|
||||
|
||||
function itstudio_join_find_formidable_entry_id_by_query($settings, $query) {
|
||||
$settings = is_array($settings) ? $settings : array();
|
||||
$query = is_array($query) ? $query : array();
|
||||
if (!empty($query['_alternatives'])) {
|
||||
foreach (itstudio_join_expand_progress_query_candidates($query) as $candidate) {
|
||||
$entry_id = itstudio_join_find_formidable_entry_id_by_query($settings, $candidate);
|
||||
if ($entry_id > 0) {
|
||||
return $entry_id;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (!class_exists('FrmEntry') || !class_exists('FrmEntryMeta')) {
|
||||
return 0;
|
||||
}
|
||||
@@ -917,6 +943,14 @@ function itstudio_join_formidable_stage_has_data($settings, $stage_key) {
|
||||
function itstudio_join_formidable_has_queryable_identity_field($settings, $query) {
|
||||
$settings = is_array($settings) ? $settings : array();
|
||||
$query = is_array($query) ? $query : array();
|
||||
if (!empty($query['_alternatives'])) {
|
||||
foreach (itstudio_join_expand_progress_query_candidates($query) as $candidate) {
|
||||
if (itstudio_join_formidable_has_queryable_identity_field($settings, $candidate)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
$form_id = itstudio_join_get_formidable_form_id($settings);
|
||||
if ($form_id <= 0) {
|
||||
return false;
|
||||
@@ -1000,6 +1034,7 @@ function itstudio_join_detect_progress_query_identity($raw_identity) {
|
||||
$detected = array(
|
||||
'raw' => $raw_identity,
|
||||
'field' => '',
|
||||
'fields' => array(),
|
||||
'value' => '',
|
||||
);
|
||||
|
||||
@@ -1010,6 +1045,7 @@ function itstudio_join_detect_progress_query_identity($raw_identity) {
|
||||
$email = sanitize_email($compacted);
|
||||
if ($email !== '' && is_email($email)) {
|
||||
$detected['field'] = 'email';
|
||||
$detected['fields'] = array('email');
|
||||
$detected['value'] = itstudio_join_normalize_lookup_value('email', $email);
|
||||
return $detected;
|
||||
}
|
||||
@@ -1020,19 +1056,19 @@ function itstudio_join_detect_progress_query_identity($raw_identity) {
|
||||
|
||||
if (preg_match('/^1[3-9]\d{9}$/', $digits)) {
|
||||
$detected['field'] = 'phone';
|
||||
$detected['fields'] = array('phone');
|
||||
$detected['value'] = itstudio_join_normalize_lookup_value('phone', $digits);
|
||||
return $detected;
|
||||
}
|
||||
|
||||
if ($len >= 10 && $len <= 12) {
|
||||
$detected['field'] = 'student_id';
|
||||
$detected['value'] = itstudio_join_normalize_lookup_value('student_id', $digits);
|
||||
return $detected;
|
||||
}
|
||||
|
||||
if ($len >= 5 && $len <= 12) {
|
||||
$detected['field'] = 'qq';
|
||||
$detected['value'] = itstudio_join_normalize_lookup_value('qq', $digits);
|
||||
if ($len <= 10) {
|
||||
$detected['fields'] = $len === 10 ? array('qq', 'student_id') : array('qq');
|
||||
} else {
|
||||
$detected['fields'] = array('student_id', 'qq');
|
||||
}
|
||||
$detected['field'] = $detected['fields'][0];
|
||||
$detected['value'] = itstudio_join_normalize_lookup_value($detected['field'], $digits);
|
||||
return $detected;
|
||||
}
|
||||
|
||||
@@ -1041,6 +1077,7 @@ function itstudio_join_detect_progress_query_identity($raw_identity) {
|
||||
|
||||
if (preg_match('/^[\x{4e00}-\x{9fff}·]{2,20}$/u', $compacted)) {
|
||||
$detected['field'] = 'name';
|
||||
$detected['fields'] = array('name');
|
||||
$detected['value'] = itstudio_join_normalize_lookup_value('name', $compacted);
|
||||
return $detected;
|
||||
}
|
||||
@@ -1119,6 +1156,14 @@ function itstudio_join_parse_result_records($raw) {
|
||||
function itstudio_join_record_matches_query($record, $query) {
|
||||
$record = is_array($record) ? $record : array();
|
||||
$query = is_array($query) ? $query : array();
|
||||
if (!empty($query['_alternatives'])) {
|
||||
foreach (itstudio_join_expand_progress_query_candidates($query) as $candidate) {
|
||||
if (itstudio_join_record_matches_query($record, $candidate)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
$has_any_query = false;
|
||||
|
||||
foreach (array('name', 'qq', 'email', 'student_id', 'phone') as $field) {
|
||||
@@ -1148,9 +1193,11 @@ function itstudio_join_find_record_in_stage_results($settings, $stage_key, $quer
|
||||
if (empty($records)) {
|
||||
return null;
|
||||
}
|
||||
foreach ($records as $record) {
|
||||
if (itstudio_join_record_matches_query($record, $query)) {
|
||||
return !empty($record['passed']);
|
||||
foreach (itstudio_join_expand_progress_query_candidates($query) as $candidate) {
|
||||
foreach ($records as $record) {
|
||||
if (itstudio_join_record_matches_query($record, $candidate)) {
|
||||
return !empty($record['passed']);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@@ -1188,9 +1235,11 @@ function itstudio_join_find_record_in_stage_results($settings, $stage_key, $quer
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($records as $record) {
|
||||
if (itstudio_join_record_matches_query($record, $query)) {
|
||||
return true;
|
||||
foreach (itstudio_join_expand_progress_query_candidates($query) as $candidate) {
|
||||
foreach ($records as $record) {
|
||||
if (itstudio_join_record_matches_query($record, $candidate)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1250,19 +1299,28 @@ function itstudio_join_resolve_progress_lookup($runtime = array(), $request_sour
|
||||
'student_id' => '',
|
||||
'phone' => '',
|
||||
);
|
||||
if ($detected_identity['field'] !== '') {
|
||||
$query[$detected_identity['field']] = (string) $detected_identity['value'];
|
||||
$detected_fields = isset($detected_identity['fields']) && is_array($detected_identity['fields']) ? $detected_identity['fields'] : array();
|
||||
if (count($detected_fields) === 1) {
|
||||
$query[$detected_fields[0]] = (string) $detected_identity['value'];
|
||||
} elseif (count($detected_fields) > 1) {
|
||||
$query['_alternatives'] = array();
|
||||
foreach ($detected_fields as $field) {
|
||||
$candidate = $query;
|
||||
unset($candidate['_alternatives']);
|
||||
$candidate[$field] = itstudio_join_normalize_lookup_value($field, $raw_identity);
|
||||
$query['_alternatives'][] = $candidate;
|
||||
}
|
||||
}
|
||||
|
||||
$has_input_value = trim((string) $raw_identity) !== '';
|
||||
$has_query_value = $detected_identity['field'] !== '';
|
||||
$has_query_value = !empty($detected_fields);
|
||||
|
||||
$submitted = isset($request_source['join_progress_lookup']) || $has_input_value;
|
||||
$response = array(
|
||||
'submitted' => $submitted,
|
||||
'has_query' => $has_query_value,
|
||||
'identity' => $raw_identity,
|
||||
'identity_field' => (string) ($detected_identity['field'] ?? ''),
|
||||
'identity_field' => implode('|', $detected_fields),
|
||||
'name' => $raw_name,
|
||||
'qq' => $raw_qq,
|
||||
'email' => $raw_email,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Plugin Name: ITStudio 招新系统
|
||||
* Plugin URI: https://git.itouc.cn/ITStudio_OUC/ITStudioMainSite
|
||||
* Description: ITStudio “加入我们”招新系统:招新文章标记、招新阶段时间状态机、录取进度查询(AJAX)、CSV/XLSX 结果解析、Formidable Forms 对接、以及后台“招新设置”页面。
|
||||
* Version: 1.0.0
|
||||
* Version: 1.0.2
|
||||
* Author: ITStudio OUC
|
||||
* Text Domain: itstudio-recruitment
|
||||
* Requires Plugins: itstudio-content
|
||||
|
||||
Reference in New Issue
Block a user