Where would I start for a module which moves items by tag?

mattdm

Joined: 2005-07-22
Posts: 181
Posted: Mon, 2012-08-06 20:39

I'd like to make a module which moves items with a given tag from the current album to another chosen album.

Ideally, it'd have the option to copy in addition to moving. More complicated selection (and and or tags) would be a further feature.

I don't see any similar modules; what would be a good starting point for this? Would it be better to hack the organizer module popup, or start from scratch?

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Wed, 2012-09-12 23:59

On the server side it's pretty easy to move the instances. The code would look something like this (off the top of my head):

// Walk the album
foreach ($album->children() as $child) {
  // Walk the item's tags
  foreach (tag::item_tags($child) as $tag) {
    if ($tag->name == "THE TAG I CARE ABOUT") {
      // Move the item
      $child->parent_id = $new_parent_album_id;
      $child->save();
  }
}

For a simple UI to get started, you'd need an album picker of some kind.. can't think if we have one of those offhand, but you could bastardize one of the album tree modules to get that. And you'd need a tag autocomplete box, which you can crib from the tag sidebar block. Combine those into a dialog and put it in the context menu for your current album and you're good to go.

This is an N^2 walk in PHP so it's slow, but for small data sets it'll be plenty fast enough. For a more efficient solution you'd want to do a single query that joins the item and the items tags tables to find just the items you care about.
---
Problems? Check gallery3/var/logs
file a bug/feature ticket | upgrade to the latest code! | hacking G3? join us on IRC!

 
bharat
bharat's picture

Joined: 2002-05-21
Posts: 7994
Posted: Wed, 2012-09-12 23:59

PS: while investigating this, I found a bug in organize (https://sourceforge.net/apps/trac/gallery/ticket/1914) - thanks for the prod.
---
Problems? Check gallery3/var/logs
file a bug/feature ticket | upgrade to the latest code! | hacking G3? join us on IRC!