Skip to content

Commit

Permalink
Merge branch 'release' into core-pr-3
Browse files Browse the repository at this point in the history
  • Loading branch information
cableman committed May 16, 2013
2 parents 3fcb015 + d8fd9f2 commit 47a1945
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 31 deletions.
1 change: 1 addition & 0 deletions alma.features.field_base.inc
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ function alma_field_default_field_bases() {
60 => '2 months',
90 => '3 months',
180 => '6 months',
360 => '12 months'
),
'allowed_values_function' => '',
'profile2_private' => 0,
Expand Down
21 changes: 10 additions & 11 deletions alma.module
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,11 @@ function alma_settings_form() {
'#default_value' => variable_get('alma_base_url', ''),
);

$form['alma']['alma_pincode_length'] = array(
'#type' => 'textfield',
'#title' => t('Length of the pin code'),
'#default_value' => variable_get('alma_pincode_length', '4'),
'#description' => t('The different libraries uses different pin code lenght (defaults to four).'),
);
// Add the option to select default interest period, which default as default
// to 180 days.
$periods = alma_get_interest_periods();
$default = variable_get('alma_default_interest_period', 180);
$form['alma'] += ding_reservation_interest_period_selector('', 'alma_default_interest_period', $default, $periods);

$form['alma']['alma_enable_reservation_deletion'] = array(
'#type' => 'checkbox',
Expand Down Expand Up @@ -267,22 +266,22 @@ function alma_profile2_presave($entity) {
// Reservation pause
$value = $wrapper->field_alma_reservation_pause->value();
$start = is_null($value['value']) ? '' : $value['value'];
$start = str_replace('T00:00:00', '', $start);
$start = str_replace(' 00:00:00', '', $start);
$stop = is_null($value['value2']) ? '' : $value['value2'];
$stop = str_replace('T00:00:00', '', $stop);
$stop = str_replace(' 00:00:00', '', $stop);

$value = $wrapper_original->field_alma_reservation_pause->value();
$org_start = is_null($value['value']) ? '' : $value['value'];
$org_start = str_replace('T00:00:00', '', $org_start);
$org_start = str_replace(' 00:00:00', '', $org_start);
$org_stop = is_null($value['value2']) ? '' : $value['value2'];
$org_stop = str_replace('T00:00:00', '', $org_stop);
$org_stop = str_replace(' 00:00:00', '', $org_stop);

if ($start != $org_start || $stop != $org_stop) {
$changes['reservation_pause_start'] = $start;
$changes['reservation_pause_stop'] = $stop;

// Set absent id.
$wrapper->field_alma_absent_id->value();
$value = $wrapper->field_alma_absent_id->value();
$changes['absent_id'] = is_null($value) ? '' : $value;
}

Expand Down
75 changes: 56 additions & 19 deletions includes/alma.reservation.inc
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php
/**
* @file
* Handles reservation with alma.
* Handles reservation with Alma.
*/


/**
* @TODO: Document this function... provider hook ?
* Creates form with which can be used during reservation to select preferred
* branch and interest period.
*
* @param type $type
* @param type $account
Expand Down Expand Up @@ -40,6 +41,12 @@ function alma_reservation_options($type, $account, $reservables) {

/**
* Validate reservations options.
*
* @param type $type
* @param type $account
* @param type $reservables
* @param type $values
* @return type
*/
function alma_reservation_options_validate($type, $account, $reservables, $values) {
// Load profile2 profile.
Expand Down Expand Up @@ -69,6 +76,11 @@ function alma_reservation_options_validate($type, $account, $reservables, $value

/**
* Submit handler for reservations options.
*
* @param type $type
* @param type $account
* @param type $reservables
* @param type $values
*/
function alma_reservation_options_submit($type, $account, $reservables, $values) {
// Load profile2 profile.
Expand All @@ -89,9 +101,8 @@ function alma_reservation_options_submit($type, $account, $reservables, $values)
/**
* Set preferred pickup branch.
*
* @TODO: Is the branch format here correct and where is this function called
* from.
*
* @param type $account
* @param type $branch
*/
function alma_reservation_set_preferred_branch($account, $branch) {
// Throws an exception if we are not logged in.
Expand All @@ -103,9 +114,11 @@ function alma_reservation_set_preferred_branch($account, $branch) {

/**
* Get list of reserved items.
*
* @param type $account
* @return object DingProviderReservation
*/
function alma_reservation_list($account) {
$creds = ding_user_get_creds($account);
$reservations = alma_reservation_get_reservations($account);
$result = array();

Expand Down Expand Up @@ -148,8 +161,17 @@ function alma_reservation_list($account) {

/**
* Create a reservation for a given account.
*
* @param type $account
* @param type $id
* @param type $options
* @param type $expiry
* @return type
* @throws DingProviderReservationExists
* @throws DingProviderReservationNotAllowed
* @throws DingProviderReservationNotAvailable
*/
function alma_reservation_create($account, $id, $branch, $expiry = NULL) {
function alma_reservation_create($account, $id, $options = array(), $expiry = NULL) {
$creds = ding_user_get_creds($account);

// Check if the users has this reservation and throw exception.
Expand All @@ -166,27 +188,32 @@ function alma_reservation_create($account, $id, $branch, $expiry = NULL) {
// Use a metadata wrapper to access the data.
$interest_period = $wrapper->field_alma_interest_period->value();
if ($interest_period) {
$expiry = REQUEST_TIME + ($interest_period['key'] * 24 * 60 * 60);
// Change it to secounds from days.
$expiry = $interest_period * 86400;
}
}
if (!isset($expiry)) {
$expiry = REQUEST_TIME + DING_RESERVATION_DEFAULT_INTEREST_PERIOD;
// The user don't have a default interest period, so use the system wide
// one for alma (which default is 180 days).
$expiry = variable_get('alma_default_interest_period', 180) * 86400;
}

// preferred branch
if (empty($branch)) {
$branch = $wrapper->field_alma_preferred_branch->value();
// Preferred branch
$branch = $wrapper->field_alma_preferred_branch->value();
if (isset($options['alma_preferred_branch'])) {
$branch = $options['alma_preferred_branch'];
}
}

// Build the reservation parameters to send.
$params = array(
'id' => $id,
'valid_from' => date('Y-m-d'),
'valid_to' => alma_reservation_format_date($expiry),
'valid_to' => alma_reservation_format_date(time() + $expiry),
'pickup_branch' => $branch,
);

// Clear the local alma cache.
alma_reservation_clear_cache();

// Try to make the reservation.
Expand Down Expand Up @@ -215,6 +242,11 @@ function alma_reservation_create($account, $id, $branch, $expiry = NULL) {

/**
* Update order, by defining new expiry date or pickup branch.
*
* @param type $account
* @param type $ids
* @param type $options
* @return boolean
*/
function alma_reservation_update($account, $ids, $options) {
$creds = ding_user_get_creds($account);
Expand Down Expand Up @@ -246,6 +278,10 @@ function alma_reservation_update($account, $ids, $options) {

/**
* Delete a reservation for a given account.
*
* @param type $account
* @param type $id
* @return type
*/
function alma_reservation_delete($account, $id) {
$creds = ding_user_get_creds($account);
Expand Down Expand Up @@ -316,12 +352,13 @@ function alma_reservation_exists($account, $item_id) {
}

/**
* @TODO: add description.
* Helper function calculate the date in the feature base on interest period.
*
* @param type $datetime
* @return type
* @param int $expiry
* The number of secounds into the feature we need at date.
* @return string
* The date in the feature in the format 'Y-m-d'.
*/
function alma_reservation_format_date($datetime) {
$timestamp = (!is_int($datetime)) ? strtotime($datetime) : $datetime;
return date('Y-m-d', $timestamp);
function alma_reservation_format_date($expiry) {
return date('Y-m-d', $expiry);
}
2 changes: 1 addition & 1 deletion lib/AlmaClient/AlmaClient.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ public function add_reservation($borr_card, $pin_code, $reservation) {
'borrCard' => $borr_card,
'pinCode' => $pin_code,
'reservable' => $reservation['id'],
'reservationPickUpBranch' => $reservation['pickup_branch']['alma_preferred_branch'],
'reservationPickUpBranch' => $reservation['pickup_branch'],
'reservationValidFrom' => $reservation['valid_from'],
'reservationValidTo' => $reservation['valid_to'],
);
Expand Down

0 comments on commit 47a1945

Please sign in to comment.