issue #2560 action select in the selection mode, show in gallery on several people

This commit is contained in:
Linty committed 2026-10-29 15:51:10 +01:00
1 parent ee12b22211
commit 3ea63014fd
9 files changed
+304 -84

No files matched your search

+86
View File
@@ -204,6 +204,92 @@ function edit_person(int $id, array $data)
return true;
}
/**
* Set the same values to several people, only the fields they can share.
* The edit_person event is triggered for each person, like in edit_person().
*
* @param int[] $person_ids
* @param array $data
* - bool is_visible (optional)
* - string source (optional)
* @return true|array ['code', 'error']
*/
function edit_people(array $person_ids, array $data)
{
$person_ids = array_values(array_unique($person_ids));
if (count($person_ids) == 0)
{
return array('code' => 403, 'error' => 'No person given.');
}
foreach ($person_ids as $person_id)
{
if (!preg_match('/^\d+$/', $person_id))
{
return array('code' => 403, 'error' => 'Person ids must be digits.');
}
}
$validated_data = array();
if (isset($data['is_visible']))
{
if (!is_bool($data['is_visible']))
{
return array('code' => 403, 'error' => 'is_visible must be: true or false.');
}
$validated_data['is_visible'] = boolean_to_string($data['is_visible']);
}
if (!empty($data['source']))
{
if (!validate_people_source($data['source']))
{
return array('code' => 403, 'error' => 'source must be: manual, auto or imported.');
}
$validated_data['source'] = $data['source'];
}
$query_people = '
SELECT *
FROM '.PERSONS_TABLE.'
WHERE id IN ('.implode(',', $person_ids).')
;';
$people_before = query2array($query_people, 'id');
if (count($people_before) != count($person_ids))
{
return array('code' => 404, 'error' => 'Person not found.');
}
if (count($validated_data) == 0)
{
return true;
}
$set = array();
foreach ($validated_data as $field => $value)
{
$set[] = $field.' = \''.$value.'\'';
}
$query = '
UPDATE '.PERSONS_TABLE.'
SET '.implode(', ', $set).'
WHERE id IN ('.implode(',', $person_ids).')
;';
pwg_query($query);
pwg_activity('people', $person_ids, 'edit');
foreach (query2array($query_people, 'id') as $person_id => $person)
{
trigger_notify('edit_person', $person, $people_before[$person_id]);
}
return true;
}
/**
* @param int[]|int $people_ids
* @return bool
+20 -3
View File
@@ -221,8 +221,25 @@ function ws_people_edit($params, &$service)
{
return new PwgError(403, 'Invalid security token');
}
$is_edited = edit_person($params['person_id'], $params);
$person_ids = array_values(array_unique($params['person_id']));
if (count($person_ids) == 1)
{
$is_edited = edit_person($person_ids[0], $params);
}
else
{
foreach (array('name', 'user_id', 'cover_image_person_id') as $field)
{
if (isset($params[$field]))
{
return new PwgError(WS_ERR_INVALID_PARAM, $field.' can only be set for one person.');
}
}
$is_edited = edit_people($person_ids, $params);
}
if (isset($is_edited['error']))
{
@@ -230,7 +247,7 @@ function ws_people_edit($params, &$service)
}
return array(
'id' => $params['person_id'],
'id' => $person_ids,
);
}