Last active
February 5, 2018 09:45
-
-
Save mohamedhafezqo/a681d6906d6a2e5e479420d4006f88bc to your computer and use it in GitHub Desktop.
Code Snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ACM\Bundle\CreditBundle\Constant; | |
final class CreditStatus implements IConstant | |
{ | |
const PENDING = 1; | |
const PENDING_LABEL = 'Pending'; | |
const SUCCESS = 2; | |
const SUCCESSFUL_LABEL = 'Success'; | |
const REFUND = 3; | |
const REFUND_LABEL = 'Refund'; | |
/** | |
* getChoices | |
* Get Status List. | |
* | |
* @return array | |
*/ | |
public static function getChoices() | |
{ | |
return array( | |
self::PENDING => self::PENDING_LABEL, | |
self::SUCCESS => self::SUCCESSFUL_LABEL, | |
self::REFUND => self::REFUND_LABEL, | |
); | |
} | |
public static function getLabel($type) | |
{ | |
$roles = self::getChoices(); | |
return isset($roles[$type]) ? $roles[$type] : null; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ACM\Bundle\ListingBundle\EventListener; | |
use ACM\Bundle\CreditBundle\Constant\CreditStatus; | |
use ACM\Bundle\ListingBundle\Entity\ListingFeature; | |
use ACM\Bundle\ListingBundle\Event\ListingEvent; | |
use Doctrine\ORM\EntityManager; | |
use Symfony\Component\DependencyInjection\Container; | |
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
class CreditStatusListener implements EventSubscriberInterface | |
{ | |
/** | |
* @var EntityManager | |
*/ | |
protected $em; | |
/** | |
* Constructor. | |
* | |
* @param EntityManager $entityManager | |
*/ | |
public function __construct(EntityManager $entityManager) | |
{ | |
$this->em = $entityManager; | |
} | |
/** | |
* @param ListingEvent $event | |
*/ | |
public function onListingPublishEvent(ListingEvent $event) | |
{ | |
$listing = $event->getListing(); | |
$featuredListings = $listing->getListingFeatures(); | |
/** @var ListingFeature $listing */ | |
foreach ($featuredListings as $listing) { | |
$credit = $listing->getCredit(); | |
if ($credit->getStatus() == CreditStatus::PENDING) { | |
$credit->setStatus(CreditStatus::SUCCESS); | |
$this->em->persist($credit); | |
$this->em->flush($credit); | |
} | |
} | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public static function getSubscribedEvents() | |
{ | |
return array( | |
'ACM.listing.publish' => array('onListingPublishEvent') | |
), | |
); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace ACM\Bundle\CreditBundle\Constant; | |
interface IConstant | |
{ | |
public static function getChoices(); | |
public static function getLabel($type); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment