PHP code example of cunningsoft / achievement-bundle
1. Go to this page and download the library: Download cunningsoft/achievement-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
cunningsoft / achievement-bundle example snippets
// in AppKernel::registerBundles()
$bundles = array(
// ...
new Cunningsoft\AchievementBundle\CunningsoftAchievementBundle(),
// ...
);
// Acme\ProjectBundle\Entity\User.php
namespace Acme\ProjectBundle\Entity;
use Cunningsoft\AchievementBundle\Entity\UserInterface as AchievementUserInterface;
use Cunningsoft\AchievementBundle\Entity\Achievement;
class User implements AchievementUserInterface
{
/**
* @var int
*/
protected $id;
/**
* @var Achievement[]
*
* @ORM\OneToMany(targetEntity="Cunningsoft\AchievementBundle\Entity\Achievement", mappedBy="user")
* @ORM\OrderBy({"insertDate" = "DESC"})
*/
protected $achievements;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return Achievement[]
*/
public function getAchievements()
{
return $this->achievements;
}
// ...
// src/Acme/AchievementBundle/AcmeAchievementBundle.php
namespace Acme\AchievementBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AcmeAchievementBundle extends Bundle
{
public function getParent()
{
return 'CunningsoftAchievementBundle';
}
}
// src/Acme/AchievementBundle/Listener/AchievementListener.php
namespace Acme\AchievementBundle\Listener;
use Cunningsoft\AchievementBundle\Services\AchievementService;
use Doctrine\ORM\EntityManager;
class AchievementListener
{
/**
* @var AchievementService
*/
private $achievementService;
/**
* @var EntityManager
*/
private $entityManager;
/**
* @param AchievementService $achievementService
* @param EntityManager $entityManager
*/
public function __construct(AchievementService $achievementService, EntityManager $entityManager)
{
$this->achievementService = $achievementService;
$this->entityManager = $entityManager;
}
}
// src/Acme/ProjectBundle/Event/CommentEvent.php
namespace Acme\ProjectBundle\Event;
use Acme\ProjectBundle\Entity\Comment;
use Symfony\Component\EventDispatcher\Event;
class CommentEvent extends Event
{
/**
* @var Comment
*/
protected $comment;
public function __construct(Comment $comment)
{
$this->comment = $comment;
}
/**
* @return Comment
*/
public function getComment()
{
return $this->comment;
}
}
// src/Acme/AchievementBundle/Listener/AchievementListener.php
// ...
public function onCommentPosted(CommentEvent $event)
{
if (mb_strlen($event->getComment()->getMessage()) >= 100) {
$this->achievementService->trigger('community', 'comment_100_characters', $event->getComment()->getAuthor());
}
}
// ...
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.