Mid July 2018

Client work

This past couple of weeks I have been carrying on work for the medical helpline web based software module.

The system now has “Advanced Case Search” and “Merge Cases” functionality.

The “Advanced Case Search” allows a user to search existing cases in detail.

The “Merge Cases” functionality allows the user to merge together two existing cases, picking and choosing the information the user wants from each case to create a new case from the existing cases.

I have been really going to town on this module in terms of the subtle but nice features that make the software easy to use.

One of these features is the “search before create” functionality.

Originally a user would access the case screen which lists all the cases and click “Create” to create a new case.

However as this part of the system will need to be used by support staff who are answering support calls more functionality for this part of the system was needed.

Now when a support user clicks “Create” to create a new case, the user is given a text field to enter the callers name.

After this the existing cases the caller is already potentially a part of is displayed to the support user from which the support user can then use to select an existing case or create a new case.

If the support user creates a new case at this point the support user is then presented with the case create form with the callers name fields already filled in.

If the support user updates a case at this point the support user is then presented with the case update form with the callers existing details already filled in.

This is an improvement from the original separate create case / search case areas that where the support users only option originally.

Now the system has a “case search and create” all built into the same area to make the process quicker for the support user.

Another feature I have enhanced is the “case note” creation form.

On the case note creation form there is a section where the support user can fill out the duration, call received time and call returned time …

medical-duration

I used the Kartik TimePicker plugin for the time-picker input fields …

https://github.com/kartik-v/yii2-widget-timepicker

Originally I thought I could get rid of the duration field as that can be calculated automatically based on the call received time and call returned time.

However the client wants the flexibility of having the duration field there as well so they have option of typing in a duration in minutes or setting the call received time and call returned time.

I built a solution for this that would allow the client to have both.

When the duration is altered it modifies the call returned time in relation to the duration.

When the call received time or call returned time is altered it modifies the duration to match the minutes between the call received time and call returned time.

As well as the above areas I have implemented case lock functionality which allows a user to take ownership of a case which means no other user can edit that case until the owner user clicks save.

Bolsover castle

One of my new goals has been to get out and about more. There is nothing worse than being stuck in week after week so I have started to put some effort into making sure I go out and do something at the weekend.

Recently I have visited Bolsover Castle. Bolsover Castle is a 17th century castle built on the site of a 12th century medieval castle.

Bolsover is not a military style castle but is more of the stately home built in a similar form to a castle.

Some photos from my day out at Bolsover Castle can be seen below …

New car

My Dad bought a new car which gave me the opportunity to purchase his old car of him …

new-car

The car is a Renault Clio Mark 4 with alloy wheels, sat nav, cruise control, IPod music player and a diesel engine.

This is the first car I have had which actually seems like a proper car. All the other cars I had before this seemed old because they where old.

My last car had a tape player and no air conditioning which is strange because the car I had before that had a CD player and air conditioning even though it was an older car.

Feels good to have the air conditioning on in this weather as well as the music playing. This car has a much more stylish interior than any other car I have had to date as well.

Losing weight

I have bought up the weight loss a couple of times in the past but this time I am really going for it.

I have modified my diet and I am have made an effort to do more exercise and stick to it. I have lost just over one and half stone so far.

So that concludes what I have been up to the last couple of weeks.

July 2018

Client work

I have recently been working on a new module for a medical web software system.

The new module serves the purpose of collecting information for a medical support helpline.

Essentially people can ring the medical helpline and the support staff at the other end of the phone can use the system to enter various details.

Details about the caller, medical patient, details about the illness and about the call can all be stored within the system.

So far I have been implementing a massive form which has loads of input fields as well as a case notes section.

The module has been built on the Yii 2 framework which is what the rest of the system is built in.

The Yii 2 framework is a framework built using the PHP programming language.

The form has an associated grid which lists all the current cases or records. The grid is searchable and sortable.

The database for the module was created using the Yii 2 migrations and SQL.

Migrations are a library within the framework which allow you to write code to generate the database.

Migrations can be rolled forwards and backwards so allow a way of versioning the database.

The case notes section includes an Ajax form along with a good looking styled list view.

At its most basic Ajax is a way of communicating with the server from the browser in the background using Javascript.

Which means from a user standpoint the page does not need to reload when adding new case notes.

PHPStorm IDE

For this project I have actually been using a new program called PHPStorm …

https://www.jetbrains.com/phpstorm

I needed to use this as part of the project as PHPStorm was part of the clients requirements as the client also uses PHPStorm.

PHPStorm has a lot more features than the text editor program I was using before because PHPStorm is an IDE and not a text editor.

IDE mean Integrated Development Environment.

PHPStorm takes some getting use to as one would expect but by the looks of things PHPStorm will be worth it the more I learn about it.

I like the way PHPStorm provides information about areas of the code such as class / function definitions.

I also like the way PHPStorm provides the class structure of the project.

There is a lot more to PHPStorm than this though.

The text editor I was using before was called TextMate …

https://macromates.com

I really like TextMate and I will most likely still use TextMate for some of my personal projects.

Although TextMate has a lot less features the feel of it is more slicker and less clunky than PHPStorm.

Also as one would expect due to its smaller feature set.

Toolkit new report feature

I have added a new report to my custom built business management system named Toolkit.

I built the system a while ago to collect information on various areas of my business.

I have added a new report to the system which shows me how many hours I have spent on a particular project and the cost of the project so far.

The cost is calculated by multiplying the number of hours by the project rate or rates.

I already had many reports in this Toolkit system but this has been needed for a while now.

It makes it easier when I can just click on a project and see how many hours I have spent on the project and how much money the project has been billed for so far.

So that concludes the work I have been doing recently.

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.

Create a master Model and Controller in Yii2

In this article I discuss how to create a master Model and Controller using the Yii2 framework. Why would you want to do this? A master Model and Controller provides a place to put higher level methods which contain functionality that you want to use in your Models and Controllers.

Rather than repeating code across multiple Models and Controllers put the code in the master Model and / or Controller and access it from the standard Models and Controllers. You can also override standard Yii2 Model and Controller functionality with your own altering the fundamental way Yii2 works without having to alter the core Yii2 files.

The master Model and Controller are classes that extend from the following …

  1. \yii\db\ActiveRecord – for Models
  2. \yii\web\Controller – for Controllers

Yii2 also contains another type of Model, this Model is used for defining data with no database table. This kind of model is useful for forms which do not need to use a database table but still need the inherit functionality within Yii2 Models like Validations.

Although I will not be extending this second type of Model in this article you can use what you learn from this article to extend it yourself if you wish. The class for this Model is located at \yii\base\Model.

The diagram below shows what we are trying to accomplish …

Master Model and Controller

The “From” part of the diagram shows what the Yii2 software application without a master Model and Controller. The “To” part of the diagram shows the addition of the Master and Controller. Notice how the original ActiveRecord is called “ActiveRecord” and so is our master Model.

Also the original Controller is called “Controller” and so is our master Controller. You do not need to worry about this as they exist in different Namespaces. You can call the master Model and / or Controller something different if you prefer.

Now lets look at the code to add the master Model and Controller to a Yii2 application. Create 2 new files one named “ActiveRecord.php” and one named “Controller.php” and place them inside the “components” folder inside your Yii2 application.

Now inside the files write the following code …

ActiveRecord.php

Controller.php

Now when it comes to creating your standard Models and Controllers you can extend from the master Model and Controller like follows …

Book.php (Model) …

BookController.php (Controller) …

The above 2 files would reside in the standard “models” and “controllers” folders.

Now any methods you want to use across multiple Models and Controllers can be placed inside the master Model and Controller. These will be accessible from the lower level Models and Controllers exactly as they would be in any extended PHP class.

Also as mentioned earlier you can override standard Yii2 Model and Controller methods in the master Models and Controllers thus allowing you to alter the way Yii2 works without having to alter the core Yii2 files.

Remember if you wish to override the constructor in the master Model or Controller to call the parent constructor inside the override constructor.

A master Model and Controller are PHP classes I create for all my Yii2 applications. They are infinitely useful for the already mentioned above reasons.

Yii 1 to Yii 2 differences and enhancements part 2

I wrote about Yii 1 to Yii 2 differences and enhancements some time ago and now I am going to carry on from that article to discuss more differences and enhancements I have found since moving to the Yii 2 framework from the Yii 1 framework …

Relations

In Yii 1 relationships where defined in the relations method. The relations methods is a method that returns an array of data specifying the relations the model has and data relevant to those relations.

The array is used to create the relations as model properties.

In Yii 2 relations are defined in “magic methods” as follows …

I prefer the Yii 2 way of using the magic methods because it allows you to write additional code in the method that defines the relation. This could come in handy in unique scenarios where custom code is needed to handle the relationship. I also think the Yii 2 method is more in line with the PHP language as a whole than the Yii 1 way of defining relations.

Validations

Yii 2 has more validation options than Yii 1 and has introduced further options the validations themselves which make creating these sorts of validations a lot more streamlined. Both Yii 1 and Yii 2 validations are defined as arrays. With the added bonus of the later version of PHP language in the Yii 2 framework the arrays in Yii 2 look more streamlined.

For example rather than this …

They are like this …

They look much better.

Yii 2 introduces the new “when” option and thanks to PHP callback functions we can now write a validation like so …

This will only require the “name” attribute when the “complete” attribute is true. In Yii 1 this validation would have had to have been written as a custom validation method which is a real pain.

That is it for now, another update to come soon.

Yii 1 to Yii 2 differences and enhancements part 1

A number of months ago I made the switch to the Yii 2 framework from the Yii 1 framework. My intent in this post is to outline some of the differences and enhancements I have found from switching to the latest Yii framework.

A framework is a set of code written to help in common programming tasks for example handling data, creating forms and data tables etc.

When I first started programming I did not use a framework as I did not understand the benefits properly of using a framework. The above tasks would have been written from scratch and would have essentially duplicated code that was already out there for solving these common tasks.

When I first started using a framework it made my life much easier and the end product was of a better quality to time ratio than not using a framework. The same quality could be achieved without the use of a framework but would take longer and the programmer would be essentially writing code for common problems that already have a solution.

I would also like to mention that frameworks provide a consistent structure to the code that a programmer writes so that one way of solving a problem at one end of the code would be the same way the problem was solved at another end of the code. This makes it easier for other programmers to understand the code base.

After using the Yii 2 framework here are some of the differences and enhancements that I have found …

User Identity

In Yii 1 a “User identity” is a class that extends “UserIdentity” and handles the authentication and identity of the logged in user. I would create a class that extends “UserIdentity” create some predefined methods and let Yii handle the authentication.

In Yii 2 a similar approach is used except I do not create an extended “UserIdentity” class but instead I “implement” “IdentityInterface” in my User class. In Yii 1 I would have a “UserIdentity” class and a “User” class, in Yii 2 I just have the “User” class. Similar to Yii 1 I create some predefined methods in my “User” class and let Yii handle the authentication.

Active Record

Active Record has some key differences going from the Yii 1 framework to the Yii 2 framework. In Yii 1 Active Record was used like so …

Or …

Or …

In Yii 2 Active Record is used as follows …

Or …

Or …

Basically in Yii 1 there where a lot of methods that where created for specific purposes “findAll”, “findByPK”, “findByAttributes”, “findAllByAttributes”, “deleteByPK”, “deleteAllByAttributes” etc.

Yii 2 can do all of the above purposes but the syntax is much more flexible in that it does not have methods for each purpose but flexible syntax that can be used for flexible purposes.

Also note how in Yii 1 I used array() and in Yii 2 I used []. That is because at the time of Yii 1 array() was the PHP syntax used for creating arrays and at the time of Yii 2 [] could also be used to create arrays. Not really a Yii issue but still the array syntax looks better in the more modern version of PHP.

Use

Due to the Yii 2 framework being written at a time when the version of PHP was later and more modern the Yii 2 framework has made extensive use of the “Use” statement and “Namespaces”. Yii 1 did not make use of these at all probably because they where not implemented in PHP at the time the Yii 1 framework was written.

Nevertheless I feel the “Use” statement and “Namespaces” give the code a more professional feel and it means that the code is only made use of when the code is needed.

I will be updating the blog with more articles on Yii 1 to Yii 2 differences and enhancements as I go a long. I already have plenty of differences lined up but I will be saving them for the next article in this series.