function node_gallery_api_reset_cover_item in Node Gallery 7
Reset Gallery cover.
Parameters
int $ngid: Gallery NID
1 call to node_gallery_api_reset_cover_item()
- NodeGalleryBehaviorHandler::NodeGalleryRelationshipCrud in plugins/
entityreference/ behavior/ NodeGalleryBehaviorHandler.class.php - Create, update or delete Node Gallery relationships based on field values.
File
- ./
node_gallery_api.inc, line 879 - Node Gallery API function
Code
function node_gallery_api_reset_cover_item($ngid) {
$new_cover = db_query('SELECT nid FROM {node_gallery_relationship} WHERE ngid = :ngid LIMIT 1', array(
':ngid' => $ngid,
))
->fetchField();
if ($new_cover !== FALSE) {
$result = db_update('node_gallery_galleries')
->fields(array(
'cover_item' => $new_cover,
))
->condition('ngid', $ngid)
->execute();
}
else {
// Gallery is now empty, set cover to NULL.
db_update('node_gallery_galleries')
->fields(array(
'cover_item' => NULL,
))
->condition('ngid', $ngid)
->execute();
}
}