1
0
mirror of https://github.com/freescout-helpdesk/freescout.git synced 2024-11-25 11:52:29 +01:00
freescout/app/Observers/MailboxObserver.php

46 lines
956 B
PHP
Raw Normal View History

2018-07-14 03:23:37 +02:00
<?php
namespace App\Observers;
use App\Folder;
2018-07-24 08:34:28 +02:00
use App\Mailbox;
2018-07-14 03:23:37 +02:00
class MailboxObserver
{
/**
* Listen to the Mailbox created event.
*
2018-07-24 08:34:28 +02:00
* @param \App\Mailbox $mailbox
*
2018-07-14 03:23:37 +02:00
* @return void
*/
public function created(Mailbox $mailbox)
{
2018-07-25 19:25:00 +02:00
// Create folders
2018-07-14 14:17:11 +02:00
foreach (Folder::$public_types as $type) {
2018-07-24 08:34:28 +02:00
$folder = new Folder();
2018-07-14 03:23:37 +02:00
$folder->mailbox_id = $mailbox->id;
$folder->type = $type;
$folder->save();
}
$mailbox->createAdminPersonalFolders();
}
/**
* Delete the following on mailbox delete:
* - folders
* - conversations
2018-07-24 08:34:28 +02:00
* - user permissions.
*
* @param Mailbox $mailbox
*
* @return [type] [description]
2018-07-14 03:23:37 +02:00
*/
public function deleting(Mailbox $mailbox)
{
$mailbox->users()->delete();
$mailbox->conversations()->delete();
$mailbox->folders()->delete();
}
2018-07-24 08:34:28 +02:00
}