Solution for using DatePickers on forms in Yii2

Sometimes in web software applications we need to collect dates such as a start date or end date using forms. In this article I will be using the Kartik DatePicker widget which can be found here …

http://demos.krajee.com/widget-details/datepicker

For the purposes of this article a master Model will need to be created. I discussed how to create master Models and Controllers in the following article …

Create a master Model and Controller in Yii2

So based on the master Model now being created the article can continue. Add the field to the form using code similar to this. Include the plugin in the form …

Add the field to the form …

In the master Model 2 methods needed to be created …

And …

These methods can be called to save the “date” data to the database from any of the child Models. The best place to call the methods would be in the “beforeSave” and “afterFind” methods as follows …

And …

Depending on how you have setup the validations for the “date” attribute you may need to run the “saveDateFormat” and “dateFormat” methods in the “beforeValidate” and “afterValidate” methods as well as the “beforeSave” and “afterFind”.

This depends on whether your validations are formatting the date as the date would be saved to the database or validating against the format the date appears on the form.

If your validations validate against the format the date saves to the database then calling “saveDateFormat” and “dateFormat” methods in the “beforeValidate” and “afterValidate” methods will not be needed.

I generally setup my validations so I do not need to run the “saveDateFormat” and “dateFormat” methods in the “beforeValidate” and “afterValidate” methods only through the “beforeSave” and “afterFind” methods.

Using the above code you can implement multiple datepickers on the same form or across different forms. Follow the same logic, add the field or fields to the form and call the “saveDateFormat” and “dateFormat” methods from the child Model.

I want employees who are emotionally invested in the success of my business

The title of this article was a statement I read recently in an article on the web. There are lot of articles of this nature on the web so the topic is quite recognised. A lot of these articles mix into other subjects, one of those subjects being money.

The title of the topic basically becomes …

I want employees who are emotionally invested in making my company lots of money but I only want to pay them an average or below average salary. Who the hell is going to be emotionally invested that much in the success of your company unless you make it worth their while?

The same people who are sprouting this garbage are the same people who state “do not work for money, work for success” or something of a similar nature. The kind of success these employers are expecting are what I call “life work” success.

To explain, “life work” is something that a lot of people will do in there spare time unless they are lucky enough to be doing it full time. The people who are doing “life work” are people who invent something groundbreaking or write one of the best novels of the century.

George R. R. Martin the person who wrote Game of Thrones which is now a huge success spent years and years of his life writing the novel. This is not something that he is just going to do for some company for an average salary and most likely this is not something he going to do for any company no matter the salary.

When people talk about not working for the money and working for success, this is what they are talking about. It is not something that can be transfered to Uncle Bobs Print Business. This is what Uncle Bob is expecting however and all the people spouting the above garbage, he is wanting the “life work” of someone like George R. R. Martin for the peanuts he is paying him to work for his local print shop.

Somewhere along the line these employers have mixed “life work” and “everyday work” together. They want the benefits of someones “life work” but they cannot have it.

So lets take it a level down. Lets say Uncle Bob is not expecting the “life work” of some individual but is just wanting the same level of emotional investment he himself puts into his business. Right OK, Uncle Bob, how much are you going to have to pay that employee to put in the same level of effort as yourself?

To get the employee emotionally invested to that level he is going to have be like yourself. He is going to have to have a similar level of shares in the business as yourself or alternatively a wage that reflects that many shares.

Uncle Bob wants an employee who will do 100% high standard work, all the time. An employee who will stay late into the night most nights, if required. An employee who will pitch in to help with the administrative and accouting areas of the business after the normal days workload is complete. To expect this level of employee and get this level of employee at an average or below wage is unlikely to happen.

“According to The Intelligence Group, 64% of Millennials would rather earn $40,000 a year at a job they love than $100,000 a year at a job they find unfulfilling. That’s a pretty significant statistic.”

I read the following on a website preaching about the emotional investment of employees. The above in a way kind of backfires on itself because what kind of job are employees most likely to find “unfulfilling”, the kind of jobs where Uncle Bobs are wanting a high level of emotional investment i.e. staying late, high standards without fail, helping into admin / account areas of business after hours.

The exact kind of unfulfilling roles are the exact kind of roles that employers in this article are wanting their employees to invest in. So I am not sure what exactly the above quoted statement is getting at? What it seems to be implying is that Uncle Bob can get an emotionally invested employee who is interesting in making his business a success and doing a load of extra tasks to make his business a success for a 60% paycut.

Infact the opposite is the case, Uncle Bob generously agreed to pay said employee $100,000 a year, said employee got fed up with being expected to invest so much of himself into the business so quit the job and took a regular $40,000 year job where so much investment was not required.

I personally believe that companies can get emotionally invested employees. However to get the level of emotional investment the employer requires, shares would have to given to the employee or a wage that reflects that many shares within the company. Obviously the company has to be quite profitable as well as no one is going to invest in the company if it is only making £10,000 profit. The shares and wage reflective of the shares would then not be worth it.

To me it is just basic common sense, if you want an employee to be as emotionally invested as yourself then the “real” incentive has to be there. I think there is general problem in that the business owner should not be expecting the same level of emotional investment from his employees as what he himself has in his own business.

Tips for clients when choosing a web development company

A while back I wrote a post about tips for freelancers …

http://www.jamesbarnsley.com/site/2016/11/27/tips-for-freelancers/

My goal at the time was to later write an article on tips for clients choosing a web development company. I thought at the time this would be a straightforward article to write but the more I thought about it the less straightforward it become.

Some typical indicators to decide whether a company is worth choosing could be as follows, How many employees does the company have? Are the companies premises any good? How long the company has been in business? Does the company have a decent looking website?

The majority of the above indicators are really indicators as to how well the business is doing. A lot of people will except that if the final product looks and feels right and it works then they are happy with the final product. With a large number of people accepting this as the basic premise most businesses can survive for a long time on this premise.

So what is it I am getting at here? In short, it is the underlying code powering the web development project. It is this area that as the client you will have no ability to judge without programming experience.

Neither did any of the previous clients of the long standing businesses, so the business may be big, the business may have been around for a long while but this does not mean that either you or the previous clients ever got a good product in terms of the code powering the web development project.

How the product looks and to some extent whether the product works or not is merely a coat of paint over the real engine powering the web development product.

A Ford car can look and work right, a Rolls Royce car can look and work right but both have huge differences in the price tag. How do you know whether you are getting a Ford or a Rolls Royce? The quality of the components? In a web development project whilst some of the components may stand out such as the design, some of the components do not stand out i.e. the code.

This article has been born from observing different web development projects with different qualities of code being sold at vastly different prices. The higher priced projects do not nessacarily equate to higher quality code although the project may be of a better quality in other areas.

As a client how can you ensure you are getting quality code? I have thought about this and I am not sure there really is an answer. You could get a programmer contact or external company to inspect the code but then how can you be sure that the external company is any good at programming code, especially since the same applies to the external company which applies to the primary company?

Conclusion
As a client without programming experience maybe it should be excepted that if the company can produce a product which “looks good” and “works right” then the company is acceptable. The quality of the code is hard to determine for the general client and getting the code verified by a third party simply means you have transfered the trust from the primary company to the external company.

Yii 2 User Permission using matchCallback

As a web software developer I sometimes need to implement some kind of user permissions in the web applications that I build. The Yii 2 framework which I currently use has a built in system for doing just this however for applications that need a more lightweight user permission system the Yii 2 framework has introduced a method which was not available in the Yii 1 framework that can be used to easily build lightweight user permissions and that method is “matchCallback”.

Both Yii 1 and Yii 2 have a user permissions system named RBAC. In Yii 1 RBAC is implemented by writing code to define the user permissions, this code then populates the database tables with the user permissions. The user permissions are then applied to controller methods via more code known as access rules.

User permissions can also have what is known as a “bizRule”, a “bizRule” is an additional piece of code executed with the user permission that needs to evaluate to true in order for the user permission to be true. This can be used to implement checks to see if the record being displayed on the page is owned by the user trying to access the page as well as various other checks. The “bizRule” code is stored in the database along with the user permission.

One of the differences between the Yii 2 implementation of RBAC and the Yii 1 version is that the Yii 2 “bizRule” code is stored in code files and not the database. This makes more sense to me as the “bizRule” code is kept alongside the other code in the frameworks, models, controllers, views etc.

Infact it makes so much sense that during the later stages of using the Yii 1 framework I actually just stored class / function references in the “bizRule” code and wrote my real “bizRule” alongside the rest of framework code. Essentially implementing my own version of what Yii 2 covers as standard.

As mentioned above Yii 2 now implements a method called “matchCallback”. This means for web applications requiring simple user permissions RBAC is not needed as the “matchCallback” can be used to define the “bizRule” directly in the access rules …

So as shown above for web applications only requiring simple user permissions, the access rules are all that are needed.

Technical questions on interviews? High standards?

So I have been to a number of interviews now where I have had to answer technical questions and do technical tests. The technical questions are of a high standard and can go deep into the principles of object orientated programming. What baffles me is when I ask to look at some of these companies codebases the codebase is a mess, even the interviewers have admitted that their own codebase is a mess occasionally.

I am talking functions with over a hundred lines of code in them, huge code files, code copied from one place to another with just a couple of minor changes, no consistency in naming conventions, if “classes” where used no real thought about true object orientation was attempted and the class was used just as a place to put some code.

Now the company may state they have high standards during the interview process to weed out the candidates who do not do well in the tests. However this makes no sense for a couple of reasons …

  1. True candidates who do well on the tests may not want to work on such a codebase. Even if the candidate who did well on the tests did want to work with such a codebase how can the candidate who did well on the tests adapt to such a codebase? All the candidates who did well on the tests can do with such a codebase is to follow what is already there for the most part.
  2. Companies with such a codebase do not want candidates who do well on the tests, the companies may claim they do but when it comes down to it the candidates suggestions for improving the codebase will not be taken seriously. Companies with codebases like the above suggested do not care whether someone can code the system in a more efficient and effective way, they just want someone who can work with the codebase they currently have.

Please note, I am not saying there is anything wrong with having different standards of code. I can adapt to different codebases and different standards of code infact adapting to what is there already is probably the best way of working with the codebase. I am merely wondering …

Why the high level technical questions and tests in the interview?

Who knows? I most certainly do not. None of the principles asked during the interview is applied to the companies codebase so why do candidates need to go through these tests and demonstrate such principles.

Earlier in the writing of this article you may have thought I was being harsh and judgemental when I was talking about the mess codebase. Like I say I am not bothered about the mess codebase if the mess codebase is already there and that is what the company has.

Sometimes codebases can become a mess if multiple people have worked on the project and there is no one there to really hold the architecture of the project together. I am not being judgemental in a harsh way, what I am arguing is why hold employees to high standards in interviews when it is obvious the codebase is a mess anyway.

It is like expecting 1 employee to do everything to a high standard on a project that has no standards. So that 1 employees contribution to the whole big project has to be to high standards whilst the rest of project can have no standards at all. Laying the burden on the 1 employee whilst the rest have not done anything to any reasonable standards anyway.

The best interview I ever had consisted of having a small conversation about myself and the company followed by a small task. The small task I had to complete was to demonstrate how I would fix a certain bug with one of the features within their current system. No tricks, no catches. I just had to explain how I would fix a fairly ordinary bug that has cropped up in the current system.

I was shown a screen with the bug on it and handed the codebase. I could determine the starting point to look for the bug via the URL of the screen with the bug on it. After starting at the above point and digging deeper into a couple more files I found the best place to implement the fix and determined what the fix would be.

It would be great if all interviews where like the one described above. The task has got to be something small that demonstrates the programmer can dig into the codebase and fix a small problem.

So in conclusion I believe that interviews should be tailored to represent the actual companny. If your company does not need candidates who do well on interview tests then the interview should not be tailored that way. If your company is adament that candidates who do well on interview tests are needed then the companies current practices and codebase should reflect the level of tests they are giving to candidates at the interview.

Please also note that in a lot of the tests companies give to candidates the questions seem more geared to how much you can remember from a standard “programmers handbook” than actual real world scenarios that might actually happen. That is why the above approach involving fixing a bug is a better approach in my opinion.

Neptune – web based lead management / tracking tool – going free

Neptune is going free. I spent sometime not long ago implementing the subscription billing system into Neptune. Now I have spent some time to enable Neptune to have a plan that can be signed up to free of charge …

www.neptuneleadtracker.com

You can sign up and use Neptune for free now.

Trying to run Neptune like a business and only have paid plans took the fun out of the Neptune project. With the business aspects of Neptune out of the way Neptune can now be treated like the side project that it really is.

Czech character code converter

During the last contract I worked on a number of tasks required the use of converting blocks of text to there respective Czech character codes. I decided to build a Czech character code converter tool to help with this task.

I have put the Czech character code converter online as a free tool that can be used by anyone needing to convert text with Czech characters within it to there respective character codes. The tool can be found at …

http://www.czechcharactercodeconverter.com

Let me know if you used this tool for your project and what you think of it.

Fire those who are not excelling

So I read a lot of content on the web in my spare time and the title of this topic is a phrase I hear quite a lot on the web and I would just like to give my opinions on the above phrase and why this is not a good idea.

Ok so what is meant by “excelling”, well the definition of “excelling” is as follows …

shine, be very good, be excellent, be brilliant, be outstanding, be skilful, be talented, be proficient, be expert, be pre-eminent, reign supreme, wear the crown, stand out, be the best, be unrivalled, be unparalleled, be unequalled, be without equal, be second to none, be unsurpassed, surpass, outdo, outshine, outclass, outstrip, beat, beat hollow, top, cap, transcend, be better than, be superior to, go one better than, better, pass, eclipse, overshadow, put in the shade, put to shame

Firstly I can see in the list “be very good” so if I want to not get fired I have to “be very good”. My critique on this is “be very good” by whose and what standard? There is no standard on what is meant by “be very good”. Now you might say “well a standard can be defined and we can use that standard to measure the employee against”.

Yes this is what any reasonable person might think however I generally find that the people who are using and passing the phrase “Fire those who are not excelling” do not actually do this in practice. The “be very good” in practice merely becomes to “be very good” in the bosses or managers opinion. So to be fired for not excelling is to be fired based on the opinion of some boss or manager and very rarely is there any real evidence or standard to back this up.

The second word that stands out in the list is “go one better than”. Ok so to not get fired I have to “go one better than”. Now who do I have to go one better than? With time to think you may say the competition, however in practice with the people who have this sort of mindset the competition is not some far away company but your actual coworkers. This creates a climate of one-up-man-ship, if employee A is expected to “go one better than” employee B and employee B is expected to “go one better than” employee A how can that ever be resolved? It creates a climate of unhealthy and somewhat vicious competition among co-workers with each employee seeking to gain the better position from which they can rule.

Which brings me to the third word that stands out in the list … “beat”. Now what I am about to say is merely a matter of opinion and whether you see the connection or not is entirely up to you. Would it not make sense that an employee that is trying his hardest to “be very good” and “go one better than” his coworkers, in a climate of hostile competition and one-up-man-ship is actually trying to “beat” his coworkers. Yes in this instance I do not mean “beat” in friendly terms either I mean physical violence. Is this not the underlying desire this employee has? Is it too far a stretch of the imagination to see the connection? Is it too far a stretch that the person who desires to “go one better than” is quick to resort to fisty cuffs to enable them to actually do that?

One opinion could be that the coworker beat somebody up or punched someone because he was under a lot of stress at the time due to the climate of the workplace. One opinion could be that the desire was there already and the coworker who plays the game of one-up-man-ship was predetermined to be physically violent anyway.

So in my opinion if a company was to “Fire those who are not excelling” what does that leave the company with? A bunch of employees who are physically violent at heart and have no desire to see the company succeed but merely wish to “one up” their coworkers.

Please note that none of the above is an excuse for employee who is genuinely not getting his / her workload done. Each employee should be productive but not in the way described above. Each employee should be responsible for his / her own productive effort but should not have the desire to create unhealthy competition among coworkers. If all an employee can do is compare himself to other coworkers and is viciously competitive with coworkers whilst showing no genuine productivity then maybe that is the employee who needs to be re-educated.

I think the main point I am trying to make is that there is difference between an employee who is genuinely productive and an employee who always seems to be trying to “excel” in a viciously competitive way that has nothing to do with his / her genuine productive output.

Please note that there is also a difference between an employee who actually has the desire to “beat”, “go one better than” etc and an employee who is merely peddling the latest buzzwords because he / she thought they sounded cool without actually having that desire at all.

So that concludes my opinion on what I think all of all this “excelling” non-sense.

What would I look for in hiring a developer?

What would I look for from a technical perspective when hiring a developer?

Below is a list of areas I would look into when hiring a developer, please note that most of the below areas only apply if the developer is working on the codebase independently i.e. the codebase is solely the developers own codebase and is not being worked on by multiple developers …

Consistency of code
Is the consistency of the developers code consistent. There are many different ways of writing the same code in terms of code syntax but is the chosen way to write a piece of code consistent with a later way of writing the same piece of code. I am not talking about blocks of code here although it could apply to blocks of code as well but I am mainly talking about the small pieces of code for example arrays.

In PHP arrays can be written in the following 2 ways …

Or …

I would expect the developer to choose a way to write arrays and stick to the one way of writing arrays throughout the code. This also applies to using brackets within the code …

Or …

I would expect the developer to choose a way of writing brackets within the code and stick to that way of writing brackets. In the particular example above it would be except-able for the developer to change the style of writing the IF statement if the IF statement was no longer than 1 line of code for example …

The above is fine because there is a reason for it. That reason being the IF statement is no longer than 1 line of code. This reasoning can be applied consistently through all areas of the code. So when an IF statement is no longer than 1 line of code brackets are not needed. This is except-able if the reasoning is kept consistent throughout the code.

Consistency can be applied across many more areas including, naming conventions in code, code files and database, structure of the code, classes and extending classes, using code in view files or not using code in view files, tabbing / spacing of code.

So long as areas of code are kept consistent and the code is not mixing the above styles without reason then that would be except-able in my opinion.

Abstraction of code
Is the code appropriately abstracted? Is the code that is used in more than 1 place wrapped in classes / functions. If using a framework is the code in the controllers appropriately thin and the models and other classes doing most of the work.

When using a framework my controllers are quite small when compared to the level of functionality that is being executed. This is because my Models do most of the work and I make full use of the “beforeSave” and “afterFind” methods.

The controllers should control the flow whilst the details are kept tucked away in classes / functions.

Making the most of the tools / web frameworks
If using a web framework is the appropriate functionality being used? For example some of the latest frameworks have a feature called “scopes”. Are scopes being used where they should be or has the developer ignored scopes and written his own way of doing scopes?

If there is a legitimate reason for writing custom code to allow functionality similar to scopes then use it but if there is not a legitimate reason and the developer wrote his / her own way because he / she could not be bothered to read the scopes documentation then I would except the legitimate scopes to be used.

Same applies with “user authentication”. I have seen plenty of developers use their own way of “user authentication” including a full permissions system when the framework the developer used already had this feature built in.

When prompted as to the reason the developer created his / her own “user authentication” system the developer will state “the built in functionality is not fit for our requirements”, or “the custom user system that has been built is better and will allow us to do more complex user permissions” or some other general reason.

However upon further inspection it can be found that the frameworks built in functionality was fit for the requirements (plus more) and that the developer just could not be bothered to use the built in functionality.

So in conclusion if I was hiring for a developer the above areas are some criteria which I would make my decision on. The above areas are not set in stone and if some of the code was not in line with the above areas and there was a reason for it that would be except-able. If there was no reason for it, it would still be except-able under the agreement that the areas are rectified. All in all the areas have to be taken on a case by case basis.

Neptune – web based lead management / tracking tool – launch

Neptune has been launched and can be found online at the following website address …

www.neptuneleadtracker.com

Neptune has had a “soft” launch in that no huge marketing efforts have been done yet and there are still plenty of features to add to Neptune over the course of time. Marketing and feature development will be on-going.

Any updates to Neptune going forward will be posted at this blog as usual.