Skip to content

Commit

Permalink
Merge pull request #9 from sumocoders/switch-to-doctrine-and-symfony-…
Browse files Browse the repository at this point in the history
…form

Switch to doctrine and symfony form
  • Loading branch information
bjorvack authored Jan 17, 2017
2 parents e08a675 + c32c459 commit aafdad8
Show file tree
Hide file tree
Showing 45 changed files with 1,736 additions and 1,602 deletions.
27 changes: 27 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# @see http://editorconfig.org/
#

root = true

[*.{js,php,py,yml}]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

[*.{html,rb,tpl,twig,xml}]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true

#
# Following languages aren't used at the moment in Fork CMS, but just in case.
# (for instance: Capistrano is used in a lot of projects for deployment)
#
# [*.{py,rb}]
105 changes: 30 additions & 75 deletions src/Backend/Modules/Partners/Actions/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,85 +2,40 @@

namespace Backend\Modules\Partners\Actions;

/*
* This file is part of Fork CMS.
*
* For the full copyright and license information, please view the license
* file that was distributed with this source code.
*/

use Backend\Core\Engine\Base\ActionAdd as BackendBaseActionAdd;
use Backend\Core\Engine\Form as BackendForm;
use Backend\Core\Engine\Language as BL;
use Backend\Core\Engine\Model as BackendModel;
use Backend\Modules\Partners\Engine\Model as BackendPartnersModel;
use Frontend\Modules\Partners\Engine\Model as FrontendPartnersModel;
use Symfony\Component\Filesystem\Filesystem;

/**
* This action will add a widget to the partners module.
*
* @author Jelmer Prins <[email protected]>
*/
class Add extends BackendBaseActionAdd
use Backend\Core\Engine\Base\ActionAdd;
use Backend\Core\Engine\Model;
use Backend\Core\Language\Language;
use Backend\Modules\Partners\Domain\Partner\PartnerType;
use Backend\Modules\Partners\Domain\Partner\Command\CreatePartner;
use Backend\Modules\Partners\Domain\Widget\Command\CreateWidget;
use Backend\Modules\Partners\Domain\Widget\WidgetType;

class Add extends ActionAdd
{
/**
* Execute the action
*/
public function execute()
{
parent::execute();

$this->loadForm();
$this->validateForm();

$this->parse();
$this->display();
}

/**
* Load the form
*/
private function loadForm()
{
$this->frm = new BackendForm('add');
$this->frm->addText('name', null, 255, 'inputText title', 'inputTextError title')->setAttribute('required');
}

/**
* Validate the form
*/
private function validateForm()
{
if ($this->frm->isSubmitted()) {
$this->frm->cleanupFields();

// validation
$this->frm->getField('name')->isFilled(BL::err('NameIsRequired'));

// no errors?
if ($this->frm->isCorrect()) {
$item['name'] = $this->frm->getField('name')->getValue();
$item['id'] = BackendPartnersModel::insertWidget($item);

//create img dir
$fs = new Filesystem();
$fs->mkdir(
FRONTEND_FILES_PATH . '/' . FrontendPartnersModel::IMAGE_PATH . '/' . $item['id'] . '/48x48'
);

// everything is saved, so redirect to the overview
$this->redirect(
BackendModel::createURLForAction(
'edit',
null,
null,
array(
'id' => $item['id']
)
)
);
}
$createWidget = new CreateWidget();
$form = $this->createForm(WidgetType::class, $createWidget);
$form->handleRequest($this->get('request'));
if (!$form->isValid()) {
$this->tpl->assign('form', $form->createView());
$this->display();

return;
}
$this->get('command_bus')->handle($form->getData());

return $this->redirect(
Model::createURLForAction(
'Index',
null,
null,
[
'report' => 'added',
'var' => $createWidget->title,
]
)
);
}
}
117 changes: 0 additions & 117 deletions src/Backend/Modules/Partners/Actions/AddPartner.php

This file was deleted.

72 changes: 17 additions & 55 deletions src/Backend/Modules/Partners/Actions/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,33 @@

namespace Backend\Modules\Partners\Actions;

/*
* This file is part of Fork CMS.
*
* For the full copyright and license information, please view the license
* file that was distributed with this source code.
*/
use Backend\Core\Engine\Base\ActionDelete;
use Backend\Core\Engine\Model;
use Backend\Modules\Partners\Domain\Widget\Widget;
use Backend\Modules\Partners\Domain\Widget\Command\DeleteWidget;

use Backend\Core\Engine\Base\ActionDelete as BackendBaseActionDelete;
use Backend\Core\Engine\Model as BackendModel;
use Backend\Modules\Partners\Engine\Model as BackendPartnersModel;
use Frontend\Modules\Partners\Engine\Model as FrontendPartnersModel;
use Symfony\Component\Filesystem\Filesystem;

/**
* This action will delete a partner
*
* @author Jelmer Prins <[email protected]>
*/
class Delete extends BackendBaseActionDelete
class Delete extends ActionDelete
{
/**
* Execute the action
*/
public function execute()
{
$this->id = $this->getParameter('id', 'int');
$widget = $this->get('partners.repository.widget')->find(
$this->getParameter('id', 'int')
);

// does the item exist
if ($this->id == null || !BackendPartnersModel::widgetExists($this->id)) {
$this->redirect(
BackendModel::createURLForAction(
'index',
null,
null,
array(
'error' => 'non-existing'
)
)
);
if (!$widget instanceof Widget) {
return $this->redirect(Model::createURLForAction('Index', null, null, ['error' => 'non-existing']));
}
$this->get('command_bus')->handle(new DeleteWidget($widget));

// get data
$this->record = BackendPartnersModel::getWidget($this->id);

// delete item
BackendPartnersModel::deleteWidget($this->record['id'], $this->record['widget_id']);

// delete files
$fs = new Filesystem();
$fs->remove(
FRONTEND_FILES_PATH . '/' . FrontendPartnersModel::IMAGE_PATH . '/' . $this->id
);

// item was deleted, so redirect
$this->redirect(
BackendModel::createURLForAction(
'index',
return $this->redirect(
Model::createURLForAction(
'Index',
null,
null,
array(
[
'report' => 'deleted',
'var' => urlencode(
$this->record['name']
)
)
'var' => $widget->getTitle(),
]
)
);
}
Expand Down
Loading

0 comments on commit aafdad8

Please sign in to comment.