83 lines
1.5 KiB
PHP
83 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Factory;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use App\Model\Sms;
|
|
use Propel\Runtime\Collection\ObjectCollection;
|
|
use App\Model\SmsQuery;
|
|
|
|
/**
|
|
* class SmsFactory.
|
|
*
|
|
* @author Simon Vieille <simon@deblan.fr>
|
|
*/
|
|
class SmsFactory implements Factory
|
|
{
|
|
/**
|
|
* Creates a SMS.
|
|
*
|
|
* @param mixed $sender
|
|
* @param mixed $message
|
|
* @param mixed $time
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function create($sender, $message, $time)
|
|
{
|
|
return (new Sms())
|
|
->setSender($sender)
|
|
->setMessage($message)
|
|
->setTime((int) $time)
|
|
->save() > 0;
|
|
}
|
|
|
|
/*
|
|
* Finds SMS.
|
|
*
|
|
* @return ObjectCollection
|
|
*/
|
|
public function getAll()
|
|
{
|
|
return SmsQuery::create()->find();
|
|
}
|
|
|
|
/*
|
|
* Get a SMS.
|
|
*
|
|
* @param int $id
|
|
*
|
|
* @return Sms|null
|
|
*/
|
|
public function get($id)
|
|
{
|
|
return SmsQuery::create()
|
|
->filterById($id)
|
|
->findOne();
|
|
}
|
|
|
|
/*
|
|
* Removes a SMS.
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function remove(Sms $object)
|
|
{
|
|
return $object->delete();
|
|
}
|
|
|
|
/**
|
|
* Creates a SMS with a Request content.
|
|
*
|
|
* @param Request $request
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function createByRequest(Request $request)
|
|
{
|
|
$content = json_decode($request->getContent(), true);
|
|
|
|
return $this->create($content['sender'], $content['message'], $content['time']);
|
|
}
|
|
}
|