'Periodical issue information', 'page callback' => 'ding_periodical_issues_ajax', 'page arguments' => array(2), 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, ); // Ajax link reservation callback (with local_id, volume and issue). $items['ting/object/%ting_object/reserve/%/%/%'] = array( 'page callback' => 'ding_periodical_reserve_ajax', 'page arguments' => array(2, 4, 5, 6), 'delivery callback' => 'ajax_deliver', 'access arguments' => array('access content'), ); return $items; } /** * Ajax reservation callback. * * @param TingEntity $entity * Ting entity for the periodical. * @param string $local_id * Local library id (faust) for the issue (base64 encoded). * @param string $volume * Volume number (for year books the year, base64 encoded). * @param string $issue * The issue in the volume to reserve (base64_encoded). * * @return array * Render array with Ajax commands. */ function ding_periodical_reserve_ajax($entity, $local_id, $volume, $issue) { $reservable = new DingPeriodicalReservable(base64_decode($local_id), base64_decode($volume), base64_decode($issue), $entity); // Use ding reservation logic to create the reservation and ajax commands. return ding_reservation_reserve_ajax($entity, $reservable); } /** * Callback function that load holdings information for a periodical. * * The information returned is a HTML table JSON encoded. * * @param string $ding_entity_id * Ding entity id for the periodical. */ function ding_periodical_issues_ajax($ding_entity_id) { $output = array(); // Load the entity for the periodical. $entity = ding_entity_load($ding_entity_id); // Get availability. $availability = ding_provider_invoke('availability', 'holdings', array($entity->provider_id)); if (isset($availability[$entity->provider_id])) { $issues = $availability[$entity->provider_id]['issues']; krsort($issues); if ($issues) { $output = array( '#theme' => 'ding_periodical_issues', '#entity' => $entity, '#issues' => $issues, '#availability' => $availability, ); } } // Render the output to HTML an return it. drupal_json_output(array( 'html' => empty($output) ? '' : render($output), )); } /** * Implements hook_theme(). */ function ding_periodical_theme() { return array( 'ding_periodical_issues' => array( 'variables' => array( 'entity' => NULL, 'issues' => array(), 'availability' => array(), ), ), 'ding_periodical_issues_ajax' => array( 'variables' => array( 'ding_entity_id' => NULL, ), 'template' => 'ding-periodical-issues', ), ); } /** * Implements theme_ding_periodical_issues(). * * Create list of periodical issues order by year. */ function theme_ding_periodical_issues($variables) { $items = array(); foreach ($variables['issues'] as $volume => $issues) { $iss = array(); $i = 0; foreach ($issues as $key => $availability) { $issue = $key; $issue_id = $availability['local_id']; $normalized_id = md5($issue_id); // Build table with holding information for the current volume. $holding_data = ding_periodical_build_table($availability); // Check if the volume is reservable and add reservation button. if (!empty($issue_id) && ding_periodical_is_reservable($issues[$key])) { $item_id = array($issue_id, $volume, $key); $item_id = array_map('base64_encode', $item_id); $button = array( array( '#theme' => 'link', '#text' => t('Reserve'), '#path' => 'ting/object/' . $variables['entity']->id . '/reserve/' . implode('/', $item_id), '#options' => array( 'attributes' => array( 'class' => array( 'action-button', 'reserve-button', 'reservable', 'available', 'use-ajax', ), 'id' => 'reservation-' . $issue_id, ), 'html' => FALSE, ), ), ); // @todo This should first be render in the template layer. $holding_data .= drupal_render($button); } $holdings = array( array( 'data' => '