Skip to content

Commit

Permalink
bug fix for services, CCC-83
Browse files Browse the repository at this point in the history
  • Loading branch information
fozeek committed Dec 18, 2013
1 parent 72d5ac4 commit 6b3a689
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 28 deletions.
18 changes: 7 additions & 11 deletions src/PlaygroundGallery/Controller/Admin/GalleryAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public function editAction()
$data = $this->getRequest()->getPost()->toArray();
if($form->isValid() && $this->checkValidUrl($data['url'])) {
$media = $this->getMediaService()->edit($data, $media);

if($media) {
return $this->redirect()->toRoute('admin/playgroundgallery');
}
Expand Down Expand Up @@ -208,9 +209,9 @@ public function createCategoryAction() {
$form->setAttribute('method', 'post');

if ($this->getRequest()->isPost()) {
$contact = $this->getCategoryService()->create($this->getRequest()->getPost()->toArray());
$category = $this->getCategoryService()->create($this->getRequest()->getPost()->toArray());

if($contact) {
if($category) {
return $this->redirect()->toRoute('admin/playgroundgallery');
}
else {
Expand Down Expand Up @@ -239,16 +240,11 @@ public function editCategoryAction() {
$form->bind($category);

if ($this->getRequest()->isPost()) {
$form->bind($this->getRequest()->getPost());

$data = $this->getRequest()->getPost()->toArray();
if($form->isValid()) {
$category = $this->getCategoryService()->edit($data, $category);
if($category) {
return $this->redirect()->toRoute('admin/playgroundgallery');
}
else {
$this->flashMessenger()->setNamespace('playgroundgallery')->addMessage('Error');
}
$category = $this->getCategoryService()->edit($data, $category);
if($category) {
return $this->redirect()->toRoute('admin/playgroundgallery');
}
else {
$this->flashMessenger()->setNamespace('playgroundgallery')->addMessage('Error');
Expand Down
3 changes: 0 additions & 3 deletions src/PlaygroundGallery/Entity/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,6 @@ public function populate($data = array())
if (isset($data['description']) && $data['description'] != null) {
$this->description = $data['description'];
}
if (isset($data['category']) && $data['category'] != null) {
$this->category = $data['category'];
}
}


Expand Down
42 changes: 36 additions & 6 deletions src/PlaygroundGallery/Service/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class Category extends EventProvider implements ServiceManagerAwareInterface
*/
protected $options;

/**
* @var categoryForm
*/
protected $categoryForm;

/**
*
* This service is ready for create a category
Expand All @@ -46,7 +51,7 @@ public function create(array $data)
$category->populate($data);
$entityManager = $this->getServiceManager()->get('playgroundgallery_doctrine_em');

$form = $this->getServiceManager()->get('playgroundgallery_category_form');
$form = $this->getCategoryForm();

$this->addCategoryParent($category, $data);

Expand Down Expand Up @@ -77,7 +82,7 @@ public function edit(array $data, $category)
{
$entityManager = $this->getServiceManager()->get('playgroundgallery_doctrine_em');

$form = $this->getServiceManager()->get('playgroundgallery_category_form');
$form = $this->getCategoryForm();

$this->addCategoryParent($category, $data);

Expand All @@ -87,9 +92,7 @@ public function edit(array $data, $category)

$category->setName($data['name']);

if (!$form->isValid()) {
return false;
}

$category = $this->getCategoryMapper()->update($category);

return $category;
Expand Down Expand Up @@ -140,7 +143,7 @@ public function getCategoryMapper()
*/
public function setCategoryMapper($categoryMapper)
{
$this->categoryMapper = $categoryMappers;
$this->categoryMapper = $categoryMapper;

return $this;
}
Expand Down Expand Up @@ -194,4 +197,31 @@ public function setServiceManager(ServiceManager $serviceManager)

return $this;
}

/**
* getCategoryForm
*
* @return categoryForm
*/
public function getCategoryForm()
{
if (null === $this->categoryForm) {
$this->categoryForm = $this->getServiceManager()->get('playgroundgallery_category_form');
}

return $this->categoryForm;
}

/**
* setCategoryForm
* @param PlaygroundGallery\Form\Category $categoryForm
*
* @return PlaygroundGallery\Service\Category this
*/
public function setCategoryForm($categoryForm)
{
$this->categoryForm = $categoryForm;

return $this;
}
}
45 changes: 37 additions & 8 deletions src/PlaygroundGallery/Service/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ class Media extends EventProvider implements ServiceManagerAwareInterface
*/
protected $serviceManager;

/**
* @var mediaForm
*/
protected $mediaForm;

/**
* @var categoryMapper
*/
Expand All @@ -52,7 +57,7 @@ public function create(array $data)
$media->populate($data);
$entityManager = $this->getServiceManager()->get('playgroundgallery_doctrine_em');

$form = $this->getServiceManager()->get('playgroundgallery_media_form');
$form = $this->getMediaForm();

$this->addCategory($media, $data);

Expand Down Expand Up @@ -83,17 +88,14 @@ public function edit(array $data, $media)
{
$entityManager = $this->getServiceManager()->get('playgroundgallery_doctrine_em');

$form = $this->getServiceManager()->get('playgroundgallery_media_form');
$form = $this->getMediaForm();

$this->addCategory($media, $data);

$form->bind($media);

$form->setData($data);
$media->setDescription($data['description']);
$media->setName($data['name']);
$media->setCredit($data['credit']);
$media->setUrl($data['url']);
$media->populate($data);

if (!$form->isValid()) {
return false;
Expand Down Expand Up @@ -137,7 +139,7 @@ public function getMediaMapper()
*/
public function setMediaMapper($mediaMapper)
{
$this->mediaMapper = $mediaMappers;
$this->mediaMapper = $mediaMapper;

return $this;
}
Expand Down Expand Up @@ -207,7 +209,7 @@ public function getCategoryMapper()
}

/**
* setCompanyMapper
* setCategoryMapper
* @param CategoryMapper $companyMapper
*
* @return PlaygroundGallery\Entity\Category Category
Expand All @@ -218,4 +220,31 @@ public function setCategoryMapper($categoryMapper)

return $this;
}

/**
* getMediaForm
*
* @return mediaForm
*/
public function getMediaForm()
{
if (null === $this->mediaForm) {
$this->mediaForm = $this->getServiceManager()->get('playgroundgallery_media_form');
}

return $this->mediaForm;
}

/**
* setMediaForm
* @param PlaygroundGallery\Form\Media $mediaForm
*
* @return PlaygroundGallery\Service\Media this
*/
public function setMediaForm($mediaForm)
{
$this->mediaForm = $mediaForm;

return $this;
}
}

0 comments on commit 6b3a689

Please sign in to comment.