11 Feb

Business Processes using Artificial Intelligence

Best Practices, Latest Developments

Business growth and expansion is in every entrepreneur’s soul. Most of them come out with good ideas and suggestions to grow their businesses, but in today’s competitive world, one can not rely on man to perform all the tasks. Automation of the industries is a very genuine step to fulfill the dreams of expansion of the business. I have seen numerous cases, where the business, with lot of help from automation, grows at a very fast pace.

The automated industries are getting the fruits, in a long term, in following ways

• Time saving
• Higher Efficiency
• No human error
• Low operational cost

The use of artificial intelligence is one of the most unconventional thought in today’s world. Artificial Intelligence leads the industry to get the boom in production and output is maximized in least inputs.

The cases of automation can be seen in today’s world in most reputed organizations. We recently helped a data entry company, in automating their data entry process. Before automation, they faced lots of problems with the human errors, low efficiency, high operating costs, in form of salaries. The pitfall deteriorates the working conditions and leads the organization into defalcation.

We came up with an excellent idea to import the concept of artificial intelligence by the means of automating the data entry process and achieved the output by 10 times with no extra costs and no labor costs.

Another case of artificial intelligence is used in Maruti Udyog Pvt Ltd, for providing the colors to the body parts with help of robotic arms. This provides the uniform color to the body parts and a higher quality has been achieved in it.

Artificial Intelligence is now days used in many companies and all of them are diverting their processes to make the best output and hence, best profits.

The concept will rock the world with its leverage and provide large profits to entrepreneurs in all perspectives. The pros of the process are much higher than the cons. The only limitation in the process is its high initial cost.

“The greatest obstacle to discovery is not ignorance - it is the illusion of knowledge”. Daniel J Boorstin.

The quote explains the whole dilemma of the today market growth, where we are running behind every illusionary idea to get the success without seeking for the available option in form of Artificial Intelligence.

- Sandeep Sinha

11 Dec

A better way to send emails than CakePHP’s default Email Component ?

Best Practices, CakePHP, Latest Developments

While working on a big project today, I had to use this default Email component. I was disappointed when I had to create two views for every singly mail... This is really bugging.. Plus, It is not fast as it can be.
At the same time, I've always loved the magic Model functions: findAllby

Today, I realized how productive it would make us if there's some similar magic functions for email as well. Say to send a user approval letter, you just have to write following in your controllers:

PHP:
  1. $this->Email->send_UserApproval($email, $verification_code)// to send user approval mail
  2. $this->Email->send_UserWelcome($email)//welcome mail
  3. $this->Email->send_AdminPaymentNotification($from);   // payment notification to admin

This does not only increases the speed of writing code, but also makes code look beautiful.

While I was thinking about the idea, I dugg into model class of CakePHP to find how its done, I found the source of magic:

PHP:
  1. function __call($method, $params, &$return) {
  2. $db =& ConnectionManager::getDataSource($this->useDbConfig);
  3. $return = $db->query($method, $params, $this);
  4. if (isset($this->__backAssociation)) {
  5. $this->__resetAssociations();
  6. }
  7. return true;
  8. }

This is the function which creates all Model:findAllby functions. So I decided to write my own component which will definately save time in many of the projects.

One good way of developing this would be creating a language/email file like emails.php with something like this:

PHP:
  1. 'user'=>array(
  2. 'Approval'=>'Hi user, You are about to get approved.',
  3. 'Welcome'=>'Welcome user, you can now play with our system.'
  4.  
  5. ),

This file will be read by Email::__call() and our magic functions will be created on the run.

What do you think of this method ? Is it better than current Email component ? I'll blog again as soon as my email component is ready..

13 Feb

Finally a practical solution: Joomla with CakePHP together - JAKE

Articles, CakePHP, Latest Developments

For all those who liked my previous post where we integrated Joomla and CakePHP together, will surely love this one. There were some problems and limitations with the previous system, the major one was - The users who are already running Joomla couldn't take advantage of Cake as the setup involved in changing paths and all. Thanks to Dr. Tarique Sani for suggesting me that.

Ok, so lets start with the setup. Here the concept is, to install CakePHP as any other Joomla component and lets not modify anything with the present setup of Joomla. This is how we will start writing our component, com_cake [You can skip this part if you are interested in getting ready to use component] :

1. Lets install CakePHP in '\components\com_cake' of Joomla directory.

2. As we did before, lets create triggers for Cake... which are actual part of the components too: cake.php and cake.html.php

Here is cake.php

PHP:
  1. <?php
  2. defined( '_VALID_MOS' ) or die( 'Restricted access' );
  3.  
  4. require_once($mainframe->getPath('front_html'));
  5. $mainframe->setPageTitle("com_cake: Ultimate Joomla Component");
  6.  
  7. $joomla_path=dirname(dirname(dirname(__FILE__)));
  8.  
  9. // As this component (cakephp) will need database access, lets include Joomla's config file
  10. require_once($joomla_path.'/configuration.php');
  11.  
  12. // Constants to be used later in com_cake
  13. define(JOOMLA_PATH,$mosConfig_live_site);
  14. define(DB_SERVER,$mosConfig_host);
  15. define(DB_USER,$mosConfig_user);
  16. define(DB_PASSWORD,$mosConfig_password);
  17. define(DB_NAME,$mosConfig_db);
  18.  
  19. $controller=mosGetParam( $_REQUEST ,'module'); //option passed is treated as a controller in cake
  20. $action=mosGetParam( $_REQUEST ,'task'); //task passed is treated as a controller in cake
  21. $param=mosGetParam( $_REQUEST ,'id');
  22.  
  23. HTML_cake::requestCakePHP('/'.$controller.'/'.$action.'/'.$param);
  24.  
  25. ?>

cake.html.php

PHP:
  1. <?php
  2. defined( '_VALID_MOS' ) or die( 'Restricted access' );
  3.  
  4. class HTML_cake {
  5.  
  6. function requestCakePHP($url)
  7. {
  8.     $_GET['url']=$url;
  9.     require_once 'app\webroot\index.php';
  10. }
  11.  
  12. }
  13. ?>

Edit Cake's database.php

PHP:
  1. <?php
  2.  
  3. class DATABASE_CONFIG
  4. {
  5.     var $default = array(
  6.         'driver' => 'mysql',
  7.         'connect' => 'mysql_connect',
  8.         'host' => DB_SERVER,
  9.         'login' => DB_USER,
  10.         'password' => DB_PASSWORD,
  11.         'database' => DB_NAME
  12.     );
  13. }
  14. ?>

Ok, now we can see that URL like:
http://localhost/joomla/index.php?option=com_cake
will open Cake's homepage in Joomla layout. Make sure you have edited your default.thtml file so that CSS and HTML tags do not mess up.

http://localhost/joomla/index.php?option=com_cake&module=names&task=add
will call CakePHP's 'names' controller and 'add' function.
(Please dont confuse 'module' variable in URL with Joomla's module !!)
It will work great but we need even more. We also need scafollding/bake and more things which Cake can give... In my case, I loved baking than any other thing, so as to support bake process. Lets do next step.

3. Since Cake baked code uses helpers to output links, images or any other URL. So, lets hack Cake helper to output Joomla's URL in this formats:

index.php?option=com_cake&module=names&task=add
index.php?option=com_cake&module=names&task=index
index.php?option=com_cake&module=names&task=view&id=12

So, I wrote a small function for this, as we all love our HTML helper in Cake:
Write this function on bootstrap.php

PHP:
  1. <?php
  2.   function reform_url($url)
  3.     {
  4.         $temp=explode('/',$url);
  5.         $controller=$temp[1];
  6.         $action=$temp[2];
  7.         $param=$temp[3];
  8.         $url=JOOMLA_PATH.'/index.php?option=com_cake&module='.$controller.'&task='.$action;
  9.         if($param)
  10.             $url=$url.'&id='.$param;
  11.         return $url;
  12.     }
  13. ?>

Now we need to integrate this function with the helper functions so that it takes input in same format but output Joomla URL.

Copy HTML Helper (html.php) to your views/helpers folder and edit the following functions:

PHP:
  1. function url($url = null, $return = false) {
  2.  
  3.         if (isset($this->plugin)) {
  4.             $base = strip_plugin($this->base, $this->plugin);
  5.         } else {
  6.             $base = $this->base;
  7.         }
  8.  
  9.         if (empty($url)) {
  10.             return $this->here;
  11.         } elseif($url{0} == '/') {
  12.             $url=reform_url($url)//Lets change the URL
  13.             $output = $base . $url;
  14.         } else {
  15.             $url=reform_url($url)//Lets change the URL
  16.             $output = $base . '/' . strtolower($this->params['controller']) . '/' . $url;
  17.         }
  18.  
  19.         return $this->output($output, $return);
  20.     }

Similar changes were done in HTML::link(), HTML::image() and Controller:flash()

PHP:
  1. function flash($message, $url, $pause = 1) {
  2.         $this->autoRender = false;
  3.         $this->autoLayout = false;
  4.         $this->set('url', reform_url($this->base . $url));
  5.         $this->set('message', $message);
  6.         $this->set('pause', $pause);
  7.         $this->set('page_title', $message);
  8.  
  9.         if (file_exists(VIEWS . 'layouts' . DS . 'flash.thtml')) {
  10.             $flash = VIEWS . 'layouts' . DS . 'flash.thtml';
  11.         } elseif ($flash = fileExistsInPath(LIBS . 'view' . DS . 'templates' . DS . "layouts" . DS . 'flash.thtml')) {
  12.         }
  13.         $this->render(null, false, $flash);
  14. }

4. We are all done, and our Cake is waiting for us....!!!
I did one more mod so that you people can still bake on using bake.php... Edit com_cake\cake\scripts\bake.php and on starting lines add this:

PHP:
  1. $joomla_path=dirname(dirname(dirname(dirname(dirname(__FILE__)))));
  2. require_once($joomla_path.'/configuration.php');

Most of your small applications developed with Cake will still work with Joomla using this component, as we have modified the helpers too. You dont even have to change Cake's conding conventions to use this plus you can still use bake.php anytime.

You can download the component here.

See it in action:
CakePHP Homepage in Joomla
Names::index()
Names::add()

Please post your feedback if you like this, good feedback on my previous article inspired me to do this.. I will post more interesting stuff soon.

UPDATE - 16, Feburary: Mariano Iglesias is extending this project further. Here's the Jake Homepage

Thanks
- Max

Hire us

Contact us to get a free quote on your project.