Skip to content

Commit

Permalink
Merge pull request #1 from volyanytsky/extend-base-users-functionalit…
Browse files Browse the repository at this point in the history
…y-with-certain-cases-and-fixes

Extend BaseUsers class with certain functionality and fixes
  • Loading branch information
Sergey Volyanytsky committed Nov 13, 2022
2 parents cdb2911 + b01864b commit a4d0138
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
Empty file modified lib/Exceptions/StalkerPortalException.php
100755 → 100644
Empty file.
3 changes: 2 additions & 1 deletion lib/Interfaces/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public function getComment();
public function getExpireDate();
public function getAccountBalance();
public function getFullName();
}
public function getPhone();
}
Empty file modified lib/Interfaces/Stb.php
100755 → 100644
Empty file.
46 changes: 40 additions & 6 deletions lib/Resources/BaseUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ final public function add(AccountInterface $user)
$data['comment'] = $user->getComment();
$data['end_date'] = $user->getExpireDate();
$data['account_balance'] = $user->getAccountBalance();
$data['phone'] = $user->getPhone();

return $this->post($data);
}
Expand All @@ -44,22 +45,55 @@ final public function updateUser(AccountInterface $user)
$data['comment'] = $user->getComment();
$data['end_date'] = $user->getExpireDate();
$data['account_balance'] = $user->getAccountBalance();
$data['phone'] = $user->getPhone();

return $this->put($user->getMac(), $data);
if(!empty($user->getLogin()))
{
$data['stb_mac'] = $user->getMac();
$userId = $user->getLogin();
}

else
{
$userId = $user->getMac();
}

return $this->put($userId, $data);
}

final public function switchTariffPlan($id)
final public function switchTariffPlan($id, $tariffPlanId)
{
return $this->put($id, ['tariff_plan' => $id]);
return $this->put($id, ['tariff_plan' => $tariffPlanId]);
}

final public function setExpireDate($id, $date)
{
if(DateTime::createFromFormat("Y-m-d", $date) === false)
if(DateTime::createFromFormat("Y-m-d H:i:s", $date) === false)
{
throw new StalkerPortalException($date .": incorrect format. STB expire date must be Y-m-d");
throw new StalkerPortalException($date .": incorrect format. User expire date must be Y-m-d H:i:s");
}

return $this->put($id, ['end_date' => $date]);
}
}

final public function setComment($id, $comment)
{
return $this->put($id, ['comment' => $comment]);
}

final public function setName($id, $name)
{
return $this->put($id, ['full_name' => $name]);
}


final public function setPassword($id, $password)
{
if(!isset($password))
{
throw new StalkerPortalException("password must be set");
}

return $this->put($id, ['password' => $password]);
}
}
7 changes: 6 additions & 1 deletion lib/Resources/Stb.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,9 @@ public function updateAccount(StbInterface $user)
return $this->put($user->getAccountNumber(), $data);
}

}
public function setAccountNumber($mac, $accountNumber)
{
return $this->put($mac, ['ls' => $accountNumber]);
}

}

0 comments on commit a4d0138

Please sign in to comment.