Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Download the latest version of Jethro from the [releases page](https://github.co
System requirements are:
* Some kind of web server (apache/ngnix etc)
* MySQL 8.0 or above
* with [ONLY_FULL_GROUP_BY](https://dev.mysql.com/doc/refman/8.4/en/sql-mode.html#sqlmode_only_full_group_by) disabled
* PHP 7.0 or above
* with [gettext extension](https://www.php.net/manual/en/book.gettext.php) enabled
* with [zip extension](https://www.php.net/manual/en/book.zip.php) enabled
Expand Down
44 changes: 18 additions & 26 deletions db_objects/person.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,39 +504,31 @@ public static function getPersonsBySearch($searchTerm, $includeArchived=true)
{
$db = $GLOBALS['db'];
$SQL = '
SELECT pp.id, pp.*
FROM (
SELECT p.*
FROM person p
WHERE (
(first_name LIKE '.$db->quote($searchTerm.'%').')
OR (last_name LIKE '.$db->quote($searchTerm.'%').')
OR (first_name LIKE '.$db->quote('% '.$searchTerm.'%').')
OR (last_name LIKE '.$db->quote('% '.$searchTerm.'%').')
OR (CONCAT(first_name, " ", last_name) LIKE '.$db->quote($searchTerm.'%').')
)

UNION

SELECT p.*
FROM person p
JOIN custom_field_value cfv ON cfv.personid = p.id
JOIN custom_field cf ON cfv.fieldid = cf.id
WHERE cf.searchable
AND (
(cfv.value_text LIKE '.$db->quote($searchTerm.'%').')
OR (cfv.value_text LIKE '.$db->quote('% '.$searchTerm.'%').' )
SELECT p.*
FROM person p
JOIN person_status ps ON ps.id = p.status
LEFT JOIN custom_field_value cfv ON cfv.personid = p.id
LEFT JOIN custom_field cf ON cfv.fieldid = cf.id
WHERE (
(first_name LIKE '.$db->quote($searchTerm.'%').')
OR (last_name LIKE '.$db->quote($searchTerm.'%').')
OR (first_name LIKE '.$db->quote('% '.$searchTerm.'%').')
OR (last_name LIKE '.$db->quote('% '.$searchTerm.'%').')
OR (CONCAT(first_name, " ", last_name) LIKE '.$db->quote($searchTerm.'%').')
OR (
cf.searchable AND (
(cfv.value_text LIKE '.$db->quote($searchTerm.'%').')
OR (cfv.value_text LIKE '.$db->quote('% '.$searchTerm.'%').' )
)
)
) pp
JOIN person_status ps ON ps.id = pp.status
)
';
if (!$includeArchived) {
$SQL .= '
WHERE (NOT ps.is_archived)
AND NOT ps.is_archived
';
}
$SQL .= '
GROUP BY pp.id
ORDER BY status
';
$res = $db->queryAll($SQL, null, null, true, true); // 5th param forces array even if one col
Expand Down
25 changes: 14 additions & 11 deletions include/photo_handler.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ public static function getDataURL($type, $id)
public static function getPhotoData($type, $id)
{
$db = $GLOBALS['db'];
$SQL = $obj = NULL;
if ($type == 'person') {
$obj = $GLOBALS['system']->getDBObject('person', (int)$id);
if ($obj) {
Expand All @@ -138,25 +137,29 @@ public static function getPhotoData($type, $id)
LEFT JOIN family_photo fp ON fp.familyid = f.id
WHERE p.id = '.(int)$obj->id.'
GROUP BY p.id';
return $GLOBALS['db']->queryOne($SQL);
}
} else if ($type == 'family') {
$obj = $GLOBALS['system']->getDBObject('family', (int)$id);
if ($obj) {
// for single-member families, treat person photo as family photo if family photo is missing
$SQL = 'SELECT COALESCE(fp.photodata, IF(count(p.id) = 1, pp.photodata, NULL)) as photodata
$SQL = 'SELECT fp.photodata, IF(count(p.id) = 1, SUM(p.id), NULL) onlyPersonId
FROM family f
LEFT JOIN family_photo fp ON fp.familyid = f.id
LEFT JOIN person p ON p.familyid = f.id AND p.status NOT IN (SELECT id FROM person_status where is_archived)
LEFT JOIN person_photo pp ON pp.personid = p.id
WHERE f.id = '.(int)$obj->id.'
GROUP BY f.id';
}

}
if ($obj) {
$res = $GLOBALS['db']->queryOne($SQL);
if ($res) {
return $res;
$res = $GLOBALS['db']->queryRow($SQL);
if ($res) {
if ($res['photodata']) {
return $res['photodata'];
} else if ($res['onlyPersonId'] == 1) {
// for single-member families, treat person photo as family photo if family photo is missing
$SQL = 'SELECT photodata
FROM person_photo
WHERE personid = '.$res['onlyPersonId'];
return $GLOBALS['db']->queryOne($SQL);
}
}
}
}
}
Expand Down