diff --git a/Controller/CategoryController.php b/Controller/CategoryController.php index 6fd5af0..9aaf665 100644 --- a/Controller/CategoryController.php +++ b/Controller/CategoryController.php @@ -10,6 +10,7 @@ use Stfalcon\Bundle\PortfolioBundle\Entity\Project; use Stfalcon\Bundle\PortfolioBundle\Entity\Category; +use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Category Controller @@ -19,10 +20,13 @@ class CategoryController extends Controller /** * View category * - * @param Category $category Category object - * @param int $page Page number + * @param string $slug Category slug + * @param int $page Page number * * @return array + * + * @throws NotFoundHttpException + * * @Route( * "/portfolio/{slug}/{page}", * name="portfolio_category_view", @@ -31,10 +35,15 @@ class CategoryController extends Controller * ) * @Template() */ - public function viewAction(Category $category, $page = 1) + public function viewAction($slug, $page) { - $query = $this->get('doctrine.orm.entity_manager') - ->getRepository("StfalconPortfolioBundle:Project") + $category = $this->get('stfalcon_portfolio.category.repository')->findOneBy(array('slug' => $slug)); + + if (!$category) { + throw new NotFoundHttpException('Category not found'); + } + + $query = $this->get('stfalcon_portfolio.project.repository') ->getQueryForSelectProjectsByCategory($category); $paginator = $this->get('knp_paginator')->paginate($query, $page, 6); @@ -63,8 +72,7 @@ public function viewAction(Category $category, $page = 1) public function servicesAction(Category $category, $project = null) { // @todo помоему этот блок отключен - $categories = $this->get('doctrine.orm.entity_manager') - ->getRepository("StfalconPortfolioBundle:Category")->getAllCategories(); + $categories = $this->get('stfalcon_portfolio.category.repository')->findAll(); return array('categories' => $categories, 'currentProject' => $project, 'currentCategory' => $category); } @@ -80,10 +88,11 @@ public function orderProjects() { // @todo переименовать метод и роут // @todo перенести сортировку проектов в админку + $em = $this->getDoctrine()->getManager(); $projects = $this->getRequest()->get('projects'); - $em = $this->get('doctrine')->getEntityManager(); + $projectManager = $this->get('stfalcon_portfolio.project.repository'); foreach ($projects as $projectInfo) { - $project = $em->getRepository("StfalconPortfolioBundle:Project")->find($projectInfo['id']); + $project = $projectManager->find($projectInfo['id']); $project->setOrdernum($projectInfo['index']); $em->persist($project); } diff --git a/Controller/ProjectController.php b/Controller/ProjectController.php index 012e7cf..97e154f 100644 --- a/Controller/ProjectController.php +++ b/Controller/ProjectController.php @@ -22,6 +22,9 @@ class ProjectController extends Controller * @param string $projectSlug Slug of project * * @return array + * + * @throws NotFoundHttpException + * * @Route("/portfolio/{categorySlug}/{projectSlug}", name="portfolio_project_view") * @Template() */ @@ -30,10 +33,15 @@ public function viewAction($categorySlug, $projectSlug) // @todo упростить когда что-то разрулят с этим PR https://github.com/sensio/SensioFrameworkExtraBundle/pull/42 // try find category by slug - $category = $this->_findCategoryBySlug($categorySlug); - + $category = $this->get('stfalcon_portfolio.category.repository')->findOneBy(array('slug' => $categorySlug)); + if (!$category) { + throw new NotFoundHttpException('Category not found'); + } // try find project by slug - $project = $this->_findProjectBySlug($projectSlug); + $project = $this->get('stfalcon_portfolio.project.repository')->findOneBy(array('slug' => $projectSlug)); + if (!$project) { + throw new NotFoundHttpException('Project not found'); + } if ($this->has('application_default.menu.breadcrumbs')) { $breadcrumbs = $this->get('application_default.menu.breadcrumbs'); @@ -57,21 +65,26 @@ public function viewAction($categorySlug, $projectSlug) * @param string $projectSlug Object of project * * @return array + * + * @throws NotFoundHttpException + * * @Template() */ public function nearbyProjectsAction($categorySlug, $projectSlug) { - // try find category by slug - $category = $this->_findCategoryBySlug($categorySlug); + $category = $this->get('stfalcon_portfolio.category.repository')->findOneBy(array('slug' => $categorySlug)); + if (!$category) { + throw new NotFoundHttpException('Category not found'); + } // try find project by slug - $project = $this->_findProjectBySlug($projectSlug); - - $em = $this->get('doctrine')->getEntityManager(); + $project = $this->get('stfalcon_portfolio.project.repository')->findOneBy(array('slug' => $projectSlug)); + if (!$project) { + throw new NotFoundHttpException('Project not found'); + } // get all projects from this category - $projects = $em->getRepository("StfalconPortfolioBundle:Project") - ->getProjectsByCategory($category); + $projects = $this->get('stfalcon_portfolio.project.repository')->findProjectsByCategory($category); // get next and previous projects from this category $i = 0; $previousProject = null; $nextProject = null; @@ -86,44 +99,4 @@ public function nearbyProjectsAction($categorySlug, $projectSlug) return array('category' => $category, 'previousProject' => $previousProject, 'nextProject' => $nextProject); } - - /** - * Try find category by slug - * - * @param string $slug Slug of category - * - * @return Category - */ - private function _findCategoryBySlug($slug) - { - $em = $this->get('doctrine')->getEntityManager(); - $category = $em->getRepository("StfalconPortfolioBundle:Category") - ->findOneBy(array('slug' => $slug)); - - if (!$category) { - throw new NotFoundHttpException('The category does not exist.'); - } - - return $category; - } - - /** - * Try find project by slug - * - * @param string $slug Slug of project - * - * @return Project - */ - private function _findProjectBySlug($slug) - { - $em = $this->get('doctrine')->getEntityManager(); - $project = $em->getRepository("StfalconPortfolioBundle:Project") - ->findOneBy(array('slug' => $slug)); - - if (!$project) { - throw new NotFoundHttpException('The project does not exist.'); - } - - return $project; - } } diff --git a/DependencyInjection/StfalconPortfolioExtension.php b/DependencyInjection/StfalconPortfolioExtension.php index b94b1a3..8e52250 100644 --- a/DependencyInjection/StfalconPortfolioExtension.php +++ b/DependencyInjection/StfalconPortfolioExtension.php @@ -5,6 +5,7 @@ use Symfony\Component\HttpKernel\DependencyInjection\Extension; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; +use Symfony\Component\Config\Definition\Processor; use Symfony\Component\Config\FileLocator; /** @@ -25,15 +26,41 @@ class StfalconPortfolioExtension extends Extension */ public function load(array $configs, ContainerBuilder $container) { - $config = array(); - foreach ($configs as $c) { - $config = array_merge($config, $c); - } + $config = $configs[0]; + - $container->setParameter('stfalcon_portfolio.config', $config); $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $loader->load('services.xml'); + $loader->load('orm.xml'); + + if (isset($config['project']['entity'])) { + $container->setParameter('stfalcon_portfolio.project.entity', $config['project']['entity']); + } + if (isset($config['category']['entity'])) { + $container->setParameter('stfalcon_portfolio.category.entity', $config['category']['entity']); + } + + if (isset($config['project']['repository'])) { + $container->setParameter('stfalcon_portfolio.project.repository', $config['project']['repository']); + } + if (isset($config['category']['repository'])) { + $container->setParameter('stfalcon_portfolio.category.repository', $config['category']['repository']); + } + + $loader->load('admin.xml'); + + if (isset($config['category']['admin']['class'])) { + $container->setParameter('stfalcon_portfolio.category.admin.class', $config['category']['admin']['class']); + } + if (isset($config['category']['admin']['controller'])) { + $container->setParameter('stfalcon_portfolio.category.admin.controller', $config['category']['admin']['controller']); + } + if (isset($config['project']['admin']['class'])) { + $container->setParameter('stfalcon_portfolio.project.admin.class', $config['project']['admin']['class']); + } + if (isset($config['project']['admin']['controller'])) { + $container->setParameter('stfalcon_portfolio.project.admin.controller', $config['project']['admin']['controller']); + } } } \ No newline at end of file diff --git a/Entity/BaseCategory.php b/Entity/BaseCategory.php new file mode 100644 index 0000000..ef9d041 --- /dev/null +++ b/Entity/BaseCategory.php @@ -0,0 +1,158 @@ +id; + } + + /** + * Set category name + * + * @param string $name Text for category name + * + * @return void + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * Get category name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set category slug + * + * @param string $slug Unique text identifier + * + * @return void + */ + public function setSlug($slug) + { + $this->slug = $slug; + } + + /** + * Get category slug + * + * @return string + */ + public function getSlug() + { + return $this->slug; + } + + /** + * Set category description + * + * @param string $description Text for category description + * + * @return void + */ + public function setDescription($description) + { + $this->description = $description; + } + + /** + * Get category description + * + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * Get category projects + * + * @return ArrayCollection + */ + public function getProjects() + { + return $this->projects; + } + + /** + * Set projects + * + * @param ArrayCollection $projects Array collection of projects + */ + public function setProjects($projects) + { + $this->projects = $projects; + } + + /** + * This method allows a class to decide how it will react when it is treated like a string + * + * @return string + */ + public function __toString() + { + return $this->getName(); + } +} \ No newline at end of file diff --git a/Entity/BaseProject.php b/Entity/BaseProject.php new file mode 100644 index 0000000..4aaec24 --- /dev/null +++ b/Entity/BaseProject.php @@ -0,0 +1,406 @@ +id; + } + + /** + * Get project categories + * + * @return ArrayCollection + */ + public function getCategories() + { + return $this->categories; + } + + /** + * Add category to project + * + * @param Category $category Category entity + * + * @return void + */ + public function addCategory(Category $category) + { + $this->categories[] = $category; + } + + /** + * Set categories collection to project + * + * @param ArrayCollection $categories Categories collection + */ + public function setCategories(ArrayCollection $categories) + { + $this->categories = $categories; + } + + /** + * Set project name + * + * @param string $name A text of project name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * Get project name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set project slug + * + * @param string $slug Unique text identifier + * + * @return void + */ + public function setSlug($slug) + { + $this->slug = $slug; + } + + /** + * Get project slug + * + * @return string + */ + public function getSlug() + { + return $this->slug; + } + + /** + * Set project description + * + * @param string $description A text of description + */ + public function setDescription($description) + { + $this->description = $description; + } + + /** + * Get project description + * + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * Set project url + * + * @param string $url A url for project + */ + public function setUrl($url) + { + $this->url = $url; + } + + /** + * Get project url + * + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * Set date when project has been realized + * + * @param \DateTime $date Date when project has been realized + */ + public function setDate(\DateTime $date) + { + $this->date = $date; + } + + /** + * Get date when project has been realized + * + * @return \DateTime + */ + public function getDate() + { + return $this->date; + } + + /** + * Get image filename + * + * @return string + */ + public function getImage() + { + return $this->image; + } + + /** + * Set image and create thumbnail + * + * @param string $image Full path to image file + * + * @return void + */ + public function setImage($image) + { + $this->image = $image; + } + + /** + * Remove thumbnail image file + * + * @return boolean + */ + public function removeImage() + { + if ($this->getImagePath() && \file_exists($this->getImagePath())) { + unlink($this->getImagePath()); + + return true; + } + + return false; + } + + /** + * Get list of users who worked on the project (as html) + * + * @return string + */ + public function getUsers() + { + return $this->users; + } + + /** + * Set list of users who worked on the project (as html) + * + * @param string $users A list in html format + */ + public function setUsers($users) + { + $this->users = $users; + } + + /** + * Set time when project created + * + * @param \DateTime $created A time when project created + */ + public function setCreated(\DateTime $created) + { + $this->created = $created; + } + + /** + * Get time when project created + * + * @return \DateTime + */ + public function getCreated() + { + return $this->created; + } + + /** + * Set time when project updated + * + * @param \DateTime $updated A time when project updated + */ + public function setUpdated(\DateTime $updated) + { + $this->updated = $updated; + } + + /** + * Get time when project updated + * + * @return \DateTime + */ + public function getUpdated() + { + return $this->updated; + } + + /** + * Set project ordernum + * + * @param int $ordernum + */ + public function setOrdernum($ordernum) + { + $this->ordernum = $ordernum; + } + + /** + * Get project ordernum + * + * @return int + */ + public function getOrdernum() + { + return $this->ordernum; + } + + /** + * Set onFrontPage + * + * @param bool $onFrontPage + */ + public function setOnFrontPage($onFrontPage) + { + $this->onFrontPage = $onFrontPage; + } + + /** + * Get onFrontPage + * + * @return bool + */ + public function getOnFrontPage() + { + return $this->onFrontPage; + } + + /** + * This method allows a class to decide how it will react when it is treated like a string + * + * @return string + */ + public function __toString() + { + return $this->getName(); + } +} \ No newline at end of file diff --git a/Entity/Category.php b/Entity/Category.php index 81dd664..00a653f 100644 --- a/Entity/Category.php +++ b/Entity/Category.php @@ -4,55 +4,15 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; -use Symfony\Component\Validator\Constraints as Assert; /** - * Category entity. It groups projects in portfolio - * - * @ORM\Table(name="portfolio_categories") * @ORM\Entity(repositoryClass="Stfalcon\Bundle\PortfolioBundle\Repository\CategoryRepository") + * @ORM\Table(name="portfolio_categories_base") */ -class Category +class Category extends BaseCategory { - - /** - * @var integer $id - * - * @ORM\Column(name="id", type="integer") - * @ORM\Id - * @ORM\GeneratedValue(strategy="AUTO") - */ - private $id; - - /** - * @var string $name - * - * @Assert\NotBlank() - * @Assert\MinLength(3) - * @ORM\Column(name="name", type="string", length=255) - */ - private $name = ''; - - /** - * @var string $slug - * - * @Assert\NotBlank() - * @Assert\MinLength(3) - * @ORM\Column(name="slug", type="string", length=128, unique=true) - */ - private $slug; - - /** - * @var text $description - * - * @Assert\NotBlank() - * @Assert\MinLength(10) - * @ORM\Column(name="description", type="text") - */ - private $description; - /** - * @var Doctrine\Common\Collections\ArrayCollection + * @var ArrayCollection $projects * * @ORM\ManyToMany( * targetEntity="Stfalcon\Bundle\PortfolioBundle\Entity\Project", @@ -60,7 +20,7 @@ class Category * ) * @ORM\OrderBy({"ordernum" = "ASC", "date" = "DESC"}) */ - private $projects; + protected $projects; /** * @@ -68,125 +28,27 @@ class Category * * @ORM\Column(name="ordernum", type="integer") */ - private $ordernum = 0; + protected $ordernum = 0; /** * Initialization properties for new category entity - * - * @return void */ public function __construct() { $this->projects = new ArrayCollection(); } - /** - * Get category id - * - * @return integer - */ - public function getId() - { - return $this->id; - } - - /** - * Set category name - * - * @param string $name Text for category name - * - * @return void - */ - public function setName($name) - { - $this->name = $name; - } - - /** - * Get category name - * - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * Set category slug - * - * @param string $slug Unique text identifier - * - * @return void - */ - public function setSlug($slug) - { - $this->slug = $slug; - } - - /** - * Get category slug - * - * @return string - */ - public function getSlug() - { - return $this->slug; - } - - /** - * Set category description - * - * @param string $description Text for category description - * - * @return void - */ - public function setDescription($description) - { - $this->description = $description; - } - - /** - * Get category description - * - * @return string - */ - public function getDescription() - { - return $this->description; - } - - /** - * Get category projects - * - * @return ArrayCollection - */ - public function getProjects() - { - return $this->projects; - } - /** * Add project to category * - * @param \Stfalcon\Bundle\PortfolioBundle\Entity\Project $project Project object - * - * @return void + * @param Project $project Project object */ - public function addProject(\Stfalcon\Bundle\PortfolioBundle\Entity\Project $project) + public function addProject($project) { - $this->projects[] = $project; + $this->projects->add($project); } - /** - * This method allows a class to decide how it will react when it is treated like a string - * - * @return string - */ - public function __toString() - { - return $this->getName(); - } + /** * Get order num @@ -207,5 +69,4 @@ public function setOrdernum($ordernum) { $this->ordernum = $ordernum; } - -} \ No newline at end of file +} diff --git a/Entity/Project.php b/Entity/Project.php index 9e9fb39..020e761 100644 --- a/Entity/Project.php +++ b/Entity/Project.php @@ -3,130 +3,23 @@ namespace Stfalcon\Bundle\PortfolioBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\ORM\Mapping as ORM; -use Symfony\Component\HttpFoundation\File\UploadedFile; use Symfony\Component\Validator\Constraints as Assert; +use Doctrine\ORM\Mapping as ORM; +use Symfony\Component\HttpFoundation\File\File; use Vich\UploaderBundle\Mapping\Annotation as Vich; -use Gedmo\Mapping\Annotation as Gedmo; -use Imagine; /** - * Project entity - * - * @ORM\Table(name="portfolio_projects") * @ORM\Entity(repositoryClass="Stfalcon\Bundle\PortfolioBundle\Repository\ProjectRepository") + * @ORM\Table(name="portfolio_projects_base") * @Vich\Uploadable */ -class Project +class Project extends BaseProject { - - /** - * @var integer $id - * - * @ORM\Column(name="id", type="integer") - * @ORM\Id - * @ORM\GeneratedValue(strategy="AUTO") - */ - private $id; - - /** - * @var string $name - * - * @Assert\NotBlank() - * @Assert\MinLength(3) - * @ORM\Column(name="name", type="string", length=255) - */ - private $name = ''; - - /** - * @var string $slug - * - * @Assert\NotBlank() - * @Assert\MinLength(3) - * @ORM\Column(name="slug", type="string", length=128, unique=true) - */ - private $slug; - - /** - * @var string $description - * - * @Assert\NotBlank() - * @Assert\MinLength(10) - * @ORM\Column(name="description", type="text") - */ - private $description; - - /** - * @var string $url - * - * @Assert\Url - * @ORM\Column(name="url", type="string", length=255, nullable=true) - */ - private $url; - - /** - * @var \DateTime $date - * - * @ORM\Column(type="datetime") - */ - private $date; - - /** - * @var \DateTime $created - * - * @ORM\Column(type="datetime") - * @Gedmo\Timestampable(on="create") - */ - private $created; - - /** - * @var \DateTime $updated - * - * @ORM\Column(type="datetime") - * @Gedmo\Timestampable(on="update") - */ - private $updated; - - /** - * @var File $image - * - * @Assert\File( - * maxSize="4M", - * mimeTypes={"image/png", "image/jpeg", "image/pjpeg"} - * ) - * @Vich\UploadableField(mapping="project_image", fileNameProperty="image") - */ - protected $imageFile; - - - /** - * @var string $image - * - * @ORM\Column(name="image", type="string", length=255, nullable=true) - */ - private $image; - - /** - * @var int $ordernum - * - * @ORM\Column(name="ordernum", type="integer") - */ - private $ordernum = 0; - - /** - * Check if this project can be published on main page of the site - * - * @var bool $onFrontPage - * - * @ORM\Column(name="onFrontPage", type="boolean") - */ - private $onFrontPage = true; - /** - * @var \Doctrine\Common\Collections\ArrayCollection + * @var ArrayCollection * * @ORM\ManyToMany(targetEntity="Stfalcon\Bundle\PortfolioBundle\Entity\Category") - * @ORM\JoinTable(name="portfolio_projects_categories", + * @ORM\JoinTable(name="portfolio_projects_categories_base", * joinColumns={ * @ORM\JoinColumn(name="project_id", referencedColumnName="id") * }, @@ -135,348 +28,35 @@ class Project * } * ) */ - private $categories; + protected $categories; /** - * @var string $users + * @var File $image * - * @ORM\Column(name="users", type="text", nullable=true) + * @Assert\File( + * maxSize="4M", + * mimeTypes={"image/png", "image/jpeg", "image/pjpeg"} + * ) + * @Vich\UploadableField(mapping="project_image", fileNameProperty="image") */ - private $users; + protected $imageFile; /** * Initialization properties for new project entity - * - * @return void */ public function __construct() { $this->categories = new ArrayCollection(); } - /** - * Get post id - * - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * Get project categories - * - * @return ArrayCollection - */ - public function getCategories() - { - return $this->categories; - } - - /** - * Add category to project - * - * @param Category $category Category entity - * - * @return void - */ - public function addCategory(Category $category) - { - $this->categories[] = $category; - } - - /** - * Set categories collection to project - * - * @param \Doctrine\Common\Collections\Collection $categories Categories collection - * - * @return void - */ - public function setCategories(\Doctrine\Common\Collections\Collection $categories) - { - $this->categories = $categories; - } - - /** - * Set project name - * - * @param type $name A text of project name - * - * @return void - */ - public function setName($name) - { - $this->name = $name; - } - - /** - * Get project name - * - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * Set project slug - * - * @param string $slug Unique text identifier - * - * @return void - */ - public function setSlug($slug) - { - $this->slug = $slug; - } - - /** - * Get project slug - * - * @return string - */ - public function getSlug() - { - return $this->slug; - } - - /** - * Set project description - * - * @param string $description A text of description - * - * @return void - */ - public function setDescription($description) - { - $this->description = $description; - } - - /** - * Get project description - * - * @return string - */ - public function getDescription() - { - return $this->description; - } - - /** - * Set project url - * - * @param string $url A url for project - * - * @return void - */ - public function setUrl($url) - { - $this->url = $url; - } - - /** - * Get project url - * - * @return string - */ - public function getUrl() - { - return $this->url; - } - - /** - * Set date when project has been realized - * - * @param \DateTime $date Date when project has been realized - * - * @return void - */ - public function setDate(\DateTime $date) - { - $this->date = $date; - } - - /** - * Get date when project has been realized - * - * @return \DateTime - */ - public function getDate() - { - return $this->date; - } - - /** - * Get image filename - * - * @return string - */ - public function getImage() - { - return $this->image; - } - - /** - * Set image and create thumbnail - * - * @param string $image Full path to image file - * - * @return void - */ - public function setImage($image) - { - $this->image = $image; - } - - /** - * Remove thumbnail image file - * - * @return boolean - */ - public function removeImage() - { - if ($this->getImagePath() && \file_exists($this->getImagePath())) { - unlink($this->getImagePath()); - - return true; - } - - return false; - } - - /** - * Get list of users who worked on the project (as html) - * - * @return string - */ - public function getUsers() - { - return $this->users; - } - - /** - * Set list of users who worked on the project (as html) - * - * @param string $users A list in html format - * - * @return void - */ - public function setUsers($users) - { - $this->users = $users; - } - - /** - * Set time when project created - * - * @param \DateTime $created A time when project created - * - * @return void - */ - public function setCreated(\DateTime $created) - { - $this->created = $created; - } - - /** - * Get time when project created - * - * @return \DateTime - */ - public function getCreated() - { - return $this->created; - } - - /** - * Set time when project updated - * - * @param \DateTime $updated A time when project updated - * - * @return void - */ - public function setUpdated(\DateTime $updated) - { - $this->updated = $updated; - } - - /** - * Get time when project updated - * - * @return \DateTime - */ - public function getUpdated() - { - return $this->updated; - } - - /** - * Set project ordernum - * - * @param int $ordernum - * - * @return void - */ - public function setOrdernum($ordernum) - { - $this->ordernum = $ordernum; - } - - /** - * Get project ordernum - * - * @return int - */ - public function getOrdernum() - { - return $this->ordernum; - } - - /** - * Set onFrontPage - * - * @param bool $onFrontPage - * - * @return void - */ - public function setOnFrontPage($onFrontPage) - { - $this->onFrontPage = $onFrontPage; - } - - /** - * Get onFrontPage - * - * @return bool - */ - public function getOnFrontPage() - { - return $this->onFrontPage; - } - /** * Set imageFile * * @param File $imageFile - * - * @return void */ public function setImageFile($imageFile) { - if (null === $imageFile) { - return; - } - $this->imageFile = $imageFile; - $imagine = new Imagine\Gd\Imagine(); - $imagePath = $imagine->open($this->imageFile->getPathName()); - $imagePath->thumbnail(new Imagine\Image\Box(240, $imagePath->getSize()->getHeight()), Imagine\Image\ImageInterface::THUMBNAIL_INSET) - ->crop(new Imagine\Image\Point(0, 0), new Imagine\Image\Box(240, 198)) - ->save($this->imageFile->getPathName(), array('format' => 'png')); - - $this->setUpdated(new \DateTime()); } /** @@ -488,14 +68,4 @@ public function getImageFile() { return $this->imageFile; } - - /** - * This method allows a class to decide how it will react when it is treated like a string - * - * @return string - */ - public function __toString() - { - return $this->getName(); - } -} \ No newline at end of file +} diff --git a/Naming/ProjectNaming.php b/Naming/ProjectNaming.php deleted file mode 100644 index 50514fd..0000000 --- a/Naming/ProjectNaming.php +++ /dev/null @@ -1,23 +0,0 @@ -getImageFile()->guessExtension(); - } -} diff --git a/Repository/CategoryRepository.php b/Repository/CategoryRepository.php index 083bdde..2b1dfd0 100644 --- a/Repository/CategoryRepository.php +++ b/Repository/CategoryRepository.php @@ -17,15 +17,8 @@ class CategoryRepository extends EntityRepository */ public function getAllCategories() { - $query = $this->getEntityManager()->createQuery(' - SELECT - c - FROM - StfalconPortfolioBundle:Category c - ORDER BY - c.ordernum'); - - return $query->getResult(); + return $this->createQueryBuilder('c') + ->orderBy('c.ordernum', 'ASC')->getQuery()->getResult(); } } \ No newline at end of file diff --git a/Repository/ProjectRepository.php b/Repository/ProjectRepository.php index 831a39b..793197f 100644 --- a/Repository/ProjectRepository.php +++ b/Repository/ProjectRepository.php @@ -3,7 +3,7 @@ namespace Stfalcon\Bundle\PortfolioBundle\Repository; use Doctrine\ORM\EntityRepository; -use Stfalcon\Bundle\PortfolioBundle\Entity\Category; +use Stfalcon\Bundle\PortfolioBundle\Entity\BaseCategory; /** * Project Repository @@ -14,29 +14,29 @@ class ProjectRepository extends EntityRepository /** * Get query for select projects by category * - * @param Category $category + * @param BaseCategory $category * * @return Doctrine\ORM\Query */ - public function getQueryForSelectProjectsByCategory(Category $category) + public function getQueryForSelectProjectsByCategory(BaseCategory $category) { return $this->createQueryBuilder('p') ->select('p') ->join('p.categories', 'c') - ->where('c.id = ?1') + ->where('c = :category') ->orderBy('p.ordernum', 'ASC') - ->setParameter(1, $category->getId()) + ->setParameter('category', $category) ->getQuery(); } /** * Get all projects from this category * - * @param Category $category A category object + * @param BaseCategory $category A category object * * @return array */ - public function getProjectsByCategory(Category $category) + public function findProjectsByCategory(BaseCategory $category) { return $this->getQueryForSelectProjectsByCategory($category) ->getResult(); diff --git a/Resources/config/admin.xml b/Resources/config/admin.xml new file mode 100644 index 0000000..3a1f012 --- /dev/null +++ b/Resources/config/admin.xml @@ -0,0 +1,31 @@ + + + + + + Stfalcon\Bundle\PortfolioBundle\Admin\CategoryAdmin + Stfalcon\Bundle\PortfolioBundle\Admin\ProjectAdmin + + SonataAdminBundle:CRUD + SonataAdminBundle:CRUD + + + + + + + %stfalcon_portfolio.category.entity% + %stfalcon_portfolio.category.admin.controller% + + + + + + %stfalcon_portfolio.project.entity% + %stfalcon_portfolio.project.admin.controller% + + + + diff --git a/Resources/config/orm.xml b/Resources/config/orm.xml new file mode 100644 index 0000000..830a070 --- /dev/null +++ b/Resources/config/orm.xml @@ -0,0 +1,29 @@ + + + + + + Stfalcon\Bundle\PortfolioBundle\Entity\Project + Stfalcon\Bundle\PortfolioBundle\Entity\Category + + Stfalcon\Bundle\PortfolioBundle\Repository\ProjectRepository + Stfalcon\Bundle\PortfolioBundle\Repository\CategoryRepository + + + + + %stfalcon_portfolio.project.entity% + + + + %stfalcon_portfolio.category.entity% + + + + diff --git a/Resources/config/services.xml b/Resources/config/services.xml deleted file mode 100644 index 2242127..0000000 --- a/Resources/config/services.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - Stfalcon\Bundle\PortfolioBundle\Admin\CategoryAdmin - Stfalcon\Bundle\PortfolioBundle\Entity\Category - - Stfalcon\Bundle\PortfolioBundle\Admin\ProjectAdmin - Stfalcon\Bundle\PortfolioBundle\Entity\Project - - - - - - - %stfalcon_portfolio.admin.category.entity% - - - - - - - %stfalcon_portfolio.admin.project.entity% - - - - - - - - - - diff --git a/Resources/doc/index.md b/Resources/doc/index.md index e48de89..94b303a 100644 --- a/Resources/doc/index.md +++ b/Resources/doc/index.md @@ -11,10 +11,8 @@ This version of the bundle requires: 2. LiipFunctionalTestBundle for testing (optional) 3. DoctrineFixturesBundle for fixtures (optional) 4. SonataAdminBundle for administering -5. VichUploaderBundle for uploads -6. StofDoctrineExtensionsBundle for timestamps -7. KnpPaginatorBundle for automate pagination -8. AvalancheImagineBundle for easy image manipulation support for Symfony2 +5. StofDoctrineExtensionsBundle for timestamps +6. KnpPaginatorBundle for automate pagination ## Installation @@ -58,9 +56,6 @@ public function registerBundles() // ... new Stfalcon\Bundle\PortfolioBundle\StfalconPortfolioBundle(), - // for use VichUploaderBundle - new Vich\UploaderBundle\VichUploaderBundle(), - // for use KnpMenuBundle new Knp\Bundle\MenuBundle\KnpMenuBundle(), @@ -75,8 +70,6 @@ public function registerBundles() new Sonata\AdminBundle\SonataAdminBundle(), new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(), new Sonata\jQueryBundle\SonatajQueryBundle(), - - new Avalanche\Bundle\ImagineBundle\AvalancheImagineBundle(), ); } ``` @@ -103,6 +96,23 @@ In YAML: ``` yaml # app/config/config.yml + +#stfalcon portfolio config +stfalcon_portfolio: + project: + entity: ~ # Required define + repository: ~ # Required define + admin: + class: Stfalcon\Bundle\PortfolioBundle\Admin\ProjectAdmin + controller: SonataAdminBundle:CRUD + category: + entity: ~ # Required define + repository: ~ # Required define + admin: + class: Stfalcon\Bundle\PortfolioBundle\Admin\CategoryAdmin + controller: SonataAdminBundle:CRUD + + # Sonata Configuration sonata_block: default_contexts: [cms] @@ -117,12 +127,6 @@ stof_doctrine_extensions: default: timestampable: true -vich_uploader: - db_driver: orm - mappings: - project_image: - upload_destination: %kernel.root_dir%/../web/uploads/portfolio/projects - namer: stfalcon_portfolio.namer.project ``` ### Step 4: Update your database schema diff --git a/composer.json b/composer.json index 42e50d6..706f229 100644 --- a/composer.json +++ b/composer.json @@ -19,8 +19,6 @@ "sonata-project/admin-bundle": "dev-master", "sonata-project/doctrine-orm-admin-bundle": "dev-master", "knplabs/knp-paginator-bundle": "2.3.2", - "vich/uploader-bundle": "0.8.1", - "avalanche123/imagine-bundle": "dev-master", "liip/functional-test-bundle": "dev-master" }, "suggest": {