Skip to content

Commit

Permalink
adding concurrency settings to resource import/export
Browse files Browse the repository at this point in the history
  • Loading branch information
nkorbel committed Aug 5, 2020
1 parent 9b465d6 commit 24a10fa
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 51 deletions.
1 change: 1 addition & 0 deletions Presenters/Admin/ManageResourcesPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,7 @@ public function ImportResource()
$resource->SetCheckin($row->checkIn, $row->autoreleaseMinutes);
$resource->SetCreditsPerSlot($row->credits);
$resource->SetPeakCreditsPerSlot($row->creditsPeak);
$resource->SetMaxConcurrentReservations($row->maximumConcurrent);

foreach ($row->attributes as $label => $value) {
if (empty($value)) {
Expand Down
1 change: 1 addition & 0 deletions lang/en_us.php
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,7 @@ protected function _LoadStrings()
$strings['AllowConcurrentReservations'] = 'Allow concurrent reservations';
$strings['ResourceDisplayInstructions'] = 'No resource has been selected. You can find the URL to display a resource in Application Management, Resources. The resource must be publicly accessible.';
$strings['Owner'] = 'Owner';
$strings['MaximumConcurrentReservations'] = 'Maximum Concurrent Reservations';
// End Strings

// Install
Expand Down
3 changes: 3 additions & 0 deletions lib/Application/Admin/ResourceImportCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ResourceImportCsvRow
public $autoreleaseMinutes;
public $credits;
public $creditsPeak;
public $maximumConcurrent;
public $attributes = array();

private $values = array();
Expand Down Expand Up @@ -89,6 +90,7 @@ public function __construct($values, $indexes, $attributes)
$this->autoreleaseMinutes = $this->valueOrDefault('autoreleaseMinutes');
$this->credits = $this->valueOrDefault('credits');
$this->creditsPeak = $this->valueOrDefault('creditsPeak');
$this->maximumConcurrent = $this->valueOrDefault('concurrentReservations');

foreach ($attributes as $label => $attribute)
{
Expand Down Expand Up @@ -145,6 +147,7 @@ public static function GetHeaders($values, $attributes)
$indexes['autoreleaseMinutes'] = self::indexOrFalse('autorelease minutes', $values);
$indexes['credits'] = self::indexOrFalse('credits (off peak)', $values);
$indexes['creditsPeak'] = self::indexOrFalse('credits (peak)', $values);
$indexes['concurrentReservations'] = self::indexOrFalse('maximum concurrent reservations', $values);

foreach ($attributes as $label => $attribute)
{
Expand Down
114 changes: 66 additions & 48 deletions lib/Common/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,35 +109,35 @@ public static function ParseExact($dateString)
return NullDate::Instance();
}

/*
* This wasn't producing correct results.
* Parameter $datestring is provided in ISO 8601 format and therefore has the correct timezone
* This then needs to be converted to UTC.
*
$offset = '';
$strLen = strlen($dateString);
$hourAdjustment = 0;
$minuteAdjustment = 0;
if ($strLen > 5)
{
$offset = substr($dateString, -5);
$hourAdjustment = substr($offset, 1, 2);
$minuteAdjustment = substr($offset, 3, 2);
}
if (BookedStringHelper::Contains($offset, '+'))
{
$hourAdjustment *= -1;
$minuteAdjustment *= -1;
}
$parsed = date_parse($dateString);
$d = Date::Create($parsed['year'], $parsed['month'], $parsed['day'], $parsed['hour'] + $hourAdjustment, $parsed['minute'] + $minuteAdjustment, $parsed['second'], 'UTC');
*/
$dt = new DateTime($dateString);
$utc = $dt->setTimezone(new DateTimeZone('UTC'));
/*
* This wasn't producing correct results.
* Parameter $datestring is provided in ISO 8601 format and therefore has the correct timezone
* This then needs to be converted to UTC.
*
$offset = '';
$strLen = strlen($dateString);
$hourAdjustment = 0;
$minuteAdjustment = 0;
if ($strLen > 5)
{
$offset = substr($dateString, -5);
$hourAdjustment = substr($offset, 1, 2);
$minuteAdjustment = substr($offset, 3, 2);
}
if (BookedStringHelper::Contains($offset, '+'))
{
$hourAdjustment *= -1;
$minuteAdjustment *= -1;
}
$parsed = date_parse($dateString);
$d = Date::Create($parsed['year'], $parsed['month'], $parsed['day'], $parsed['hour'] + $hourAdjustment, $parsed['minute'] + $minuteAdjustment, $parsed['second'], 'UTC');
*/

$dt = new DateTime($dateString);
$utc = $dt->setTimezone(new DateTimeZone('UTC'));

$d = Date::Create($utc->format('Y'), $utc->format('m'), $utc->format('d'), $utc->format('H'), $utc->format('i'), $utc->format('s'), 'UTC');

Expand Down Expand Up @@ -801,24 +801,24 @@ public function Compare(Date $date)
}

public function LessThan(Date $end)
{
return false;
}

public function GreaterThan(Date $end)
{
return false;
}

public function Timestamp()
{
return 0;
}

public function ToIso()
{
return '';
}
{
return false;
}

public function GreaterThan(Date $end)
{
return false;
}

public function Timestamp()
{
return 0;
}

public function ToIso()
{
return '';
}
}

class DateDiff
Expand Down Expand Up @@ -1013,7 +1013,7 @@ public function GreaterThan(DateDiff $diff)
return $this->seconds > $diff->seconds;
}

/**
/**
* @param DateDiff $diff
* @return bool
*/
Expand All @@ -1030,6 +1030,24 @@ public function Invert()
return new DateDiff($this->seconds * -1);
}

/**
* @param false $short
* @return string
*/
public function ToString($short = false)
{
if ($short)
{
if ($this->TotalSeconds() > 0)
{
return $this->Days() . 'd' . $this->Hours() . 'h' . $this->Minutes() . 'm';
}
return '';
}

return $this->__toString();
}

/**
* @return string
*/
Expand Down
18 changes: 18 additions & 0 deletions lib/Common/TimeInterval.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* You should have received a copy of the GNU General Public License
* along with Booked Scheduler. If not, see <http://www.gnu.org/licenses/>.
*/

class TimeInterval
{
/**
Expand Down Expand Up @@ -181,6 +182,23 @@ public function __toString()
return '';
}

/**
* @return string
*/
public function ToShortString()
{
if ($this->interval != null)
{
return $this->interval->ToString(true);
}

return '';
}

/**
* @param bool $includeTotalHours
* @return string
*/
public function ToString($includeTotalHours)
{
if ($includeTotalHours)
Expand Down
2 changes: 1 addition & 1 deletion tpl/Admin/Resources/import_resource_template_csv.tpl
Original file line number Diff line number Diff line change
@@ -1 +1 @@
name,status,schedule,resource type,sort order,location,contact,description,notes,resource administrator,resource color,reservation minimum length,reservation maximum length,buffer time,reservations can be made across days,resource groups,permission is automatically granted,reservations must be approved,capacity{foreach from=$attributes item=attribute},{$attribute->Label()|escape:'quotes'}{/foreach}
name,status,schedule,resource type,sort order,location,contact,description,notes,resource administrator,resource color,reservation minimum length,reservation maximum length,buffer time,reservations can be made across days,resource groups,permission is automatically granted,reservations must be approved,capacity,requires check in/out,autorelease minutes,credits (off peak),credits (peak),maximum concurrent reservations{foreach from=$attributes item=attribute},{$attribute->Label()|escape:'quotes'}{/foreach}
2 changes: 1 addition & 1 deletion tpl/Admin/Resources/manage_resources.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ along with Booked Scheduler. If not, see <http://www.gnu.org/licenses/>.
<label for="resourceAdminGroupId">{translate key='ResourceAdministrator'}</label>
<select class="form-control" {formname key=RESOURCE_ADMIN_GROUP_ID}
id="resourceAdminGroupId">
<option value="">{translate key=None}</option>
{if $CanViewAdmin}<option value="">{translate key=None}</option>{/if}
{foreach from=$AdminGroups item=adminGroup}
<option value="{$adminGroup->Id}">{$adminGroup->Name}</option>
{/foreach}
Expand Down
2 changes: 1 addition & 1 deletion tpl/Admin/Resources/resources_csv.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"{translate key='Name'}","{translate key='Status'}","{translate key='Schedule'}","{translate key='ResourceType'}","{translate key='SortOrder'}","{translate key='Location'}","{translate key='Contact'}","{translate key='Description'}","{translate key='Notes'}","{translate key='ResourceAdministrator'}","{translate key='ResourceColor'}","{translate key='ResourceMinLengthCsv'}","{translate key='ResourceMaxLengthCsv'}","{translate key='ResourceBufferTimeCsv'}","{translate key='ResourceAllowMultiDay'}","{translate key='Capacity'}","{translate key='ResourceGroups'}","{translate key='ResourceMinNoticeAddCsv'}","{translate key='ResourceMinNoticeUpdateCsv'}","{translate key='ResourceMinNoticeDeleteCsv'}","{translate key='ResourceMaxNotice'}","{translate key='ResourceRequiresApproval'}","{translate key='ResourcePermissionAutoGranted'}","{translate key='RequiresCheckInNotification'}","{translate key='AutoReleaseMinutes'}","{translate key='CreditsOffPeak'}","{translate key='CreditsPeak'}"{foreach from=$AttributeList item=attr name=attributeLabels},"{$attr->Label()|escape:'quotes'}"{/foreach}
"{translate key='Name'}","{translate key='Status'}","{translate key='Schedule'}","{translate key='ResourceType'}","{translate key='SortOrder'}","{translate key='Location'}","{translate key='Contact'}","{translate key='Description'}","{translate key='Notes'}","{translate key='ResourceAdministrator'}","{translate key='ResourceColor'}","{translate key='ResourceMinLengthCsv'}","{translate key='ResourceMaxLengthCsv'}","{translate key='ResourceBufferTimeCsv'}","{translate key='ResourceAllowMultiDay'}","{translate key='Capacity'}","{translate key='ResourceGroups'}","{translate key='ResourceMinNoticeAddCsv'}","{translate key='ResourceMinNoticeUpdateCsv'}","{translate key='ResourceMinNoticeDeleteCsv'}","{translate key='ResourceMaxNotice'}","{translate key='ResourceRequiresApproval'}","{translate key='ResourcePermissionAutoGranted'}","{translate key='RequiresCheckInNotification'}","{translate key='AutoReleaseMinutes'}","{translate key='CreditsOffPeak'}","{translate key='CreditsPeak'}","{translate key='MaximumConcurrentReservations'}{foreach from=$AttributeList item=attr name=attributeLabels},"{$attr->Label()|escape:'quotes'}"{/foreach}
{foreach from=$Resources item=resource}
"{$resource->GetName()|escape:'quotes'}","{if $resource->IsAvailable()}{translate key='Available'}{elseif $resource->IsUnavailable()}{translate key='Unavailable'}{else}{translate key='Hidden'}{/if}","{$Schedules[$resource->GetScheduleId()]}","{if $resource->HasResourceType()}{($ResourceTypes[$resource->GetResourceTypeId()]->Name())|escape:'quotes'}{/if}",{$resource->GetSortOrder()|default:"0"},"{$resource->GetLocation()|escape:'quotes'}","{$resource->GetContact()|escape:'quotes'}","{$resource->GetDescription()|escape:'quotes'}","{$resource->GetNotes()|escape:'quotes'}","{($GroupLookup[$resource->GetAdminGroupId()]->Name)|escape:'quotes'}","{$resource->GetColor()}","{$resource->GetMinLength()}","{$resource->GetMaxLength()}","{$resource->GetBufferTime()}","{$resource->GetAllowMultiday()|default:0}","{$resource->GetMaxParticipants()}","{foreach from=$resource->GetResourceGroupIds() item=resourceGroupId name=eachGroup}{($ResourceGroupList[$resourceGroupId]->name)|escape:'quotes'}{if !$smarty.foreach.eachGroup.last},{/if}{/foreach}","{$resource->GetMinNoticeAdd()}","{$resource->GetMinNoticeUpdate()}","{$resource->GetMinNoticeDelete()}","{$resource->GetMaxNotice()}","{$resource->GetRequiresApproval()|default:0}","{$resource->GetAutoAssign()|default:0}","{$resource->IsCheckInEnabled()|default:0}","{$resource->GetAutoReleaseMinutes()}","{$resource->GetCreditsPerSlot()}","{$resource->GetPeakCreditsPerSlot()}"{foreach from=$AttributeList item=attribute name=attributeLoop},"{$resource->GetAttributeValue($attribute->Id())|escape:'quotes'}"{/foreach}
{/foreach}

0 comments on commit 24a10fa

Please sign in to comment.