Category Archives: PHP

There is a better way to implement X

One of the code reviews comments that I’ve been seeing recently is “There is a better way to do this” and without further explanation.

By far this is one of the killer comments you can leave to someone. It is not only telling the coder that his code is not the best. but also leaving him with two challenging questions.

  • What is wrong about this implementation?
  • What are those better ways?

My advice to any reviewer who writes such comment, Try to write a more constructive review. One of the goals of code review is to identify the problems in the code and propose better ideas for implementation. so If you see something that is not at its best. Identify why it is not. and what are the better ways to implements it? always give the requestor something to learn, and go home with.

And If you are requesting a review then received this comment, don’t be defensive about your code. just take a deep breath, and ask the 2 questions above.

Adding custom mapping types in doctrine

While working in some enhancements for my startup Careerise, I had an issue with doctrine not recognising the mysql data type “blob“.

The error I was getting while running doctrine diff was :

[Doctrine\DBAL\DBALException]                                                                    
  Unknown database type blob requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support it.

In order to overcome the issue, I had to add the blob data type to doctrine.

Step 1 :

Creating a class to handle the blob type.

path : Doctrine/DBAL/Types/BlobType.php

file content :

<?php
namespace Doctrine\DBAL\Types;
use Doctrine\DBAL\Platforms\AbstractPlatform;

/**
 * Type that maps a database BLOB to an encoded base64 value
 *
 * @author Ahmed
 *        
 */

class BlobType extends Type
{

    public function getName ()
    {
        return TYPE::BLOB;
    }

    public function getSQLDeclaration (array $fieldDeclaration,
            AbstractPlatform $platform)
    {
        return $platform-&gt;getDoctrineTypeMapping('BLOB');
    }

    public function convertToDatabaseValue ($value, AbstractPlatform $platform)
    {
        return ($value === null) ? null : base64_encode($value);
    }

    public function convertToPHPValue ($value, AbstractPlatform $platform)
    {
        return ($value === null) ? null : base64_decode($value);
    }
}

Step 2: Add the blob type name to the Type abstract class

File Path : Doctrine/DBAL/Types/Type.php

    const BLOB = 'blob';

Step 3: Modify the DoctrineTypeMappings for mysql

File Path: Doctrine/DBAL/Platforms/MySqlPlatform.php

Append the blob type to the end of the array, ex :

protected function initializeDoctrineTypeMappings()
    {
        $this->doctrineTypeMapping = array(
            'tinyint'       => 'boolean',
            'smallint'      => 'smallint',
            'mediumint'     => 'integer',
            'int'           => 'integer',
            'integer'       => 'integer',
            'bigint'        => 'bigint',
            'tinytext'      => 'text',
            'mediumtext'    => 'text',
            'longtext'      => 'text',
            'text'          => 'text',
            'varchar'       => 'string',
            'string'        => 'string',
            'char'          => 'string',
            'date'          => 'date',
            'datetime'      => 'datetime',
            'timestamp'     => 'datetime',
            'time'          => 'time',
            'float'         => 'float',
            'double'        => 'float',
            'real'          => 'float',
            'decimal'       => 'decimal',
            'numeric'       => 'decimal',
            'year'          => 'date',
            'blob'          => 'blob',
        );
    }

now doctrine will be able to recognise the mysql data type blob.

the documentation here was helpful in some of the steps above : Custom Mapping Types

Where I am ?

Looks like i have stopped blogging for a while. except from some trips and tricks I am keeping for my reference and public users.

well that’s not the case but since the team I am working with grew to around 22 developer, which i believe considered the biggest php team in one company in Egypt, things were going so crazy, lots of projects going, lots of new approaches, new integrations, and i have to be on top of it all the time.

meanwhile i am driven by four ideas for projects that i believe is gonna make a little difference in their business areas, I am prototyping each one of them, jumping from one to other, I launched one of them already which is www.lamptag.com, which is simply a crawler for LAMP resources and related technologies, after less than a month from launching he prototype, the feedback is good, the twitter page reached 100 follower. and the number of clicks on the links is good too.

Soon i will blog about the recent challenged i have encountered in the field, weather they are technically or management related.

Recruitment System – One of my projects

I wanted to post this since a while.

The recruitment system is one of the applications I built for cha-international while working there beside developing the Middle East & North Africa travel awards system, mail marketing system, and converting all their servers from windows to Linux.

In brief the system has the following features :

  • Backend :
  1. Managing countries, Nationalities, Languages, World Areas, System Announcements.
  2. Managing Education Levels, Industries, Titles, Departments, System Reply Messages, Candidate Status, Candidates Classifications, and Quotes.
  3. Testimonials section where the company can post its clients testimonials to be displayed in the frontend.
  4. Managing 2 types of resumes : Uploaded Attachments, and Detailed filled forms Resumes.
  5. Easy form for the data entry team to add the resumes from the backend.
  6. Searching for candidates, using simple forms like name, email or advanced one which contains name, different nationalities, different languages, age, sex, industry, title, keyword in resume, etc.
  7. Consultants area where they can post / close job posting, search  for candidates, export word version of resumes, add to their favorite list, recommend them to another consultant.
  8. Consultants also can comment on the resumes, change their availability status to be seen by other consultants, and communicate with the candidate through the reply messages and keep track of those sent messages.
  9. The system has a approval workflow engine, the admins have to check the resume to approve it first.
  10. The system has a privileges section where the administrator can create a new role, assign access to certain areas in the backend to certain role, and assign the roles to system users.
  11. Feedback system where the backend users can communicate with the administrator for support tickets, etc.
  12. Auditrail system where every action in the system is logged.
  • Frontend:
  1. Simple upload form where users can just upload their resume and simple details.
  2. Advanced profile form where users can fill in all the details, and add many attachments to their profiles.
  3. Listing, Simple search, advanced search for jobs, and applying to them.
  4. Clients area where they can request certain services.
  5. Featured profiles, where a certain profiles selected by the admins showed in frontend.

The project was completely built from scratch using Zend Framework, and right now it has more than 70,000 applicant in its database, and the system is as fast as you see in the videos, these demos were taken with 50,000 record in the database.

Please don’t give me any feedback on the design ;), I am just a developer.

Here is some videos describing the different features of the system, I will try to post a better quality ones later.

 

Change your Signature

[youtube=http://www.youtube.com/watch?v=KXMg4q43Vf0]

 


Search Resumes

[youtube=http://www.youtube.com/watch?v=UUCuQ3XZmHg]

 


Apply as New Candidate

[youtube=http://www.youtube.com/watch?v=UNMVIahQAeU]

 


Send Feedback to support

[youtube=http://www.youtube.com/watch?v=-QiwYphCi2k]

 


Consultant Functionality walk through

[youtube=http://www.youtube.com/watch?v=wU6MDYO-xsw]

 


Check who applied for your job

[youtube=http://www.youtube.com/watch?v=X7_ZNVjksKg]

 


Apply for Posted Job

[youtube=http://www.youtube.com/watch?v=B06xlZr8A-w]

 

My Search Story :)

Quick dive into Flash Builder 4 (formerly Flex)

It has been a while since I have opened Flash Builder 4 Beta, but having to fill in the survey for testing, I gave it another shot yesterday.

Downloaded the last build “253292” from adobe prerelease repository.

I spend like couple of hours reading the docs and trying this and that, there is a lot of improvements, but what really caught my eyes is the tooltip help when you mouse-over a component, it gives you a more detailed information than before.

And what really was a WOW for me is the changes in the Data menu, now with the simple wizard you can create a connection to web service, PHP, BlazeDs, and others.

I tried the PHP one, and it went very smooth, I could even without writing a single line of PHP, enter the database credentials, and select the table I want to have access to from my flex app, and in few click, flex created the service in PHP and the mirroring AS classes, It even downloaded the Zend Framework AMF component.

It is much different than before, I had to do a lot of hard coding to get to this point, now developers will have more time to concentrate on the application itself, rather than on connecting to database and making it work.

It is worth trying and developers should read the migration docs from previous versions to get ready for it when it released.

Download Flash Builder Beta : http://labs.adobe.com/technologies/flashbuilder4/

Flash Builder 4 Migration Doc. : http://livedocs.adobe.com/flex/gumbo/flex4featuresandmigration.pdf


Manage your notes / Code snippets with Snippely

It has been a challenge for me to keep tracking code snippets I want to remember, I have always used text files, or sending my self email with the snippet that I feel I am gonna need to look at again in the future, same for notes also.

Today I have found this nice Air App called Snippely, it allow you to manage your notes / code snippets, It is enough for me and better than text files and emails, I believe I am gonna stick to it for now.

Snippely

Only Two options I wish to see in the coming version, to backup / restore the data & to sync the data across many machines, but like I said, I am happy with what I have now.

You can get Snippely from their Google Code page : http://code.google.com/p/snippely/

I hope you will find it as much useful as I did.

Fix for Zend Studio 7 Button Problems in Ubuntu 9.10 “Karmic Koala”

After updating to Ubuntu 9.10 “Karmic Koala”, i had some problems with Zend Studio GUI, some buttons when clicked appear to be pressed, but no action follows.

After searching for a while i found this fix in Zend support pages, and it solved the issue

here is the link for the fix :
http://kb.zend.com/index.php?View=entry&EntryID=435

Zend Certified Engineer

Hi mates,

finally i have got certified as Zend Certified Engineer on 10th of this month.

i have been decided to take the exam since a year, but was too busy to hold myself at home and revise the manual and prepare for the exam, but this month i said this is it.

The exam is very tricky with lots of confusing questions, it tests your ability of thinking and your real experience with php, web development, security and many other topics that some people will not expect to exist in PHP exam, it is  real benchmarking to your abilities.

I must say that preaparing for the exam has opened various topics for me to dig deep in, and it was a great experience.

And being one of the only 2 certified in Egypt is cool 😉

PHP is Now

Lots of people asks the question why php, i guess this article titles “PHP is Now” by Cal Evans is the Director of the PHP Center for Expertise at Ibuildings, will help those who asks, to know what is the powers of this great tool.

article URL: http://www.ibuildings.com/blog/archives/1554-PHP-is-NOW.html