Replace update/delete with Term::insertFramTagFieldByItemId + Code Standards + Wording
This commit is contained in:
parent
e022bac339
commit
b03050c339
|
@ -1419,12 +1419,13 @@ function photos_content(App $a)
|
|||
// parse tags and add links
|
||||
$tag_arr = [];
|
||||
foreach ($arr as $tag) {
|
||||
array_push($tag_arr, ['name' => BBCode::convert($tag), 'removeurl' => '/tagrm/'.$link_item['id'] . '/' . bin2hex($tag)]);
|
||||
array_push($tag_arr, ['name' => BBCode::convert($tag),
|
||||
'removeurl' => '/tagrm/'.$link_item['id'] . '/' . bin2hex($tag)]);
|
||||
}
|
||||
$tags = ['title' => L10n::t('Tags: '), 'tags' => $tag_arr];
|
||||
if ($cmd === 'edit') {
|
||||
$tags += ['removeanyurl' => 'tagrm/' . $link_item['id']];
|
||||
$tags += ['removetitle' => L10n::t('[Remove any tag]')];
|
||||
$tags += ['removetitle' => L10n::t('[Select tags to remove]')];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,8 +29,6 @@ function tagrm_post(App $a)
|
|||
$item_id = defaults($_POST,'item', 0);
|
||||
update_tags($item_id, $tags);
|
||||
|
||||
info(L10n::t('Tag(s) removed') . EOL );
|
||||
|
||||
$a->internalRedirect($_SESSION['photo_return']);
|
||||
|
||||
// NOTREACHED
|
||||
|
@ -43,12 +41,12 @@ function tagrm_post(App $a)
|
|||
*/
|
||||
function update_tags($item_id, $tags){
|
||||
if (empty($item_id) || empty($tags)){
|
||||
$a->internalRedirect($_SESSION['photo_return']);
|
||||
return;
|
||||
}
|
||||
|
||||
$item = Item::selectFirst(['tag'], ['id' => $item_id, 'uid' => local_user()]);
|
||||
if (!DBA::isResult($item)) {
|
||||
$a->internalRedirect($_SESSION['photo_return']);
|
||||
return;
|
||||
}
|
||||
|
||||
$old_tags = explode(',', $item['tag']);
|
||||
|
@ -63,12 +61,7 @@ function update_tags($item_id, $tags){
|
|||
}
|
||||
|
||||
$tag_str = implode(',',$old_tags);
|
||||
if(!empty($tag_str)) {
|
||||
Item::update(['tag' => $tag_str], ['id' => $item_id]);
|
||||
}
|
||||
else {
|
||||
Term::deleteByItemId($item_id);
|
||||
}
|
||||
Term::insertFromTagFieldByItemId($item_id, $tag_str);
|
||||
|
||||
info(L10n::t('Tag(s) removed') . EOL );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue