Announcement

  •  » Requests
  •  » Add the ability to set selected images as album thumbnails in batchman

#1 2022-01-13 17:38:42

Crythes
Member
2020-01-23
112

Add the ability to set selected images as album thumbnails in batchman

Hello/Hi/Greetings,

I sometimtes upload hundreds of albums at a time, and setting an album thumbnail for each one is incredibly unecessarily time consuming because it has to be done manually for each album. I decided that enough is enough and modified the batch_manager_global.php and  batch_manager_global.tpl files to add a new action called "Set as thumbnail for the parent album" in batch manager. The function sets each selected image as the thumbnail for its parent album.

Note that all changes are for Piwigo 11.4.0, as I still haven't migrated to 12.

In batch_manager_global.tpl I added this code to line 658:

Code:

<option value="make_thumbnail">{'Set as thumbnail for the parent album'|@translate}</option>

In batch_manager_global.php I added this code after line 420 (peace brotha):

Code:

else if ('make_thumbnail' == $action)
  {
  foreach($_POST['selection'] as $image_id) {
    $query = '
  SELECT category_id 
    FROM '.IMAGE_CATEGORY_TABLE.' WHERE image_id IN ('.$image_id.')';

    $testing2 = query2array($query);
    $category_ids[] = $testing2[0]['category_id'].",".$image_id;
  }

  foreach($category_ids as $category_id) {
  
  $album_id = explode(',', $category_id)[0];
  $image_id = explode(',', $category_id)[1];
    
    $query = '
    UPDATE '.CATEGORIES_TABLE.'
    SET representative_picture_id = '.$image_id.'
    WHERE id = '.$album_id.'';

    pwg_query($query);
  }

The use of

Code:

foreach

is disgusting, but with this code:

Code:

 $query = '
  SELECT category_id 
    FROM '.IMAGE_CATEGORY_TABLE.' WHERE image_id IN ('.implode(',',$_POST['selection']).')';
  
  $testing= query2array($query);

The order in which the category_ids are returned in the $tesing array is not in the same order as the values in implode(',',$_POST['selection']), and I don't know why. query2array is a custom piwigo function, maybe it automatically sorts values based on ascending order?

I am not a PHP programer at all, so this solution is just an example of what can work. Hopefully the Piwigo team will consider implementing something similar. It is also possible that this functionality exists and I just don't know about it.

Last edited by Crythes (2022-01-13 17:40:47)

Offline

 
  •  » Requests
  •  » Add the ability to set selected images as album thumbnails in batchman

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact