A new entity was found through the relationship (No it wasn’t !)

If you notice such an error, even though the relationship that Doctrine complains about hasn’t changed and you’re selecting the fresh object from the db. Don’t need to persis here as suggested as it won’t help anyways as the object (in this case a User instance) is already in the DB, so it doesn’t need persisting.

Multiple non-persisted new entities were found through the given association graph:\n\n * A new entity was found through the relationship 'App\\Entity\\Trade#user' that was not configured to cascade persist operations for entity: Proxies\\__CG__\\App\\Entity\\User@00000000534bea8e000000001661e3c7. To solve this issue: Either explicitly call EntityManager#persist() on this unknown entity or configure cascade persist this association in the mapping for example @ManyToOne(..,cascade={\"persist\"}). If you cannot find out which entity causes the problem implement 'App\\Entity\\User#__toString()' to get a clue

The solution in my case was to clear the entity manager, which causes all the entities currently managed by the Entity Manager to be detached and then start from scratch by selecting the entities again.

        #1 clear the Entity Manager here 
        $this->em->clear();

        #2 use the id to find the trade $this->tradeId
        $trade = $this->tradeRepository->find($this->tradeId);
        $trade->setStatus("tradeCreated");
        
        #3 and now Doctrine is not complaining when saving the entity
        $this->tradeRepository->save($trade);

reCaptcha3 and timeout solution

If reCaptcha3 token is generated on page load then it’s not practical as it times out in a few minutes, therefore the form submission will fail. Better to generate it on form submission like that.

var webQueryForm = $('#webQuery');
webQueryForm.submit(function(event) {
  e.preventDefault();
  grecaptcha.execute('MYSITEKEY(PUBLIC)', {
     action: 'contact'
     }).then(function(token) {
     $('#recaptchaToken').val(token);
    webQueryForm.submit();
  });
});

source: https://jsfiddle.net/skobaljic/rL6fux5w/2/

Gitlab – git pull with ssh key

  1. Clone the SSH repo

git clone git@gitlab.com:YourUsername/YourRepoName.git

(this will copy the repo into a new folder YourRepoName)

2. Alterantively to 1 if you have already copied the HTTPS version of the repo

check which version you have with “git remote -v”

$ git remote -v
origin git@gitlab.com:YourUsername/YourRepoName.git (fetch)
origin git@gitlab.com:YourUsername/YourRepoName.git (push)

if you have the repo that starts with git@… it’s already the SSH version if you have https:// then do following to change it to ssh version:

git remote set-url origin git@gitlab.com:YourUsername/YourRepoName.git

3. Create folders and files that store your public key

$ mkdir .ssh && chmod 700 .ssh
$ touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys

4. Copy you public key to authorized_keys file

Copy it from ~/.ssh/id_rsa.pub (or whichever name you’ve given to it)

5. Have a ssh config file for Gitlab

cat ~/.ssh/config 
Host gitlab.com
    Preferredauthentications publickey
    IdentityFile ~/.ssh/id_rsa
    IdentitiesOnly yes

7. Add your SSH pub key in Gitlab for this project

https://subscription.packtpub.com/book/application-development/9781783986842/2/ch02lvl1sec20/adding-your-ssh-key-to-gitlab

6. Now you’ll be able to do “git pull” without entering login and password for https version

User experience – Busuu, part 2

Hi there!

Recently I have spent less time developing Busuu, than using it. I will walk you through positive experiences and “To improve” here.

What I like about the app

  1. In general the app gives so much value, that for a serious learners it’s worth a lot more that what it’s being sold at. Essentially giving you a classroom quality experience with full flexibility of when and how to learn. Having teachers on board and the course structured in a similar way is something that could be communicated more to the potential customers. After all this is what everyone says after having some experience with the Owl and Busuu – it feels as if you were in the class, can see the teachers speaking, there is logic to the lessons and on the other hand “your elephant is pink” standard. I would say “make the marketing hay whlie the sun shines” as I am sure they’re working on improving this image relentlessly.

2. Summaries

These kind of summaries above. Super useful, I am a kind of learner that like to write things down (hence I liked Confluence when I was at Busuu ;)) So I literally write stuff down to my notebook.

3. Social element – especially writing and having a possiblity to have some feedback. Also replying to these comments as it’s nice to thank them for their help.

4. Lack of bots – thanks Adam!

5. Live and group lessons – that’s for me to discover once I have some more courage to speak in Spanish.

To improve

I have gathered a few things that I see could be improved in the user experience. I would be so grateful if these could be implemented!

Did one list on Busuu’s confluence before and now, when focusing on learning Spanish a lot more and after buying my premium membership (Anais, used the discount you set up, they work nicely 😉 I can tell you what would make the learning experience much better in my eyes.

Problem: Web app has minutes, Android app has stars.

Solution: Have both shown in the mobile app and in the web app

2.

Problem: I keep getting transferred to the lesson in the past (57 – after switching in the left menu from “Review” to “Lessons” for instance). The second icon with the lightning is an animation. As you can see I have

Solution: if this can’t be fixed in the app, let the users mark the lesson as “completed”. They might want to skip some lessons anyways and use this feature.

3.

Problem: As a web app, arriving at the “Lessons” page I don’t know what’s the unit in the lesson I should be continuing with. The colours here (blue – completed, orange – not started yet) or does it refer to premium – orange goes with the crown?)

Solution: Mark, using a universally recognisable method that a unit has been completed and which one I can continue with? Blue and gray to make it obvious.

4.

Problem: As a premium member I don’t need to see what’s premium and what’s not – it’s adding to the UX confusement with Point 3. Same image as above here.

Solution: Show the free/premium units only to free users

5.

Problem: Make it possible to see the progress on individual days (How many minutes did I spent learning yesterday?). It’s much easier for a learner, when they are trying to stick to a routine to trade one day’s minutes for another in order to catch up if they skipped one day.

Solution: by tapping in the Study Plan on day icons, I should see how many minutes/stars I did each day.

6.

Problem: Study plan is listed as an important feature. The biggest advantage is in the knowing on what day in the future I will have reached my goal. Yet the study plan is limited to 30 minutes per day. What if I spend more time?

Solution: Make the tool do what it “says on the packaging” and allow for more than 30 minutes per day.

Summary

Again I wish Busuu lots of success as it deserves it. Keep working and providing the value. After all it’s not that much common in the app business 🙂

JavaScript – quick tips #1

1. Console logging done right

var  images = {
  'img1': 'http://foo.bar',
  'text1': 'Foo',
}

var  texts = {
  'text1': 'Lorem',
}

// Colored text in the console: 
console.log('%c Images and Texts:', 'color: orange; font-weight: bolder;')
// View the properties in a table (common properties grouped together)
console.table([images, texts])

2. Timer for code

// start timer
console.time('loooop');

let i = 0;
while(i < 10000000) { i++ }

// end timer
console.timeEnd('loooop');

3. Tracing function calls

When we want to see where the code was trigerred it shows where the code was defined (VM227:1) and where it was called (VM227:3) and (VM227:4).

const doSayHello = () => console.trace('saying hello')

doSayHello();
doSayHello();

4. How to display properties of an object in a more concise way

STANDARD WAY:

const vehicle = {
   'fuel': 'diesel',
   'milage': '100000 km',
   'upholstery': 'leather',
}

function viewVehicleProps(vehicle) {
   return `The vehicle runs on ${vehicle.fuel}, the upholstery is ${vehicle.upholstery} and it has run for ${vehicle.milage}`;
}

BETTER – OPTION 1:

In the argument of the function you can just specify the properties of an object and exclude the repeatable name from the inside of it.

const vehicle = {
   'fuel': 'diesel',
   'milage': '100000 km',
   'upholstery': 'leather',
}

function viewVehicleProps({fuel, milage, upholstery}) {
   return `The vehicle runs on ${fuel}, the upholstery is ${upholstery} and it has run for ${milage}`;
}

BETTER – OPTION 2:

let vehicle = {
   'fuel': 'diesel',
   'milage': '100000 km',
   'upholstery': 'leather',
}

function viewVehicleProps(vehicle) {
   let {fuel, milage, upholstery} = vehicle;
   return `The vehicle runs on ${fuel}, the upholstery is ${upholstery} and it has run for ${milage}`;
}

Does a service of correcting essays counts as supplying digital services to consumers in the EU?

Found the set of rules businesses providing services over the Internet. But it seems that correcting essays might not be encompassed by this law. But it depends, if the course mentioned here is prepared beforehand and not a bespoke work of the teacher.

https://www.gov.uk/guidance/the-vat-rules-if-you-supply-digital-services-to-private-consumers#businesses-established-outside-the-eu

Custom style for one field – turning a textarea into a rich text editor Quill with Symfony Forms and Twig

I have a form rendered with {{ form(form }} so a standard way of rendering using Form component from Symfony. Now, we want to add a Rich Text Editor (Quill in this case) and add a possibility to attach functionality to chosen textareas. The form now, renders nicely thanks to inbuilt layouts that twig already supports so that form elements are styled with different versions of Bootstrap for instance thanks to Form Themes. So in the end the form is going to look like that (Essay text – Quill enhanced).

First have a look at your Twig config:

config/packages/twig.yaml

twig:
    default_path: '%kernel.project_dir%/templates'
    debug: '%kernel.debug%'
    strict_variables: '%kernel.debug%'
    number_format:
        thousands_separator: ','
    form_themes: ['bootstrap_4_layout.html.twig']

You can add a default theme that’s compatible with your front framework like Bootstrap 4 (in the config above it’s already there)

form_themes: ['bootstrap_4_layout.html.twig']

Grap Quill from github – BSD licencesed rich text editor.

This paragraph from Symfony docs exaplains how to modify only one form element in twig, instead of using form_row or form_label, form_error and form_widget for every element of the form and editing the whole html for the form.

But most importantly read this article about new feature in Symfony 4.3 which makes it simpler to prepare a name of the twig block that you want to override.

See how essayText has block_prefix called essay_text and then…

the new definition of the twig block that we can add that will have this name essay_text_widget. Oh and we’re modifying only widget, not error and label part.

templates/form/fields.html.twig

{% block essay_text_widget %}
    <div class="form-group">

        <textarea data-quilljs
                  id="essay_essayText"
                  name="essay[essayText]"
                  required="required" rows="10"
                  class="form-control">

        </textarea>
    </div>
{% endblock %}

So now in the twig template where we’re rendering the form it still stays simple:

{% form_theme form 'form/fields.html.twig' %}

{{ form(form) }}

We’re updating the form theme with our new, customised definition that we put into form/fields.html.twig and then rendering the whole form with {{ form(form) }}

One piece of code to apply Quill to the textareas. Have a look inside. It’s short and simple.

https://github.com/tangien/quilljs-textarea

How to initialize Quill with modules, what are the modules?

https://quilljs.com/docs/modules/toolbar/

Symfony bundles that allow db records version control and audit

  1. Doctrine Audit Bundle
    This one is maintained and is compatible with Symfony 5
    https://packagist.org/packages/damienharper/doctrine-audit-bundle

    Demo bundle here.
  1. DataDogAuditBundle
    https://github.com/DATA-DOG/DataDogAuditBundle
  1. knplabs/doctrine-behaviors

    Maintained.https://github.com/KnpLabs/DoctrineBehaviors
  2. antishov/doctrine-extensions-bundle

    (fork of 5)
  3. Gedmo loggable

    (but currently no Symfony 5 support) https://symfony.com/doc/master/bundles/StofDoctrineExtensionsBundle/index.htmlDocs and example here.

Design a site like this with WordPress.com
Get started