Permalink
Browse files

fixes and refactoring

  • Loading branch information...
stfalcon committed Apr 24, 2012
1 parent 5a228ce commit 22a901a12a552c4ee9083b7c4f57eb2536d80219
View
@@ -14,16 +14,17 @@ protected function configureFormFields(FormMapper $formMapper)
$formMapper
->add('slug')
->add('name')
- ->add('description', 'textarea', array('attr' => array("class" => 'xxlarge')))
+ ->add('description', 'textarea', array('attr' => array("class" => 'input-xxlarge')))
+ // @todo сделать сортировку через sortable (по аналогии с проектами)
+ ->add('ordernum')
;
}
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('slug')
- ->add('description')
- ->add('ordernum')
+ ->add('name')
;
}
}
View
@@ -21,34 +21,35 @@ public function __construct($code, $class, $baseControllerName)
);
}
}
+
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
- ->add('slug')
->add('name')
- ->add('description', 'textarea', array('attr' => array("class" => 'xxlarge')))
+ ->add('slug')
->add('url')
- ->add('date', 'datetime', array('required' => false))
- ->add('imageFile', 'file')
- ->add('categories')
- ->add('users', 'textarea', array('attr' => array("class" => 'xxlarge')))
+ ->add('description', 'textarea', array('attr' => array("class" => 'input-xxlarge')))
+ ->add('imageFile', 'file', array('required' => false))
+ ->add('date', 'date', array('required' => false))
+ ->add('categories', null, array('required' => false))
+ ->add('users', 'textarea', array('required' => false, 'attr' => array("class" => 'input-xxlarge')))
->add('onFrontPage', 'checkbox', array('required' => false))
;
}
+ // @todo с sortable проблемы начиная со второй страницы
protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('slug')
->add('name')
- ->add('description')
->add('date')
;
}
public function setTemplates(array $templates)
{
- $templates['list'] = 'StfalconPortfolioBundle::list.html.twig';
+ $templates['list'] = 'StfalconPortfolioBundle:ProjectAdmin:list.html.twig';
parent::setTemplates($templates);
}
}
@@ -3,23 +3,16 @@
namespace Stfalcon\Bundle\PortfolioBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
-use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
-use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Response;
-use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
-
use Stfalcon\Bundle\PortfolioBundle\Entity\Project;
use Stfalcon\Bundle\PortfolioBundle\Entity\Category;
-use Stfalcon\Bundle\PortfolioBundle\Form\CategoryForm;
/**
- * CRUD categories. Services widget.
- *
- * @author Stepan Tanasiychuk <ceo@stfalcon.com>
+ * Category Controller
*/
class CategoryController extends Controller
{
@@ -32,23 +25,20 @@ class CategoryController extends Controller
* @return array
* @Route(
* "/portfolio/{slug}/{page}",
- * name="portfolioCategoryView",
+ * name="portfolio_category_view",
* requirements={"page" = "\d+"},
* defaults={"page" = "1"}
* )
* @Template()
*/
- public function viewAction(Category $category)
+ public function viewAction(Category $category, $page = 1)
{
- $knpPaginator = $this->get('knp_paginator');
- $paginator = $knpPaginator->paginate(
- $this->get('doctrine.orm.entity_manager')
- ->getRepository("StfalconPortfolioBundle:Project")
- ->getProjectsQueryForPagination($category->getId()),
- $this->getRequest()->get('page', 1) /*page number*/,
- 6 /*limit per page*/
- );
- $paginator->setUsedRoute('portfolioCategoryView');
+ $query = $this->get('doctrine.orm.entity_manager')
+ ->getRepository("StfalconPortfolioBundle:Project")
+ ->getQueryForSelectProjectsByCategory($category);
+
+ $paginator = $this->get('knp_paginator')->paginate($query, $page, 6);
+ $paginator->setUsedRoute('portfolio_category_view');
if ($this->has('application_default.menu.breadcrumbs')) {
$breadcrumbs = $this->get('application_default.menu.breadcrumbs');
@@ -58,7 +48,7 @@ public function viewAction(Category $category)
return array(
'category' => $category,
- 'paginator' => $paginator,
+ 'paginator' => $paginator, // @todo переименовать переменную
);
}
@@ -73,28 +63,13 @@ public function viewAction(Category $category)
*/
public function servicesAction(Category $category, $project = null)
{
+ // @todo помоему этот блок отключен
$categories = $this->get('doctrine.orm.entity_manager')
->getRepository("StfalconPortfolioBundle:Category")->getAllCategories();
return array('categories' => $categories, 'currentProject' => $project, 'currentCategory' => $category);
}
- /**
- * Show projects by category
- *
- * @param Category $category
- *
- * @return array
- * @Route("/admin/portfolio/category/{slug}/projects", name="portfolioProjectsByCategory")
- * @Template()
- */
- public function projectsAction(Category $category)
- {
- return array(
- 'category' => $category,
- );
- }
-
/**
* Ajax order projects
*
@@ -104,6 +79,8 @@ public function projectsAction(Category $category)
*/
public function orderProjects()
{
+ // @todo переименовать метод и роут
+ // @todo перенести сортировку проектов в админку
$projects = $this->getRequest()->get('projects');
$em = $this->get('doctrine')->getEntityManager();
foreach ($projects as $projectInfo) {
@@ -4,19 +4,14 @@
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
-use Symfony\Component\HttpFoundation\RedirectResponse;
-use Symfony\Component\HttpFoundation\Response;
-use Stfalcon\Bundle\PortfolioBundle\Form\ProjectForm;
-use Stfalcon\Bundle\PortfolioBundle\Entity\Project;
-use Stfalcon\Bundle\PortfolioBundle\Entity\Category;
-use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
+use Stfalcon\Bundle\PortfolioBundle\Entity\Project;
+use Stfalcon\Bundle\PortfolioBundle\Entity\Category;
+
/**
- * CRUD projects. Show users and nearby projects widget.
- *
- * @author Stepan Tanasiychuk <ceo@stfalcon.com>
+ * Project controller
*/
class ProjectController extends Controller
{
@@ -27,11 +22,13 @@ class ProjectController extends Controller
* @param string $projectSlug Slug of project
*
* @return array
- * @Route("/portfolio/{categorySlug}/{projectSlug}", name="portfolioCategoryProjectView")
+ * @Route("/portfolio/{categorySlug}/{projectSlug}", name="portfolio_project_view")
* @Template()
*/
public function viewAction($categorySlug, $projectSlug)
{
+ // @todo упростить когда что-то разрулят с этим PR https://github.com/sensio/SensioFrameworkExtraBundle/pull/42
+
// try find category by slug
$category = $this->_findCategoryBySlug($categorySlug);
@@ -43,7 +40,7 @@ public function viewAction($categorySlug, $projectSlug)
$breadcrumbs->addChild(
$category->getName(),
array(
- 'route' => 'portfolioCategoryView',
+ 'route' => 'portfolio_category_view',
'routeParameters' => array('slug' => $category->getSlug())
)
);
@@ -65,29 +62,29 @@ public function viewAction($categorySlug, $projectSlug)
public function nearbyProjectsAction($categorySlug, $projectSlug)
{
// try find category by slug
- $categorySlug = $this->_findCategoryBySlug($categorySlug);
+ $category = $this->_findCategoryBySlug($categorySlug);
// try find project by slug
- $projectSlug = $this->_findProjectBySlug($projectSlug);
+ $project = $this->_findProjectBySlug($projectSlug);
$em = $this->get('doctrine')->getEntityManager();
// get all projects from this category
$projects = $em->getRepository("StfalconPortfolioBundle:Project")
- ->getProjectsByCategory($categorySlug);
+ ->getProjectsByCategory($category);
// get next and previous projects from this category
$i = 0; $previousProject = null; $nextProject = null;
foreach ($projects as $p) {
- if ($projectSlug->getId() == $p->getId()) {
+ if ($project->getId() == $p->getId()) {
$previousProject = isset($projects[$i-1]) ? $projects[$i-1] : null;
$nextProject = isset($projects[$i+1]) ? $projects[$i+1] : null;
break;
}
$i++;
}
- return array('category' => $categorySlug, 'previousProject' => $previousProject, 'nextProject' => $nextProject);
+ return array('category' => $category, 'previousProject' => $previousProject, 'nextProject' => $nextProject);
}
/**
@@ -120,10 +117,9 @@ private function _findCategoryBySlug($slug)
private function _findProjectBySlug($slug)
{
$em = $this->get('doctrine')->getEntityManager();
-
- // try find project by slug
$project = $em->getRepository("StfalconPortfolioBundle:Project")
->findOneBy(array('slug' => $slug));
+
if (!$project) {
throw new NotFoundHttpException('The project does not exist.');
}
@@ -54,16 +54,16 @@ public function load(ObjectManager $manager)
$this->addReference('project-eprice', $eprice);
for ($i = 0; $i < 6; $i++) {
- $eprice = new Project();
- $eprice->setName('eprice.kz_' . $i);
- $eprice->setSlug('eprice-kz_' . $i);
- $eprice->setUrl('http://eprice.kz');
- $eprice->setDate(new \DateTime('now'));
- $eprice->setDescription('Comparison of the prices of mobile phones, computers, monitors, audio and video in Kazakhstan');
- $eprice->setOnFrontPage(0);
- $eprice->setOrdernum(2 + $i);
- $eprice->addCategory($manager->merge($this->getReference('category-development')));
- $manager->persist($eprice);
+ $example = new Project();
+ $example->setName('example.com_' . $i);
+ $example->setSlug('example-com_' . $i);
+ $example->setUrl('http://example.com');
+ $example->setDate(new \DateTime('now'));
+ $example->setDescription('As described in RFC 2606, we maintain a number of domains such as EXAMPLE.COM and EXAMPLE.ORG for documentation purposes. These domains may be used as illustrative examples in documents without prior coordination with us. They are not available for registration.');
+ $example->setOnFrontPage(0);
+ $example->setOrdernum(2 + $i);
+ $example->addCategory($manager->merge($this->getReference('category-development')));
+ $manager->persist($example);
}
$manager->flush();
}
View
@@ -9,7 +9,6 @@
/**
* Category entity. It groups projects in portfolio
*
- * @author Stepan Tanasiychuk <ceo@stfalcon.com>
* @ORM\Table(name="portfolio_categories")
* @ORM\Entity(repositoryClass="Stfalcon\Bundle\PortfolioBundle\Repository\CategoryRepository")
*/
@@ -55,7 +54,10 @@ class Category
/**
* @var Doctrine\Common\Collections\ArrayCollection
*
- * @ORM\ManyToMany(targetEntity="Stfalcon\Bundle\PortfolioBundle\Entity\Project", mappedBy="categories")
+ * @ORM\ManyToMany(
+ * targetEntity="Stfalcon\Bundle\PortfolioBundle\Entity\Project",
+ * mappedBy="categories", fetch="EXTRA_LAZY"
+ * )
* @ORM\OrderBy({"ordernum" = "ASC", "date" = "DESC"})
*/
private $projects;
Oops, something went wrong.

0 comments on commit 22a901a

Please sign in to comment.