// простая структура данных, не entity
class TaskView
{
/**
* @var Member
*
* @Assert\NotBlank()
*/
public $author;
/**
* @var string
*
* @Assert\NotBlank()
*/
public $label;
/**
* @var string
*
* @Assert\NotBlank()
* @Assert\Length(min="20")
*/
public $resume;
/**
* @var string
*/
public $content;
/**
* @var \DateTimeImmutable
*
*/
public $startDate;
/**
* @var string
*/
public $executor;
public function __construct(Member $author, \DateTimeImmutable $startDate)
{
$this->author = $author;
$this->startDate = $startDate;
}
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('resume', TextType::class, [
'label' => 'Резюме'
])
->add('content', TextareaType::class, [
'label' => 'Описание',
'attr' => ['rows' => '10'],
])
->add('label', ChoiceType::class, [
'choices' => [
'Текущая' => Label::TASK_CURRENT,
'Срочная' => Label::TASK_EXPRESS
],
'label' => 'Тип задачи',
])
->add('endDate', DateType::class, [
'label' => 'Крайний срок',
'widget' => 'single_text',
'html5' => false,
'attr' => ['class' => 'js-datepicker', 'autocomplete' => 'off'],
]);
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => TaskView::class
]);
}
public function handle(TaskView $view): void
{
/** @var Member $executor */
$executor = !empty($view->executor) ?
$this->members->get($view->executor) :
null;
$task = Task::create(
$view->author,
$view->startDate,
$view->endDate,
$view->label,
$view->resume,
$view->content,
$executor
);
$this->tasks->add($task);
$this->em->flush();
}
/** @var User $user */
/** @var Member $member */
$user = $this->tokenStorage->getToken()->getUser();
$member = $this->members->findByUser($user);
$taskView = new Create\TaskView(
$member,
new \DateTimeImmutable()
);
$form = $this->form->create(Create\Form::class, $taskView);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
try {
$handler->handle($taskView);
$this->flashMessage->success('Задача создана');
return RedirectResponse::create($this->router->generate('admin_tasks_all'));
} catch (\DomainException $exception) {
$this->flashMessage->error($exception->getMessage());
return RedirectResponse::create($this->router->generate('admin_tasks_all'));
}
}
return Response::create($this->view->render('admin/tasks/create.html.twig', [
'form' => $form->createView()
]));
При чём тут мои или чьито способности
try {
$pdo->beginTransaction();
$ids = $pdo->query('SELECT id FROM `comments` where news_id = 77278 and dateAdd < (NOW() - INTERVAL 2 DAY')->fetchAll(\PDO::FETCH_COLUMN);
$stmtInsert = $pdo->prepare('INSERT INTO table(column1, column2) SELECT column1, column2 FROM table2 WHERE table2.id = :id');
foreach ($ids as $id) {
$stmtInsert->execute(['id' => $id]);
}
$stmtDelete = $pdo->prepare('DELETE FROM table2 WHERE id = :id');
foreach ($ids as $id) {
$stmtDelete->execute(['id' => $id]);
}
$pdo->commit();
} catch (PDOException $e) {
$pdo->rollBack();
// $logger->error($e->getMessage());
}
INSERT INTO table2 (column1, column2, column3, ...)
SELECT column1, column2, column3, ...
FROM table1
WHERE condition;