Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

events can have a different owner #1190

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions src/Classes/ServiceAPI/MyRadio_Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,21 @@ public function setEndTime(int $endTime): void
$this->updateCacheObject();
}

/**
* @param int
*/
public function setHostId(int $hostId): void
{
self::$db->query('UPDATE public.events
SET hostid = $2
WHERE eventid = $1', [
$this->getID(),
$hostId
]);
alyxbb marked this conversation as resolved.
Show resolved Hide resolved
$this->hostId = $hostId;
$this->updateCacheObject();
}

/**
* @return string
*/
Expand Down Expand Up @@ -184,7 +199,7 @@ public function getHost(): MyRadio_User
*/
public function update(array $data)
{
$requiredFields = ['title', 'description_html', 'start_time', 'end_time'];
$requiredFields = ['title', 'description_html', 'start_time', 'end_time', 'host'];
foreach ($requiredFields as $field) {
if (!(isset($data[$field]))) {
throw new MyRadioException("Missing $field", 400);
Expand All @@ -203,21 +218,24 @@ public function update(array $data)
SET title = $2,
description_html = $3,
start_time = $4,
end_time = $5
end_time = $5,
hostid = $6
WHERE eventid = $1',
[
$this->getID(),
$data['title'],
$data['description_html'],
CoreUtils::getTimestamp($data['start_time']),
CoreUtils::getTimestamp($data['end_time'])
CoreUtils::getTimestamp($data['end_time']),
$data['host']->getID()
]
);

$this->title = $data['title'];
$this->descriptionHtml = $data['description_html'];
$this->startTime = $data['start_time'];
$this->endTime = $data['end_time'];
$this->hostId = $data['host']->getID();

$this->updateCacheObject();
}
Expand Down Expand Up @@ -263,7 +281,7 @@ public static function getInRange($start, $end)
public static function create($data = [])
{
// Validate
$requiredFields = ['title', 'description_html', 'start_time', 'end_time'];
$requiredFields = ['title', 'description_html', 'start_time', 'end_time', 'host'];
foreach ($requiredFields as $field) {
if (!(isset($data[$field]))) {
throw new MyRadioException("Missing $field", 400);
Expand All @@ -277,15 +295,14 @@ public static function create($data = [])
}
}

$hostid = MyRadio_User::getCurrentOrSystemUser()->getID();

$sql = "INSERT INTO public.events (title, description_html, start_time, end_time, hostid)
VALUES ($1, $2, $3, $4, $5) RETURNING eventid";

$result = self::$db->fetchColumn($sql, [
$data['title'], $data['description_html'],
CoreUtils::getTimestamp($data['start_time']), CoreUtils::getTimestamp($data['end_time']),
$hostid
$data['host']->getID()
]);

return self::factory($result[0]);
Expand Down Expand Up @@ -352,6 +369,18 @@ public static function getForm()
'label' => 'End Time',
]
)
)
->addField(
new MyRadioFormField(
'host',
MyRadioFormField::TYPE_MEMBER,
[
'required' => true,
'label' => 'Organizer',
'explanation' => 'The person running the event',
]

)
);
}

Expand All @@ -365,7 +394,8 @@ public function getEditForm()
'title' => $this->getTitle(),
'description_html' => $this->getDescriptionHtml(),
'start_time' => date('d/m/Y H:i', $this->getStartTime()),
'end_time' => date('d/m/Y H:i', $this->getEndTime())
'end_time' => date('d/m/Y H:i', $this->getEndTime()),
'host' => MyRadio_User::getInstance($this->getHostId()),
]
);
}
Expand Down
1 change: 1 addition & 0 deletions src/Controllers/Events/editEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
} else {
// creating new
MyRadio_Event::getForm()
->setFieldValue('host', MyRadio_User::getInstance())
->render();
}
}