add personalisation logo

This commit is contained in:
aina-esokia
2018-08-29 15:11:04 +04:00
parent 7a71da5d7e
commit 5dba9f64dd
7 changed files with 91 additions and 33 deletions

View File

@@ -14,6 +14,7 @@ use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Controller\Controller;
use Alchemy\Phrasea\Core\Configuration\PropertyAccess;
use Alchemy\Phrasea\Core\Configuration\RegistryFormManipulator;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
class SetupController extends Controller
@@ -61,4 +62,15 @@ class SetupController extends Controller
'form' => $form->createView(),
]);
}
public function sendPersonaliseLogo(Request $request)
{
if(null !== $blob = $request->request->get('fileToUpload')){
$result = $this->app->getApplicationBox()->write_application_logo($this->app['filesystem'], $blob);
return new JsonResponse($result);
}
return new JsonResponse('No file send');
}
}

View File

@@ -47,6 +47,9 @@ class Setup implements ControllerProviderInterface, ServiceProviderInterface
->bind('setup_display_globals')
->method('GET|POST');
$controllers->post('/send-logo', 'controller.admin.setup:sendPersonaliseLogo')
->bind('setup_send_personalize_logo');
return $controllers;
}
}

View File

@@ -56,7 +56,7 @@ class GeneralFormType extends AbstractType
'attr' => ['min' => -1],
'constraints' => new GreaterThanOrEqual(['value' => -1]),
]);
$builder->add('personalize-logo-choice', new PersonalisationLogoForm(), [
$builder->add('personalize-logo-choice', new PersonalisationLogoFormType(), [
'label' => 'Design of personalization logo section',
'attr' => [
'id' => 'personalize-logo-container'

View File

@@ -13,28 +13,29 @@ namespace Alchemy\Phrasea\Form\Configuration;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
class PersonalisationLogoForm extends AbstractType
class PersonalisationLogoFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('originalChoiceInput', 'choice', [
$builder->add('logoChoice', 'choice', [
'label' => false,
'choices' => ['original' => 'original-choice-label'],
'choices' => [
'original' => 'original logo',
'personalize' => 'personalize logo'
],
'expanded' => true,
'multiple' => false,
]);
$builder->add('personaliseChoiceInput', 'choice', [
'label' => false,
'choices' => ['personalise' => 'personalise-choice-label'],
'expanded' => true,
]);
$builder->add('personalizeLogoInput', 'file', [
'label' => false,
]);
$builder->add('logoChoice', 'hidden', [
$builder->add('personalizeFile', 'hidden', [
'label' => false,
]);
}
public function getName()

View File

@@ -95,6 +95,23 @@ class appbox extends base
return $this;
}
public function write_application_logo(Filesystem $filesystem, $blob)
{
$logo_path = $this->app['root.path'] . '/www/custom/minilogos/personalize_logo.png';
$data = str_replace('data:image/png;base64,', '', $blob);
$data = str_replace(' ', '+', $data);
$data = base64_decode($data);
try{
$filesystem->dumpFile($logo_path, $data);
}catch(\Exception $e){
return $e->getMessage();
}
return 'success';
}
/**
*
* @param collection $collection