Exemple #1
0
 /**
  * Returns a limited query based on page number and size
  * If nulls are passed for both $pageNumber, $pageSize then all results are returned
  *
  * @param SqlCommand $command
  * @param callback $listBuilder callback to for each row of results
  * @param int|null $pageNumber
  * @param int|null $pageSize
  * @param string|null $sortField
  * @param string|null $sortDirection
  * @return PageableData
  */
 public static function GetList($command, $listBuilder, $pageNumber = null, $pageSize = null, $sortField = null, $sortDirection = null)
 {
     $total = null;
     $totalCounter = 0;
     $results = array();
     $db = ServiceLocator::GetDatabase();
     $pageNumber = intval($pageNumber);
     $pageSize = intval($pageSize);
     if (empty($pageNumber) && empty($pageSize) || $pageSize == PageInfo::All) {
         $resultReader = $db->Query($command);
     } else {
         $totalReader = $db->Query(new CountCommand($command));
         if ($row = $totalReader->GetRow()) {
             $total = $row[ColumnNames::TOTAL];
         }
         $pageNumber = empty($pageNumber) ? 1 : $pageNumber;
         $pageSize = empty($pageSize) ? 1 : $pageSize;
         $resultReader = $db->LimitQuery($command, $pageSize, ($pageNumber - 1) * $pageSize);
     }
     while ($row = $resultReader->GetRow()) {
         $results[] = call_user_func($listBuilder, $row);
         $totalCounter++;
     }
     $resultReader->Free();
     return new PageableData($results, is_null($total) ? $totalCounter : $total, $pageNumber, $pageSize);
 }
 private function GetGroupAdminPermissions($userId)
 {
     $userCommand = new SelectUserGroupResourceAdminPermissions($userId);
     $reader = ServiceLocator::GetDatabase()->Query($userCommand);
     $resources = array();
     while ($row = $reader->GetRow()) {
         $resources[] = new ScheduleResource($row[ColumnNames::RESOURCE_ID], $row[ColumnNames::RESOURCE_NAME]);
     }
     return $resources;
 }
 /**
  * @param $userId int
  * @param $preferenceName string
  * @param $preferenceValue string
  * @return void
  */
 public function SetUserPreference($userId, $preferenceName, $preferenceValue)
 {
     $db = ServiceLocator::GetDatabase();
     $existingValue = self::GetUserPreference($userId, $preferenceName);
     if (is_null($existingValue)) {
         $db->ExecuteInsert(new AddUserPreferenceCommand($userId, $preferenceName, $preferenceValue));
     } else {
         if ($existingValue != $preferenceValue) {
             $db->Execute(new UpdateUserPreferenceCommand($userId, $preferenceName, $preferenceValue));
         }
     }
 }
 /**
  * @param $userId
  * @return array|ScheduleGroup[]
  */
 private function GetGroupPermissions($userId)
 {
     $groupCommand = new SelectUserGroupPermissions($userId);
     $reader = ServiceLocator::GetDatabase()->Query($groupCommand);
     $groupList = array();
     while ($row = $reader->GetRow()) {
         $group_id = $row[ColumnNames::GROUP_ID];
         $resourceId = $row[ColumnNames::RESOURCE_ID];
         $resourceName = $row[ColumnNames::RESOURCE_NAME];
         $groupList[$group_id][] = array($resourceId, $resourceName);
     }
     $groups = array();
     foreach ($groupList as $group_id => $resourceList) {
         $resources = array();
         foreach ($resourceList as $resourceItem) {
             $resources[] = new ScheduleResource($resourceItem[0], $resourceItem[1]);
         }
         $groups[] = new ScheduleGroup($group_id, $resources);
     }
     return $groups;
 }
Exemple #5
0
 public function Validate($username, $password)
 {
     if ($this->ShowUsernamePrompt() && empty($username) || $this->ShowPasswordPrompt() && empty($password)) {
         return false;
     }
     Log::Debug('Trying to log in as: %s', $username);
     $command = new AuthorizationCommand($username);
     $reader = ServiceLocator::GetDatabase()->Query($command);
     $valid = false;
     if ($row = $reader->GetRow()) {
         Log::Debug('User was found: %s', $username);
         $migration = $this->GetMigration();
         $password = $migration->Create($password, $row[ColumnNames::OLD_PASSWORD], $row[ColumnNames::PASSWORD]);
         $salt = $row[ColumnNames::SALT];
         if ($password->Validate($salt)) {
             $password->Migrate($row[ColumnNames::USER_ID]);
             $valid = true;
         }
     }
     Log::Debug('User: %s, was validated: %d', $username, $valid);
     return $valid;
 }
 public function RemoveResourceGroupPermission($resourceId, $groupId)
 {
     ServiceLocator::GetDatabase()->Execute(new DeleteGroupResourcePermission($groupId, $resourceId));
 }
 /**
  * @param Date $earliestDate
  * @param null $lastDate
  * @return NextReservationView[]
  */
 public function GetNextReservations(Date $earliestDate, $lastDate = null)
 {
     if ($lastDate == null) {
         $lastDate = new NullDate();
     }
     $command = new GetNextReservationsCommand($earliestDate, $lastDate);
     $result = ServiceLocator::GetDatabase()->Query($command);
     $reservations = array();
     while ($row = $result->GetRow()) {
         $reservations[$row[ColumnNames::RESOURCE_ID]] = NextReservationView::Populate($row);
     }
     $result->Free();
     return $reservations;
 }
 /**
  * @param Date $now
  * @param ReservationReminderType $reminderType
  * @return ReminderNotice[]|array
  */
 public function GetReminderNotices(Date $now, $reminderType)
 {
     $reader = ServiceLocator::GetDatabase()->Query(new GetReminderNoticesCommand($now->ToTheMinute(), $reminderType));
     $notices = array();
     while ($row = $reader->GetRow()) {
         $notices[] = ReminderNotice::FromRow($row);
     }
     $reader->Free();
     return $notices;
 }
Exemple #9
0
 /**
  * @param $roleLevel int|RoleLevel
  * @return GroupItemView[]|array
  */
 public function GetGroupsByRole($roleLevel)
 {
     $reader = ServiceLocator::GetDatabase()->Query(new GetAllGroupsByRoleCommand($roleLevel));
     $groups = array();
     while ($row = $reader->GetRow()) {
         $groups[] = GroupItemView::Create($row);
     }
     $reader->Free();
     return $groups;
 }
Exemple #10
0
 /**
  * @param BlackoutSeries $blackoutSeries
  */
 public function Update(BlackoutSeries $blackoutSeries)
 {
     if ($blackoutSeries->IsNew()) {
         $seriesId = $this->AddSeries($blackoutSeries);
         $db = ServiceLocator::GetDatabase();
         $start = $blackoutSeries->CurrentBlackout()->StartDate();
         $end = $blackoutSeries->CurrentBlackout()->EndDate();
         $db->Execute(new UpdateBlackoutInstanceCommand($blackoutSeries->CurrentBlackoutInstanceId(), $seriesId, $start, $end));
     } else {
         $this->DeleteSeries($blackoutSeries->CurrentBlackoutInstanceId());
         $this->Add($blackoutSeries);
     }
 }
Exemple #11
0
 /**
  * @param $quotaId
  * @return void
  */
 function DeleteById($quotaId)
 {
     //TODO:  Make this delete a quota instead of the id
     $command = new DeleteQuotaCommand($quotaId);
     ServiceLocator::GetDatabase()->Execute($command);
 }
Exemple #12
0
 public function UserExists($emailAddress, $userName)
 {
     $reader = ServiceLocator::GetDatabase()->Query(new CheckUserExistenceCommand($userName, $emailAddress));
     if ($row = $reader->GetRow()) {
         return $row[ColumnNames::USER_ID];
     }
     return null;
 }
Exemple #13
0
 public function AddScheduleLayout($scheduleId, ILayoutCreation $layout)
 {
     $db = ServiceLocator::GetDatabase();
     $timezone = $layout->Timezone();
     $addLayoutCommand = new AddLayoutCommand($timezone);
     $layoutId = $db->ExecuteInsert($addLayoutCommand);
     $days = array(null);
     if ($layout->UsesDailyLayouts()) {
         $days = DayOfWeek::Days();
     }
     foreach ($days as $day) {
         $slots = $layout->GetSlots($day);
         /* @var $slot LayoutPeriod */
         foreach ($slots as $slot) {
             $db->Execute(new AddLayoutTimeCommand($layoutId, $slot->Start, $slot->End, $slot->PeriodType, $slot->Label, $day));
         }
     }
     $db->Execute(new UpdateScheduleLayoutCommand($scheduleId, $layoutId));
     $db->Execute(new DeleteOrphanLayoutsCommand());
 }
 /**
  * @param int $accessoryId
  * @return void
  */
 public function Delete($accessoryId)
 {
     ServiceLocator::GetDatabase()->Execute(new DeleteAccessoryCommand($accessoryId));
 }
Exemple #15
0
You should have received a copy of the GNU General Public License
along with Booked Scheduler.  If not, see <http://www.gnu.org/licenses/>.
*/
define('ROOT_DIR', dirname(__FILE__) . '/../');
require_once ROOT_DIR . 'lib/Application/Reservation/namespace.php';
require_once ROOT_DIR . 'lib/Common/Helpers/namespace.php';
echo "<h1>Booked Scheduler Data Load</h1>";
$stopWatch = new StopWatch();
$stopWatch->Start();
$numberOfResources = 10;
$numberOfUsers = 1000;
$numberOfReservations = 5000;
$numberOfAccessories = 20;
$users = array();
$resources = array();
$db = ServiceLocator::GetDatabase();
// USERS
$db->Execute(new AdHocCommand("delete from users where fname ='load' and lname = 'test'"));
$userRepo = new UserRepository();
for ($i = 0; $i < $numberOfUsers; $i++) {
    $user = User::Create("load{$i}", "test{$i}", "email {$i}", "username {$i}", "en_us", "America/Chicago", "7b6aec38ff9b7650d64d0374194307bdde711425", "3b3dbb9b");
    $userId = $userRepo->Add($user);
    $users[] = $user;
}
echo "Loaded {$numberOfUsers} users<br/>";
// RESOURCES
$db->Execute(new AdHocCommand("delete from resources where name like 'load%'"));
$resourceRepo = new ResourceRepository();
for ($i = 0; $i < $numberOfResources; $i++) {
    $resource = BookableResource::CreateNew("load{$i}", 1);
    $resourceId = $resourceRepo->Add($resource);
 public function DeleteSavedReport($reportId, $userId)
 {
     ServiceLocator::GetDatabase()->Execute(new DeleteSavedReportCommand($reportId, $userId));
 }
 /**
  * @param $attributeId int
  * @return void
  */
 public function DeleteById($attributeId)
 {
     ServiceLocator::GetDatabase()->Execute(new DeleteAttributeCommand($attributeId));
     ServiceLocator::GetDatabase()->Execute(new DeleteAttributeValuesCommand($attributeId));
 }
Exemple #18
0
 private function AutoAssignPermissions($userId)
 {
     $autoAssignCommand = new AutoAssignPermissionsCommand($userId);
     ServiceLocator::GetDatabase()->Execute($autoAssignCommand);
 }
Exemple #19
0
 private function GetProgressCounts($legacyCountCommand, $migratedCountCommand)
 {
     $legacyCount = 0;
     $migratedCount = 0;
     $legacyDb = new Database($this->GetLegacyConnection());
     $reader = $legacyDb->Query($legacyCountCommand);
     if ($row = $reader->GetRow()) {
         $legacyCount = $row['count'];
     }
     $reader = ServiceLocator::GetDatabase()->Query($migratedCountCommand);
     if ($row = $reader->GetRow()) {
         $migratedCount = $row['count'];
     }
     return new ProgressCounts($legacyCount, $migratedCount);
 }
 public function Update(Announcement $announcement)
 {
     ServiceLocator::GetDatabase()->Execute(new UpdateAnnouncementCommand($announcement->Id(), $announcement->Text(), $announcement->Start(), $announcement->End(), $announcement->Priority()));
 }
Exemple #21
0
 public function Migrate($userid)
 {
     $salt = $this->Encryption->Salt();
     $encrypted = $this->Encryption->Encrypt($this->plaintext, $salt);
     ServiceLocator::GetDatabase()->Execute(new MigratePasswordCommand($userid, $encrypted, $salt));
     ServiceLocator::GetDatabase()->Execute(new RemoveLegacyPasswordCommand($userid));
 }
 public function __construct(SmartyPage $smarty)
 {
     parent::__construct($smarty);
     $this->presenter = new UpcomingReservationsPresenter($this, new ReservationViewRepository());
     $this->DBconn = ServiceLocator::GetDatabase();
 }
 public function GetBlackoutsWithin(DateRange $dateRange, $scheduleId = ReservationViewRepository::ALL_SCHEDULES)
 {
     $getBlackoutsCommand = new GetBlackoutListCommand($dateRange->GetBegin(), $dateRange->GetEnd(), $scheduleId);
     $result = ServiceLocator::GetDatabase()->Query($getBlackoutsCommand);
     $blackouts = array();
     while ($row = $result->GetRow()) {
         $blackouts[] = BlackoutItemView::Populate($row);
     }
     $result->Free();
     return $blackouts;
 }
Exemple #24
0
 public function RemoveStatusReason($reasonId)
 {
     ServiceLocator::GetDatabase()->Execute(new DeleteResourceStatusReasonCommand($reasonId));
 }
 /**
  * @param $attachmentFile ReservationAttachment
  * @return int
  */
 public function AddReservationAttachment(ReservationAttachment $attachmentFile)
 {
     $command = new AddReservationAttachmentCommand($attachmentFile->FileName(), $attachmentFile->FileType(), $attachmentFile->FileSize(), $attachmentFile->FileExtension(), $attachmentFile->SeriesId());
     $id = ServiceLocator::GetDatabase()->ExecuteInsert($command);
     $extension = $attachmentFile->FileExtension();
     $attachmentFile->WithFileId($id);
     $fileSystem = ServiceLocator::GetFileSystem();
     $fileSystem->Add($fileSystem->GetReservationAttachmentsPath(), "{$id}.{$extension}", $attachmentFile->FileContents());
     return $id;
 }
 private function ValidateCookie($loginCookie)
 {
     $valid = false;
     $reader = ServiceLocator::GetDatabase()->Query(new CookieLoginCommand($loginCookie->UserID));
     if ($row = $reader->GetRow()) {
         $valid = $row[ColumnNames::LAST_LOGIN] == $loginCookie->LastLogin;
     }
     return $valid ? $row[ColumnNames::EMAIL] : null;
 }
 public function Delete(WebServiceUserSession $session)
 {
     ServiceLocator::GetDatabase()->Execute(new DeleteUserSessionCommand($session->SessionToken));
 }
/**
Copyright 2011-2015 Nick Korbel

This file is part of Booked Scheduler.

Booked Scheduler is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Booked Scheduler is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Booked Scheduler.  If not, see <http://www.gnu.org/licenses/>.
*/
define('ROOT_DIR', dirname(__FILE__) . '/../');
require_once ROOT_DIR . 'lib/Common/namespace.php';
require_once ROOT_DIR . 'lib/Database/namespace.php';
require_once ROOT_DIR . 'lib/Database/Commands/namespace.php';
$command = new GetReservationListCommand(Date::Parse('2010-01-01'), Date::Parse('2012-01-01'), 1, 1);
$result = ServiceLocator::GetDatabase()->Query($command);
while ($row = $result->GetRow()) {
    foreach ($row as $name => $val) {
        echo "{$name} = {$val}, ";
    }
    echo PHP_EOL;
}