-
Notifications
You must be signed in to change notification settings - Fork 9
Fejlretning og nye felter #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,13 +15,15 @@ function ding_availability_menu() { | |
| 'title' => 'Availability status', | ||
| 'page callback' => 'ding_availability_js', | ||
| 'access arguments' => array('access content'), | ||
| 'delivery callback' => 'ajax_deliver', | ||
| 'type' => MENU_CALLBACK, | ||
| ); | ||
|
|
||
| $items['ding_availability/holdings'] = array( | ||
| 'title' => 'Availability and holding status', | ||
| 'page callback' => 'ding_availability_holdings_js', | ||
| 'access arguments' => array('access content'), | ||
| 'delivery callback' => 'ajax_deliver', | ||
| 'type' => MENU_CALLBACK, | ||
| ); | ||
|
|
||
|
|
@@ -44,14 +46,62 @@ function ding_availability_ding_provider_user() { | |
| * | ||
| */ | ||
| function ding_availability_js($provider_ids) { | ||
| $data = $_POST['availability']; | ||
| drupal_json_output(ding_availability_items(explode(',', $provider_ids))); | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| function ding_availability_holdings_js($provider_ids) { | ||
| drupal_json_output(ding_availability_holdings(explode(',', $provider_ids))); | ||
| function ding_availability_holdings_js($provider_ids = NULL) { | ||
| $commands = array(); | ||
| $availability = $_POST['availability']; | ||
|
|
||
| $holdings = $_POST['holdings']; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the $_POST data sanitized ? |
||
| if(is_array($availability) && is_array($holdings)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If statements missing {} |
||
| $ids = array_merge($availability, $holdings); | ||
| else | ||
| $ids = is_array($availability) ? $availability : $holdings; | ||
| $data = ding_availability_holdings($ids); | ||
|
|
||
| if(is_array($availability)) { | ||
| // Set availability | ||
| foreach($availability as $html_id => $avid) { | ||
| if(isset($data[$avid])) { | ||
| $return = theme('ding_availability_status', array('availability' => $data[$avid])); | ||
| $commands[] = ajax_command_replace('#' . $html_id, $return); | ||
| } else { | ||
| $default_data = array( | ||
| 'local_id' => $avid, | ||
| 'available' => 0, | ||
| 'reservable' => 0, | ||
| 'show_reservation_button' => 0, | ||
| 'reserved_count' => 0, | ||
| 'deferred_period' => FALSE, | ||
| 'is_periodical' => 0, | ||
| 'is_internet' => TRUE, | ||
| 'status' => 'unavailable', | ||
| ); | ||
| $return = theme('ding_availability_status', array('availability' => $default_data)); | ||
| $commands[] = ajax_command_replace('#' . $html_id, $return); | ||
| } | ||
| } | ||
| } | ||
| if(is_array($holdings)) { | ||
| // Set holdings | ||
| foreach($holdings as $html_id => $avid) { | ||
| if(empty($data[$avid]) || !isset($data[$avid])) { | ||
| $data[$avid]['location']['holdings'][][] = t('Not provided'); | ||
| } | ||
| $return = theme('ding_availability_holdings', array('holdings' => $data[$avid])); | ||
| $commands[] = ajax_command_html('#' . $html_id, $return); | ||
| } | ||
| } | ||
|
|
||
| return array( | ||
| '#type' => 'ajax', | ||
| '#commands' => $commands, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -102,7 +152,10 @@ function ding_availability_holdings($provider_ids) { | |
| * Adds the human readable status text of an item. | ||
| */ | ||
| function _ding_availability_text(&$item) { | ||
| if ($item['available'] && $item['reservable']) { | ||
| if (isset($item['status']) && $item['status'] == 'inAcquisition') { | ||
| $item['status'] = t('in acquisition'); | ||
| } | ||
| elseif (($item['available'] && $item['reservable']) || $item['is_internet']) { | ||
| $item['status'] = t('available'); | ||
| } | ||
| elseif (!$item['available'] && $item['reservable']) { | ||
|
|
@@ -180,3 +233,18 @@ function ding_availability_preprocess_ting_object_entities(&$variables) { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Implements hook_theme | ||
| */ | ||
| function ding_availability_theme($existing, $type, $theme, $path) { | ||
| return array( | ||
| 'ding_availability_holdings' => array( | ||
| 'variables' => array('holdings' => array()), | ||
| 'file' => 'ding_availability.theme.inc', | ||
| ), | ||
| 'ding_availability_status' => array( | ||
| 'variables' => array('availability' => NULL), | ||
| 'file' => 'ding_availability.theme.inc', | ||
| ), | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| <?php | ||
|
|
||
|
|
||
| /** | ||
| * Preprocess ding_availability_holdings | ||
| */ | ||
| function template_preprocess_ding_availability_holdings(&$variables) { | ||
| $variables['content'] = array(); | ||
|
|
||
| $holdings = $variables['holdings']; | ||
| $variables['content']['title'] = array( | ||
| '#type' => 'markup', | ||
| '#markup' => '<h2>' . t('Position') . '</h2>', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a tpl should be used to make it easier to override the markup ? |
||
| ); | ||
| $items = array(); | ||
| if(isset($holdings['location'])) { | ||
| foreach($holdings['location']['holdings'] as $count => $location) { | ||
| $items[] = join(' → ', $location); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a note: Would it be possible to have the separate char as input parameter to the theme function ? |
||
| } | ||
| $variables['content']['location'] = array( | ||
| '#theme' => 'item_list', | ||
| '#items' => $items, | ||
| '#title' => '', | ||
| '#type' => 'ul', | ||
| '#attributes' => array( | ||
| 'class' => array(drupal_html_class('ding_availability_location')), | ||
| ), | ||
| ); | ||
| } | ||
| if(isset($holdings['holdings'])) { | ||
| $variables['content']['holdings'] = array( | ||
| '#type' => 'fieldset', | ||
| '#title' => t('View all holdings'), | ||
| '#collapsible' => TRUE, | ||
| '#collapsed' => FALSE, | ||
| '#attached' => array( | ||
| 'js' => array( | ||
| 'misc/form.js', | ||
| 'misc/collapse.js', | ||
| ), | ||
| ), | ||
| '#attributes' => array( | ||
| 'class' => array('collapsible', 'collapsed'), | ||
| ), | ||
| ); | ||
| $row = array(); | ||
| $row['data']['Library'] = t('Reservations'); | ||
| $row['data']['Copies'] = $variables['holdings']['reserved_count']; | ||
| $row['data']['Home'] = ''; | ||
| $row['data']['Reference'] = ''; | ||
| $row['data']['Checked_out'] = ''; | ||
| $row['class'] = array(drupal_html_class('availability_holdings_last_row')); | ||
| $holdings['holdings']['rows'][] = $row; | ||
|
|
||
| $variables['content']['holdings']['table'] = array( | ||
| '#theme' => 'table', | ||
| '#attributes' => $holdings['holdings']['attributes'], | ||
| '#header' => $holdings['holdings']['header'], | ||
| '#rows' => $holdings['holdings']['rows'], | ||
| ); | ||
| } | ||
| $variables['classes'] = ''; | ||
| $variables['classes_array'] = array(); | ||
| $variables['classes_array'][] = 'ding_availability_holdings'; | ||
| } | ||
|
|
||
| /** | ||
| * Theme ding_availability_holdings | ||
| */ | ||
| function theme_ding_availability_holdings(&$variables) { | ||
| return '<div class="' . $variables['classes'] . '">' . render($variables['content']) . '</div>'; | ||
| } | ||
|
|
||
| /** | ||
| * Preprocess ding_availability_status | ||
| */ | ||
| function template_preprocess_ding_availability_status(&$variables) { | ||
| $availability = $variables['availability']; | ||
| $variables['attributes']['title'] = $availability['status']; | ||
| if($availability['available']) { | ||
| $variables['attributes']['class'][] = 'available'; | ||
| } | ||
| if($availability['reservable']) { | ||
| $variables['attributes']['class'][] = 'reservable'; | ||
| } | ||
| if($availability['is_internet']) { | ||
| $variables['attributes']['class'][] = drupal_html_class('is_internet'); | ||
| } | ||
| if($availability['is_periodical']) { | ||
| $variables['attributes']['class'][] = drupal_html_class('is_periodical'); | ||
| } | ||
| $variables['data'] = t(ucfirst($availability['status'])); | ||
| $variables['classes_array'][] = 'ding_availability_status'; | ||
| } | ||
|
|
||
| /** | ||
| * Theme ding_availability_holdings | ||
| */ | ||
| function theme_ding_availability_status(&$variables) { | ||
| return '<li' . drupal_attributes($variables['attributes']) . '>' . $variables['data'] . "</li>"; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The $data variable is not used ?