本文整理汇总了PHP中ServiceLocator::GetDatabase方法的典型用法代码示例。如果您正苦于以下问题:PHP ServiceLocator::GetDatabase方法的具体用法?PHP ServiceLocator::GetDatabase怎么用?PHP ServiceLocator::GetDatabase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ServiceLocator
的用法示例。
在下文中一共展示了ServiceLocator::GetDatabase方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: GetList
/**
* 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);
}
示例2: GetGroupAdminPermissions
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;
}
示例3: SetUserPreference
/**
* @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));
}
}
}
示例4: GetGroupPermissions
/**
* @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;
}
示例5: Validate
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;
}
示例6: RemoveResourceGroupPermission
public function RemoveResourceGroupPermission($resourceId, $groupId)
{
ServiceLocator::GetDatabase()->Execute(new DeleteGroupResourcePermission($groupId, $resourceId));
}
示例7: GetNextReservations
/**
* @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;
}
示例8: GetReminderNotices
/**
* @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;
}
示例9: GetGroupsByRole
/**
* @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;
}
示例10: Update
/**
* @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);
}
}
示例11: DeleteById
/**
* @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);
}
示例12: UserExists
public function UserExists($emailAddress, $userName)
{
$reader = ServiceLocator::GetDatabase()->Query(new CheckUserExistenceCommand($userName, $emailAddress));
if ($row = $reader->GetRow()) {
return $row[ColumnNames::USER_ID];
}
return null;
}
示例13: AddScheduleLayout
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());
}
示例14: Delete
/**
* @param int $accessoryId
* @return void
*/
public function Delete($accessoryId)
{
ServiceLocator::GetDatabase()->Execute(new DeleteAccessoryCommand($accessoryId));
}
示例15: define
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);