panda-fire/core-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

Let the bundle organize your tasks efficiently

Installs: 188

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 1

Forks: 0

Open Issues: 1

Type:symfony-bundle

dev-master / 1.0.x-dev 2016-02-01 23:16 UTC

This package is not auto-updated.

Last update: 2018-02-27 12:49:07 UTC


README

Build Status SensioLabsInsight

Introduction

Imagine a world in which you have numerous tasks to perform with their respective due dates. Imagine that those tasks, tell you the right order to get everything done. Imagine that those tasks could let you know that you are trying to do something impossible. This is how PandaFire was born and what it wants to accomplish for you.

All you need to know is your task due date and its length. Then click. PandaFire will immediately tell you its feasibility and when to do it to be the most efficient as possible.

Because you want to get things done.

Installation

Download the plugin via composer

$ composer require panda-fire/core-bundle

Enable plugin

In the app/AppKernel.php file, add the following lines

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // other bundles ...
            new PandaFire\CoreBundle\PandaFireCoreBundle(),

        return $bundles;
    }

Create user and task classes using XML

User

<!-- AppBundle/Resources/config/doctrine/User.orm.xml -->
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="AppBundle\Entity\User" table="user">

        <id name="id" type="integer">
            <generator strategy="AUTO" />
        </id>

        <!-- PandaFire required properties -->
        <field name="startWorkingHour" type="integer" column="start_working_hour" />
        <field name="endWorkingHour" type="integer" column="end_working_hour" />
        <field name="startBreakHour" type="integer" column="start_break_hour" />
        <field name="endBreakHour" type="integer" column="end_break_hour" />
        <field name="daysOff" type="array" column="days_off" nullable="true" />

        <one-to-many target-entity="AppBundle\Entity\Task" mapped-by="owner" field="timeSortableItems" />
        <!-- End PandaFire required properties -->
    </entity>

</doctrine-mapping>
<?php
// src/AppBundle/Entity/User.php
namespace AppBundle\Entity;

use PandaFire\CoreBundle\Model\TaskOwner;

class User extends TaskOwner
{
    // your custom logic
}

Task

<!-- AppBundle/Resources/config/doctrine/Task.orm.xml -->
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="AppBundle\Entity\Task" table="task" repository-class="PandaFire\CoreBundle\Repository\ORM\TimeSortableItemRepository">

        <id name="id" type="integer">
            <generator strategy="AUTO" />
        </id>

        <many-to-one target-entity="User" field="owner" inversed-by="timeSortableItems">
            <join-column on-delete="CASCADE" />
        </many-to-one>

    </entity>

</doctrine-mapping>
<?php
// src/AppBundle/Entity/Task.php
namespace AppBundle\Entity;

use PandaFire\CoreBundle\Model\TimeSortable;

class Task extends TimeSortable
{
    /**
     * @var User
     */
    protected $owner;
}

Configuration

Configure the PandaFireCoreBundle :

panda_fire_core:
    db_driver: orm                          # Only driver supported at the moment
    task_class: AppBundle\Entity\Task     # Your "task" object class

Run migrations

Update your schema using the following command

$ php app/console doctrine:schema:update --force

Go further

Integration with FOSUserBundle

  1. Install and configure FOSUserBundle
  2. Create entities
  3. Enable the bundle
  4. Update your database schema

Step 1 : FOSUserBundle installation & configuration

Install the FOSUserBundle as specified in the related documentation. Once everything is fine, proceed to the following steps.

Step 2 : Create entities

Add the required properties to your Resources/config/doctrine/User.orm.xml model configuration file as follow:

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="AppBundle\Entity\User">

        <id name="id" type="integer">
            <generator strategy="AUTO" />
        </id>

        <!-- PandaFire -->
        <field name="startWorkingHour" type="integer" column="start_working_hour" />
        <field name="endWorkingHour" type="integer" column="end_working_hour" />
        <field name="startBreakHour" type="integer" column="start_break_hour" />
        <field name="endBreakHour" type="integer" column="end_break_hour" />
        <field name="daysOff" type="array" column="days_off" nullable="true" />
         <!-- End PandaFire -->

        <one-to-many target-entity="Task" mapped-by="owner" field="timeSortableItems" />
    </entity>

</doctrine-mapping>

To easily add the getters/setters of your class, just use the Trait provided :

<?php

namespace AppBundle\Entity;

use FOS\UserBundle\Model\User as FOSUser;
use PandaFire\CoreBundle\Model\TaskOwnerTrait;

class User extends FOSUser
{
    use TaskOwnerTrait;
}

Create a Task entity starting with the mapping file in AppBundle/Resources/config/doctrine/Task.orm.xml ...

<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">

    <entity name="AppBundle\Entity\Task" repository-class="PandaFire\CoreBundle\Repository\ORM\TimeSortableItemRepository">

        <id name="id" type="integer">
            <generator strategy="AUTO" />
        </id>

        <many-to-one target-entity="User" field="owner" inversed-by="timeSortableItems">
            <join-column on-delete="CASCADE" />
        </many-to-one>

    </entity>

</doctrine-mapping>

And its entity file in AppBundle/Entity/Task.php :

<?php

namespace AppBundle\Entity;

use PandaFire\CoreBundle\Model\TimeSortable;

class Task extends TimeSortable
{
    /**
     * @var User
     */
    protected $owner;
}

Note that the property $owner don't have to be defined but makes type hinting more developer friendly ;-)

Step 3 : Enable the bundle

Enable the plugin in your app/AppKernel.php file :

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // other bundles ...
            new AppBundle\AppBundle(),
            new FOS\UserBundle\FOSUserBundle(),
            new PandaFire\CoreBundle\PandaFireCoreBundle(),

        return $bundles;
    }

Configure the bundle in your app/config/config.yml :

panda_fire_core:
    db_driver: orm                      # Only supported driver at the moment
    task_class: AppBundle\Entity\Task   # You task entity class

Step 4 : Update your database schema

Simply run the following command :

$ php app/console doctrine:schema:update --force

And voilà !