Skip to content

Commit

Permalink
Document block updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
abgreeve committed May 15, 2023
1 parent 8096543 commit a2e3d43
Showing 1 changed file with 43 additions and 12 deletions.
55 changes: 43 additions & 12 deletions classes/swap.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class swap {
private $messageformat;
private $status;

public function __construct($stashid, $initiator, $receiver, $initiatoritems = [], $receiveritems = [], $message = '',
$messageformat = 1, $status = null) {
public function __construct(int $stashid, int $initiator, int $receiver, array $initiatoritems = [], array $receiveritems = [],
string $message = '', int $messageformat = 1, int $status = null) {
$this->stashid = $stashid;
$this->initiator = $initiator;
$this->receiver = $receiver;
Expand All @@ -65,31 +65,46 @@ public function __construct($stashid, $initiator, $receiver, $initiatoritems = [
$this->status = $status;
}

public function set_id($id) {
/**
* Set the swap id.
*
* @param int $id The swap id.
*/
public function set_id($id) : void {
$this->id = $id;
}

public function set_status($status) {
/**
* Set the status of the swap.
*
* @param int $status The status of the swap.
*/
public function set_status($status) : void {
$this->status = $status;
}

public function get_initiator_items() {
public function get_initiator_items() : array {
return $this->initiatoritems;
}

public function get_receiver_items() {
public function get_receiver_items() : array {
return $this->receiveritems;
}

public function get_receiver_id() {
public function get_receiver_id() : int {
return $this->receiver;
}

public function get_initiator_id() {
public function get_initiator_id() : int {
return $this->initiator;
}

public function save() {
/**
* Save the swap.
*
* @return int The swap id.
*/
public function save() : int {
global $DB;
// Save swap.
$rawdata = (object) [
Expand Down Expand Up @@ -117,7 +132,13 @@ public function save() {

}

private function save_detail($swapitems, $swapid) {
/**
* Save the swap details.
*
* @param array $swapitems The items to save.
* @param int $swapid The swap id.
*/
private function save_detail(array $swapitems, int $swapid) : void {
global $DB;
foreach ($swapitems as $items) {
$data = (object) [
Expand All @@ -129,14 +150,24 @@ private function save_detail($swapitems, $swapid) {
}
}

public function delete() {
/**
* Delete the whole swap (including details).
*/
public function delete() : void {
global $DB;

$DB->delete_records(self::TABLE_DETAIL, ['swapid' => $this->id]);
$DB->delete_records(self::TABLE, ['id' => $this->id]);
}

public static function load($swapid, $detailsaswell = false) {
/**
* Load the swap from an id.
*
* @param int $swapid The swap id.
* @param bool $detailsaswell Whether to load the details as well.
* @return \block_stash\swap
*/
public static function load(int $swapid, bool $detailsaswell = false) : swap {
global $DB;
$record = $DB->get_record(self::TABLE, ['id' => $swapid]);
$initiatoritems = [];
Expand Down

0 comments on commit a2e3d43

Please sign in to comment.