Skip to content

Commit

Permalink
Merge branch 'dev' into feature/MAR10001-345-order-api
Browse files Browse the repository at this point in the history
  • Loading branch information
24198 committed Apr 5, 2018
2 parents 7de86d1 + a3d0ff7 commit b8bd403
Show file tree
Hide file tree
Showing 186 changed files with 5,334 additions and 1,021 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ chapter.
Requirements
------------

Marello requires Symfony 2.8.x, Doctrine 2 and PHP 5.6 or above.
Marello requires Symfony 2.8.x, Doctrine 2 and PHP 7.0 or above.

Installation
------------
Expand Down
93 changes: 93 additions & 0 deletions src/Marello/Bundle/CatalogBundle/Controller/CategoryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace Marello\Bundle\CatalogBundle\Controller;

use Marello\Bundle\CatalogBundle\Entity\Category;
use Oro\Bundle\SecurityBundle\Annotation as Security;
use Oro\Bundle\UIBundle\Route\Router;
use Sensio\Bundle\FrameworkExtraBundle\Configuration as Config;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class CategoryController extends Controller
{
/**
* @Config\Route(
* "/{_format}",
* name="marello_category_index",
* requirements={"_format"="html|json"},
* defaults={"_format"="html"}
* )
* @Security\AclAncestor("marello_category_view")
* @Config\Template
*/
public function indexAction()
{
return [];
}

/**
* @Config\Route("/create", name="marello_category_create")
* @Security\AclAncestor("marello_category_create")
* @Config\Template("MarelloCatalogBundle:Category:update.html.twig")
*
* @return array
*/
public function createAction()
{
return $this->update(new Category());
}

/**
* @Config\Route("/update/{id}", requirements={"id"="\d+"}, name="marello_category_update")
* @Security\AclAncestor("marello_category_update")
* @Config\Template("MarelloCatalogBundle:Category:update.html.twig")
*
* @param Category $category
*
* @return array
*/
public function updateAction(Category $category)
{
return $this->update($category);
}

/**
* @param Category $category
*
* @return array
*/
protected function update(Category $category)
{
$handler = $this->get('marello_catalog.category.form.handler');

if ($handler->process($category)) {
$this->get('session')->getFlashBag()->add(
'success',
$this->get('translator')->trans('marello.catalog.ui.category.saved.message')
);

return $this->get('oro_ui.router')->redirect($category);
}

return [
'entity' => $category,
'form' => $handler->getFormView(),
];
}

/**
* @Config\Route("/view/{id}", requirements={"id"="\d+"}, name="marello_category_view")
* @Security\AclAncestor("marello_category_view")
* @Config\Template("MarelloCatalogBundle:Category:view.html.twig")
*
* @param Category $category
*
* @return array
*/
public function viewAction(Category $category)
{
return [
'entity' => $category,
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Marello\Bundle\CatalogBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

class MarelloCatalogExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $config, ContainerBuilder $container)
{
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
}
}
250 changes: 250 additions & 0 deletions src/Marello/Bundle/CatalogBundle/Entity/Category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
<?php

namespace Marello\Bundle\CatalogBundle\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Marello\Bundle\CatalogBundle\Model\ExtendCategory;
use Marello\Bundle\CoreBundle\Model\EntityCreatedUpdatedAtTrait;
use Marello\Bundle\ProductBundle\Entity\Product;
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\Config;
use Oro\Bundle\EntityConfigBundle\Metadata\Annotation\ConfigField;
use Oro\Bundle\OrganizationBundle\Entity\OrganizationAwareInterface;
use Oro\Bundle\OrganizationBundle\Entity\Ownership\AuditableOrganizationAwareTrait;

/**
* @ORM\Entity()
* @ORM\Table(name="marello_catalog_category")
* @Config(
* routeName="marello_category_index",
* routeView="marello_category_view",
* routeUpdate="marello_category_update",
* defaultValues={
* "entity"={
* "icon"="fa-folder"
* },
* "ownership"={
* "owner_type"="ORGANIZATION",
* "owner_field_name"="organization",
* "owner_column_name"="organization_id"
* },
* "security"={
* "type"="ACL",
* "group_name"="",
* "category"="catalog"
* },
* "dataaudit"={
* "auditable"=true
* }
* }
* )
* @ORM\HasLifecycleCallbacks()
*
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
*/
class Category extends ExtendCategory implements OrganizationAwareInterface
{
use EntityCreatedUpdatedAtTrait;
use AuditableOrganizationAwareTrait;

/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;

/**
* @var string
*
* @ORM\Column(type="string")
* @ConfigField(
* defaultValues={
* "dataaudit"={
* "auditable"=true
* }
* }
* )
*/
protected $name;

/**
* @var string
*
* @ORM\Column(type="string", nullable=false)
* @ConfigField(
* defaultValues={
* "dataaudit"={
* "auditable"=true
* }
* }
* )
*/
protected $code;

/**
* @var string
*
* @ORM\Column(name="description", type="text", nullable=true)
* @ConfigField(
* defaultValues={
* "dataaudit"={
* "auditable"=true
* }
* }
* )
*/
protected $description;

/**
* @var Collection|Product[]
*
* @ORM\ManyToMany(targetEntity="Marello\Bundle\ProductBundle\Entity\Product", inversedBy="categories")
* @ORM\JoinTable(
* name="marello_category_to_product",
* joinColumns={
* @ORM\JoinColumn(name="category_id", referencedColumnName="id", onDelete="CASCADE")
* },
* inverseJoinColumns={
* @ORM\JoinColumn(name="product_id", referencedColumnName="id", onDelete="CASCADE", unique=true)
* }
* )
* @ConfigField(
* defaultValues={
* "dataaudit"={
* "auditable"=true
* }
* }
* )
*/
protected $products;

/**
* Constructor
*/
public function __construct()
{
parent::__construct();

$this->products = new ArrayCollection();
}

/**
* @return integer
*/
public function getId()
{
return $this->id;
}

/**
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* @param string $name
* @return $this
*/
public function setName($name)
{
$this->name = $name;

return $this;
}

/**
* @return string
*/
public function getCode()
{
return $this->code;
}

/**
* @param string $code
* @return $this
*/
public function setCode($code)
{
$this->code = $code;

return $this;
}

/**
* @return string
*/
public function getDescription()
{
return $this->description;
}

/**
* @param string $description
* @return $this
*/
public function setDescription($description)
{
$this->description = $description;

return $this;
}

/**
* @return Collection|Product[]
*/
public function getProducts()
{
return $this->products;
}

/**
* @param Product $product
* @return $this
*/
public function addProduct(Product $product)
{
if (!$this->hasProduct($product)) {
$this->products->add($product);
}

return $this;
}

/**
* @param Product $product
* @return $this
*/
public function removeProduct(Product $product)
{
if ($this->hasProduct($product)) {
$this->products->removeElement($product);
}

return $this;
}

/**
* @param Product $product
* @return bool
*/
public function hasProduct(Product $product)
{
return $this->products->contains($product);
}

/**
* @return string
*/
public function __toString()
{
return (string)$this->getName();
}
}
Loading

0 comments on commit b8bd403

Please sign in to comment.