You are here

function node_gallery_api_rules_gallery_set_cover in Node Gallery 7

Rules action for setting the cover item of a gallery.

Parameters

object $item_wrapper: Gallery Item

object $gallery_wrapper: Gallery, if null, will set cover for all galleries

1 string reference to 'node_gallery_api_rules_gallery_set_cover'
node_gallery_api_rules_action_info in ./node_gallery_api.rules.inc
Implements hook_rules_action_info().

File

./node_gallery_api.rules.inc, line 205
Rules module integration.

Code

function node_gallery_api_rules_gallery_set_cover($item_wrapper, $gallery_wrapper = NULL) {
  if (in_array($item_wrapper->type
    ->value(), node_gallery_api_get_types('item'))) {
    $gallery_nid = !empty($gallery_wrapper) ? $gallery_wrapper->nid
      ->value() : NULL;
    $relationships = node_gallery_api_get_relationships($gallery_nid, $item_wrapper->nid
      ->value());
    foreach ($relationships as $relationship) {
      if ($item_wrapper->nid
        ->value() != node_gallery_api_get_cover_nid($relationship->ngid)) {
        node_gallery_api_set_gallery_cover_item($item_wrapper->nid
          ->value(), $relationship->ngid);
      }
    }
  }
}