mirror of
https://github.com/RaspbianFrance/raspisms.git
synced 2025-04-20 16:37:48 +02:00
add medias to scheduled creation
This commit is contained in:
parent
f330312b55
commit
3fff7e0abd
5 changed files with 157 additions and 87 deletions
|
@ -33,6 +33,36 @@ namespace controllers\internals;
|
|||
return $this->get_model()->insert($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload and create a media
|
||||
*
|
||||
* @param int $id_user : Id of the user
|
||||
* @param array $file : array representing uploaded file, extracted from $_FILES['yourfile']
|
||||
* @return mixed bool | int : False on error, or new media id on success
|
||||
*/
|
||||
public function upload_and_create_for_user(int $id_user, array $file)
|
||||
{
|
||||
$user_media_path = PWD_DATA . '/medias/' . $id_user;
|
||||
|
||||
//Create user medias dir if not exists
|
||||
if (!file_exists($user_media_path))
|
||||
{
|
||||
if (!mkdir($user_media_path, fileperms(PWD_DATA), true))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$upload_result = \controllers\internals\Tool::save_uploaded_file($file, $user_media_path);
|
||||
if ($upload_result['success'] !== true)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$new_filepath = 'medias/' . $id_user . '/' . $upload_result['content'];
|
||||
return $this->create($id_user, $new_filepath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Link a media to a scheduled, a received or a sended message
|
||||
* @param int $id_media : Id of the media
|
||||
|
@ -99,7 +129,7 @@ namespace controllers\internals;
|
|||
*
|
||||
* @return mixed bool : false on error, true on success
|
||||
*/
|
||||
public function unlink_all_of(int $resource_type, int $resource_id)
|
||||
public function unlink_all_of(string $resource_type, int $resource_id)
|
||||
{
|
||||
switch ($resource_type)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue