PHP code example of avoo / achievement-bundle

1. Go to this page and download the library: Download avoo/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/ */

    

avoo / achievement-bundle example snippets

 php
// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Avoo\AchievementBundle\AvooAchievementBundle(),
    );
}
 php
namespace AppBundle\Entity;

use Avoo\AchievementBundle\Model\UserInterface;
use FOS\UserBundle\Model\User as BaseUser;

/**
 * Class User
 */
class User extends BaseUser implements UserInterface
{
    /**
     * @var integer $id
     */
    protected $id;

    /**
     * @var array $achievements
     */
    protected $achievements;

    /**
     * {@inheritdoc}
     */
    public function getAchievements()
    {
        return $this->achievements;
    }
}
 php
namespace AppBundle\Entity;

use Avoo\AchievementBundle\Entity\UserAchievement as BaseUserAchievement;
use Avoo\AchievementBundle\Model\UserInterface;

/**
 * Class UserAchievement
 */
class UserAchievement extends BaseUserAchievement
{
    /**
     * @var UserInterface $user
     */
    protected $user;
}

 php
namespace Avoo\EloBundle\Entity;

use Avoo\AchievementBundle\Model\UserInterface;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

class User extends BaseUser implement UserInterface
{
    /**
     * @OneToMany(targetEntity="AppBundle\Entity\UserAchievement", mappedBy="user")
     */
    protected $achievements;

    /**
     * {@inheritdoc}
     */
    public function getAchievements()
    {
        return $this->achievements;
    }
}
 php
namespace Avoo\EloBundle\Entity;

use Avoo\AchievementBundle\Entity\UserAchievement as BaseUserAchievement;
use Doctrine\ORM\Mapping as ORM;

class UserAchievement extends BaseUserAchievement
{
    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @ORM\ManyToOne(targetEntity="AppBundle\Entity\UserAchievement", inversedBy="achievements")
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
     */
    protected $user;
}
 php
namespace AppBundle\Listener;

use Avoo\AchievementBundle\Listener\AchievementListener;

/**
 * Class SuperAchievementListener
 *
 */
class SuperAchievementListener extends AchievementListener
{
}

 php
public function indexAction(Request $request)
{
    $achievement = $this->get('avoo_achievement');

    $achievement->get('my_category.my_super_achievement')->progress(2); // Return true or false
}
 php
public function indexAction(Request $request)
{
    $achievement = $this->get('avoo_achievement');

    $achievement->get('my_category.my_super_achievement')->isComplete(); // Return true or false
}
 php
namespace AppBundle\Listener;

use Avoo\AchievementBundle\Listener\AchievementListener;

/**
 * Class SuperAchievementListener
 *
 */
class SuperAchievementListener extends AchievementListener
{
    public function isValid($object = null)
    {
        //My validation process
    }
}

 php
public function indexAction(Request $request)
{
    $listener = $this->get('avoo_achievement')->get('my_category.my_super_achievement');
    if ($listener->isValid()) {
        $listener->progress(1);
    }
}
 php
namespace AppBundle\Listener;

use Avoo\AchievementBundle\Listener\AchievementListener;

/**
 * Class SuperAchievementListener
 *
 */
class SuperAchievementListener extends AchievementListener
{
    public function progress($value)
    {
        //My progress process
    }
}