Skip to content
This repository was archived by the owner on May 1, 2019. It is now read-only.

Commit b50b157

Browse files
author
Marco Rieger
committed
added Module Entity/Repo/Service
1 parent 9653bdc commit b50b157

4 files changed

Lines changed: 196 additions & 82 deletions

File tree

Lines changed: 88 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,104 @@
11
<?php
2-
32
namespace ZfModule\Entity;
43

54
use DateTime;
6-
7-
class Module implements ModuleInterface
5+
use Doctrine\ORM\Mapping as ORM;
6+
7+
/**
8+
* Module
9+
*
10+
* @ORM\Table(name="module")
11+
* @ORM\Entity(repositoryClass="ZfModule\Repository\Module")
12+
*/
13+
class Module
814
{
915
/**
10-
* @var int
16+
* @var integer
17+
*
18+
* @ORM\Id
19+
* @ORM\Column(name="module_id", type="integer", nullable=false)
20+
* @ORM\GeneratedValue(strategy="IDENTITY")
1121
*/
1222
private $id;
1323

1424
/**
1525
* @var string
26+
*
27+
* @ORM\Column(name="name", type="string", length=255, nullable=false)
1628
*/
1729
private $name;
1830

1931
/**
2032
* @var string
33+
*
34+
* @ORM\Column(name="description", type="text", nullable=false)
2135
*/
2236
private $description;
2337

2438
/**
25-
* @var string
39+
* @var DateTime
40+
*
41+
* @ORM\Column(name="created_at", type="datetime", nullable=true)
2642
*/
27-
private $url;
43+
private $created_at;
44+
45+
/**
46+
* @var DateTime
47+
*
48+
* @ORM\Column(name="updated_at", type="datetime", nullable=true)
49+
*/
50+
private $updated_at;
2851

2952
/**
3053
* @var string
54+
*
55+
* @ORM\Column(name="photo_url", type="string", length=255, nullable=true)
3156
*/
32-
private $createdAt;
57+
private $photo_url;
3358

3459
/**
3560
* @var string
61+
*
62+
* @ORM\Column(name="url", type="string", length=255, nullable=false)
3663
*/
37-
private $updatedAt;
64+
private $url;
3865

3966
/**
4067
* @var string
68+
*
69+
* @ORM\Column(name="owner", type="string", length=255, nullable=false)
4170
*/
4271
private $owner;
4372

4473
/**
45-
* @var string
74+
* @return string|null
4675
*/
47-
private $photoUrl;
76+
public function getIdentifier()
77+
{
78+
$owner = $this->getOwner();
79+
$name = $this->getName();
80+
81+
if (empty($owner) || empty($name)) {
82+
return;
83+
}
84+
85+
return sprintf('%s/%s', $owner, $name);
86+
}
4887

4988
/**
5089
* @return string
5190
*/
52-
public function getPhotoUrl()
91+
public function getUrl()
5392
{
54-
return $this->photoUrl;
93+
return $this->url;
5594
}
5695

5796
/**
58-
* @param string $photoUrl
97+
* @param string $url
5998
*/
60-
public function setPhotoUrl($photoUrl)
99+
public function setUrl($url)
61100
{
62-
$this->photoUrl = $photoUrl;
101+
$this->url = $url;
63102
}
64103

65104
/**
@@ -79,121 +118,98 @@ public function setOwner($owner)
79118
}
80119

81120
/**
82-
* @return string
121+
* @return int
83122
*/
84-
public function getUpdatedAt()
123+
public function getId()
85124
{
86-
return $this->updatedAt;
125+
return $this->id;
87126
}
88127

89128
/**
90-
* @param string $updatedAt
129+
* @param int $id
91130
*/
92-
public function setUpdatedAt($updatedAt)
131+
public function setId($id)
93132
{
94-
$this->updatedAt = $updatedAt;
133+
$this->id = $id;
95134
}
96135

97136
/**
98137
* @return string
99138
*/
100-
public function getCreatedAt()
101-
{
102-
return $this->createdAt;
103-
}
104-
105-
/**
106-
* @return DateTime
107-
*/
108-
public function getCreatedAtDateTime()
139+
public function getName()
109140
{
110-
return new DateTime($this->getCreatedAt());
141+
return $this->name;
111142
}
112143

113144
/**
114-
* @param string $createdAt
145+
* @param string $name
115146
*/
116-
public function setCreatedAt($createdAt)
147+
public function setName($name)
117148
{
118-
$this->createdAt = $createdAt;
149+
$this->name = $name;
119150
}
120151

121152
/**
122-
* @return int
153+
* @return string
123154
*/
124-
public function getId()
155+
public function getDescription()
125156
{
126-
return $this->id;
157+
return $this->description;
127158
}
128159

129160
/**
130-
* @param int $id
161+
* @param string $description
131162
*/
132-
public function setId($id)
163+
public function setDescription($description)
133164
{
134-
$this->id = (int) $id;
165+
$this->description = $description;
135166
}
136167

137168
/**
138-
* @return string
169+
* @return DateTime
139170
*/
140-
public function getUrl()
171+
public function getCreatedAt()
141172
{
142-
return $this->url;
173+
return $this->created_at;
143174
}
144175

145176
/**
146-
* @param string $url
177+
* @param DateTime $created_at
147178
*/
148-
public function setUrl($url)
179+
public function setCreatedAt($created_at)
149180
{
150-
$this->url = $url;
181+
$this->created_at = $created_at;
151182
}
152183

153184
/**
154-
* @return string
185+
* @return DateTime
155186
*/
156-
public function getDescription()
187+
public function getUpdatedAt()
157188
{
158-
return $this->description;
189+
return $this->updated_at;
159190
}
160191

161192
/**
162-
* @param string $description
193+
* @param DateTime $updated_at
163194
*/
164-
public function setDescription($description)
195+
public function setUpdatedAt($updated_at)
165196
{
166-
$this->description = $description;
197+
$this->updated_at = $updated_at;
167198
}
168199

169200
/**
170201
* @return string
171202
*/
172-
public function getName()
203+
public function getPhotoUrl()
173204
{
174-
return $this->name;
205+
return $this->photo_url;
175206
}
176207

177208
/**
178-
* @param string $name
209+
* @param string $photo_url
179210
*/
180-
public function setName($name)
211+
public function setPhotoUrl($photo_url)
181212
{
182-
$this->name = $name;
183-
}
184-
185-
/**
186-
* @return string|null
187-
*/
188-
public function getIdentifier()
189-
{
190-
$owner = $this->getOwner();
191-
$name = $this->getName();
192-
193-
if (empty($owner) || empty($name)) {
194-
return;
195-
}
196-
197-
return sprintf('%s/%s', $owner, $name);
213+
$this->photo_url = $photo_url;
198214
}
199215
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace ZfModule\Repository;
4+
5+
use Doctrine\ORM\EntityRepository;
6+
7+
class Module extends EntityRepository
8+
{
9+
10+
public function findModulesByName($term, $orderBy = [], $limit = null)
11+
{
12+
if (!$term) {
13+
// return all modules on empty search
14+
return $this->findAll($limit);
15+
}
16+
17+
$dqlQuery = 'SELECT m FROM ZfModule\Entity\Module m WHERE m.name LIKE :term';
18+
19+
if ($orderBy && count($orderBy) >= 1) {
20+
$dqlQuery .= ' ORDER BY ' . implode(',', $orderBy);
21+
}
22+
23+
$query = $this->getEntityManager()->createQuery($dqlQuery);
24+
$query->setParameter('term', '%' . $term . '%');
25+
$query->setMaxResults($limit);
26+
27+
return $query;
28+
}
29+
30+
public function findAll($limit = null, $offset = null)
31+
{
32+
$query = $this->getEntityManager()->createQuery('SELECT m FROM ZfModule\Entity\Module m');
33+
//$query->setFirstResult($offset);
34+
//$query->setMaxResults($limit);
35+
36+
return $query;
37+
}
38+
39+
public function countTotalModules()
40+
{
41+
$query = $this->getEntityManager()->createQuery('SELECT count(m) FROM ZfModule\Entity\Module m');
42+
return $query;
43+
}
44+
45+
}

0 commit comments

Comments
 (0)