raspisms/controllers/internals/Webhook.php

90 lines
2.4 KiB
PHP
Raw Normal View History

2019-12-04 03:04:45 +01:00
<?php
/*
* This file is part of RaspiSMS.
*
* (c) Pierre-Lin Bonnemaison <plebwebsas@gmail.com>
*
* This source file is subject to the GPL-3.0 license that is bundled
* with this source code in the file LICENSE.
*/
namespace controllers\internals;
class Webhook extends StandardController
{
2020-01-17 18:36:53 +01:00
protected $bdd;
2020-01-17 18:19:25 +01:00
protected $model;
2019-12-04 03:04:45 +01:00
/**
2020-01-17 18:19:25 +01:00
* Create a new webhook.
*
* @param int $id_user : User id
* @param string $url : Webhook url
* @param string $type : Webhook type
*
2019-12-04 03:04:45 +01:00
* @return mixed bool|int : False if cannot create webhook, id of the new webhook else
*/
public function create(int $id_user, string $url, string $type)
{
$webhook = [
'id_user' => $id_user,
'url' => $url,
'type' => $type,
];
$result = $this->get_model()->insert($webhook);
if (!$result)
{
return false;
}
2020-01-17 18:19:25 +01:00
2019-12-04 03:04:45 +01:00
return $result;
}
2020-01-17 18:19:25 +01:00
2019-12-04 03:04:45 +01:00
/**
2020-01-17 18:19:25 +01:00
* Update a webhook.
*
* @param int $id_user : User id
* @param int $id : Webhook id
* @param string $url : Webhook url
* @param string $type : Webhook type
*
2019-12-04 03:04:45 +01:00
* @return mixed bool|int : False if cannot create webhook, id of the new webhook else
*/
public function update_for_user(int $id_user, int $id, string $url, string $type)
{
$datas = [
'url' => $url,
'type' => $type,
];
return $this->get_model()->update_for_user($id_user, $id, $datas);
}
/**
2020-01-17 18:19:25 +01:00
* Find all webhooks for a user and for a type of webhook.
*
* @param int $id_user : User id
* @param string $type : Webhook type
*
* @return array
*/
2020-01-17 18:19:25 +01:00
public function gets_for_type_and_user(int $id_user, string $type)
{
return $this->get_model()->gets_for_type_and_user($id_user, $type);
}
2020-01-17 18:19:25 +01:00
/**
* Get the model for the Controller.
*
* @return \descartes\Model
*/
protected function get_model(): \descartes\Model
{
$this->model = $this->model ?? new \models\Webhook($this->bdd);
return $this->model;
}
2019-12-04 03:04:45 +01:00
}