Completed
Pull Request — master (#168)
by
unknown
02:59
created

ProfileManager::createProfile()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 13
rs 9.4285
cc 2
eloc 9
nc 2
nop 3
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\SettingsBundle\Service;
13
14
use ONGR\SettingsBundle\Document\Profile;
15
use ONGR\ElasticsearchBundle\Service\Manager;
16
use ONGR\ElasticsearchDSL\Query\MatchAllQuery;
17
18
class ProfileManager
19
{
20
    /**
21
     * Elasticsearch manager
22
     *
23
     * @var Manager
24
     */
25
    private $manager;
26
27
    /**
28
     * ProfileFinder constructor.
29
     *
30
     * @param Manager $manager
31
     */
32
    public function __construct(Manager $manager)
33
    {
34
        $this->manager = $manager;
35
    }
36
37
    /**
38
     * Finds all profiles
39
     *
40
     * @returns array
41
     */
42
    public function getAllProfiles()
43
    {
44
        $repo = $this->manager->getRepository('ONGRSettingsBundle:Profile');
45
        $search = $repo->createSearch();
46
        $search->addQuery(new MatchAllQuery());
47
        return $repo->execute($search, 'array');
48
    }
49
50
    /**
51
     * Creates a new profile
52
     *
53
     * @param string $name
54
     * @param string $description
55
     * @param string $id
56
     */
57
    public function createProfile($name, $description, $id = '')
58
    {
59
        $profile = new Profile();
60
        if ($id != '') {
61
            $profile->setId($id);
62
        }
63
        $profile->setName($name);
64
        $profile->setDescription($description);
65
66
        $this->manager->persist($profile);
67
        $this->manager->commit();
68
        $this->manager->flush();
69
    }
70
}
71