ExportAttendeeListCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 8
dl 0
loc 51
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
B execute() 0 40 3
1
<?php
2
3
/**
4
 * @author    Markus Tacker <[email protected]>
5
 * @copyright 2013-2016 Verein zur Förderung der Netzkultur im Rhein-Main-Gebiet e.V. | http://netzkultur-rheinmain.de/
6
 */
7
8
namespace BCRM\BackendBundle\Command;
9
10
use BCRM\BackendBundle\Entity\Event\EventRepository;
11
use BCRM\BackendBundle\Entity\Event\Ticket;
12
use BCRM\BackendBundle\Entity\Event\TicketRepository;
13
use BCRM\BackendBundle\Exception\BadMethodCallException;
14
use BCRM\BackendBundle\Exception\CommandException;
15
use Doctrine\Common\Collections\ArrayCollection;
16
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
17
use Symfony\Component\Console\Input\InputArgument;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
/**
22
 * Exports the next events attendees as CSV.
23
 *
24
 * @package BCRM\BackendBundle\Command
25
 */
26
class ExportAttendeeListCommand extends ContainerAwareCommand
27
{
28
    protected function configure()
29
    {
30
        $this
31
            ->setName('bcrm:event:export-attendees')
32
            ->setDescription('Exports the next events attendees as CSV.')
33
            ->addArgument('output', InputArgument::REQUIRED, 'Name of the file to export to');
34
    }
35
36
    protected function execute(InputInterface $input, OutputInterface $output)
37
    {
38
        /* @var TicketRepository $ticketRepo */
39
        /* @var EventRepository $eventRepo */
40
        $eventRepo  = $this->getContainer()->get('bcrm.backend.repo.event');
41
        $ticketRepo = $this->getContainer()->get('bcrm.backend.repo.ticket');
42
43
        $tickets = array();
44
        $sort1   = array();
45
        $sort2   = array();
46
        foreach ($ticketRepo->getTicketsForEvent($eventRepo->getNextEvent()->getOrThrow(
47
            new BadMethodCallException('No event.')
48
        )) as $ticket) {
49
            /* @var Ticket $ticket */
50
            $tickets[] = array(
51
                $ticket->getDay(),
52
                $ticket->getCode(),
53
                $ticket->getName(),
54
                $ticket->getEmail(),
55
                $ticket->getLabel()
56
            );
57
            $sort1[]   = $ticket->getDay();
58
            $sort2[]   = $ticket->getCode();
59
        }
60
61
        array_multisort($sort1, SORT_ASC, $sort2, SORT_ASC, SORT_STRING, $tickets);
62
63
        $fp = fopen($input->getArgument('output'), 'w+');
64
        fputcsv($fp, array(
65
            'Tag',
66
            'Code',
67
            'Name',
68
            'E-Mail',
69
            'Typ',
70
        ));
71
        foreach ($tickets as $ticket) {
72
            fputcsv($fp, $ticket);
73
        }
74
        fclose($fp);
75
    }
76
}
77