Skip to content

Commit

Permalink
Refactor: Repository queries fixed to group by creation date + remove…
Browse files Browse the repository at this point in the history
…d dependency on gedmo
  • Loading branch information
pix-art committed May 5, 2015
1 parent 3990732 commit 3a0584e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
phpunit.xml
vendor
composer.lock
composer.phar
composer.phar
bin
.idea
2 changes: 0 additions & 2 deletions Entity/SmartCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Intracto\SmartCodeBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;

/**
* @ORM\Entity(repositoryClass="Intracto\SmartCodeBundle\Repository\SmartCodeRepository")
Expand Down Expand Up @@ -81,7 +80,6 @@ class SmartCode implements SmartCodeInterface
* Creation time.
*
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")
*
* @var \DateTime
*/
Expand Down
2 changes: 2 additions & 0 deletions Generator/SmartCodeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ public function __construct(EntityManagerInterface $manager)
public function generate(PayloadInterface $payload, SmartCodeOptions $options)
{
$codes = array();
$now = new \DateTime();

for ($i = 0, $amount = $options->getAmount(); $i < $amount; $i++) {
$smartCode = new SmartCode($payload);
$smartCode->setCreatedAt($now);
$smartCode->setCode($this->generateUniqueCode());
$smartCode->setUsageLimit($options->getUsageLimit());
$smartCode->setExpiresAt($options->getExpiresAt());
Expand Down
8 changes: 4 additions & 4 deletions Repository/SmartCodeRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class SmartCodeRepository extends EntityRepository
{
public function findAllCreationGroupsForPayload(PayloadInterface $payload)
public function findAllCreationDatesForPayload(PayloadInterface $payload)
{
return $this->getEntityManager()
->createQuery(
Expand All @@ -21,18 +21,18 @@ public function findAllCreationGroupsForPayload(PayloadInterface $payload)
->getResult();
}

public function findAllByCreationGroup(\DateTime $creationGroup, PayloadInterface $payload)
public function findAllByCreationDate(\DateTime $creationDate, PayloadInterface $payload)
{
return $this->getEntityManager()
->createQuery(
'SELECT sc
FROM SmartCodeBundle:SmartCode sc
WHERE sc.createdAt = :creationGroup
WHERE sc.createdAt = :creationDate
AND sc.payload = :payload
ORDER BY sc.id ASC'
)
->setParameter('payload', $payload)
->setParameter('creationGroup', $creationGroup)
->setParameter('creationDate', $creationDate)
->getResult();
}
}
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"require": {
"php": ">=5.3.9",
"doctrine/orm": "~2.2",
"symfony/framework-bundle": "~2.1",
"stof/doctrine-extensions-bundle": "~1.1",
"symfony/framework-bundle": "~2.1"
},

"config": {
Expand Down

0 comments on commit 3a0584e

Please sign in to comment.