Monday, December 9, 2013

ZF2 : Custom config file inside module(s)

Hi,

ZF2 has the feature to create custom config file inside module(s).

Its provide help to declared variable those will used inside the particular module.

It is independent of main ZF2 config file.

Below are step to create/Use the custom config file inside the module:

Step 1: Create Module as Report

Step 2: Create custom config file in module's config directory i.e. module.customconfig.php, 

Step 3: Sample content inside module.customconfig.php

return array(
         'report' => array(
              'header' => array(
                    'name' => 'Name'
               )
         ),
);


Step 4: In controller of Report Module, Ex: ReportController.php

In Action: 

$config = $this->getServiceLocator ()->get ( 'config' );
//Take custom-config data from config file
$data = $config['report'];
print_r($data);




Tuesday, November 12, 2013

Zend Framework 2 Sql Expression

Hi,

To perform the sql function inside sql query in ZF2 like:

Type 1:
Query: 
 "select count(*) from foo group by name"  

ZF2: 
 $sql = new Sql($adaptor);  
 $select = $sql->select()->from(array('f' => 'foo'));  
 $select = $select->columns(array('count' => new \Zend\Db\Sql\Expression("count(*)")));  
 $select = $select->group(array('name'));  
 $statement = $sql->prepareStatementForSqlObject($select);  
 echo $statement->getSql();  


Type 2:

 Query = "Select * from foo where foo_name = lower('test')";  
ZF2:
  $sql = new SQL($adaptor);   
 $select = $sql->select()->from(array('f'=>'foo'));   
 $select = $select->where('foo_name' => new \Zend\Db\Sql\Expression("LOWER('test')"));  
 $statement = $sql->prepareStatementForSqlObject($select);  
 echo $statement->getSql();  

Type 3: 
Manage sub-query inside query:

Query:
 SELECT `comment`.`id` AS `commentId`, `comment`.`comment` AS `comment`,   
     (SELECT COUNT(`comment_vote`.`id`) AS `negativeVote`   
     FROM `comment_vote`   
     WHERE vote = -1   
     AND `comment_vote`.`commentId` = `comment`.`id`) AS `nagetiveVoteCount`   
 FROM `comment`  
ZF2:
 $sub = new Select('comment_vote');  
 $sub->columns(array('negativeVote' => new \Zend\Db\Sql\Expression('COUNT(comment_vote.id)')), FALSE)->where(array('vote' => -1 , 'comment_vote.commentId' => 'comment.id'));  
 $subquery = new \Zend\Db\Sql\Expression("({$sub->getSqlString()})");  
 $predicate = new \Zend\Db\Sql\Predicate\Expression("({$sub->getSqlString()})");  
 $sql = new Sql($this->adapter);  
 $select = $sql->select()->from('comment');  
 $select->columns(array('commentId','comment', 'nagetiveVoteCount' => $subquery));  
 echo $select->getSqlString();  
 
Type 4:

Union of Sql Query:

Query:
select 'passport' as type,a.user_id from join_user_passport_office as a where a.user_id=7
 union
select 'embassy' as type,b.user_id from join_user_embassy_office as b where b.user_id=7
 union 
select 'visa' as type,c.user_id from join_user_visa_office as c where c.user_id=7
 union 
select 'ecowas' as type,d.user_id from join_user_ecowas_office as d where d.user_id=7
 union 
select 'freezone' as type,e.user_id from join_user_freezone_office as e where e.user_id=7 ;
 
ZF2:
 $select1 = $this->_sql->select()
        ->from(array('t1' => 'join_user_embassy_office'))
        ->columns(array('type' => new \Zend\Db\Sql\Expression("'embassy'"), 'user_id' => 'user_id'))
        ->where(array('t1.user_id' => $id));
        

        $select2 = $this->_sql->select()
        ->from(array('t2' => 'join_user_passport_office'))
        ->columns(array('type' => new \Zend\Db\Sql\Expression("'passport'") ,'user_id' => 'user_id'))
        ->where(array('t2.user_id' => $id));
        
        $select1->combine($select2);

        
        
        $select3 = $this->_sql->select()
        ->from(array('t3' => 'join_user_visa_office'))
        ->columns(array('type' => new \Zend\Db\Sql\Expression("'visa'") , 'user_id' => 'user_id'))
        ->where(array('t3.user_id' => $id));
        
        $selectall3 = $this->_sql->select();
        $selectall3->from(array('sel1and2' => $select1));
        $selectall3->combine($select3);

 
 

Sunday, November 10, 2013

Jquery Plugin : FlexBox

Hi,

Flexbox is a jQuery plugin that is intended to be a very flexible replacement for html textboxes and dropdowns, optionally using ajax to retrieve and bind JSON data.

It's a nice library to load the html dropdown or textbox with paging functionality and many other settings.

Look and feel for the textbox/dropdown html elements also lightweight.

Reference URL:
http://flexbox.codeplex.com/
http://fairwaytech.com/flexbox/flexbox-demos/

Thursday, October 17, 2013

GIT : Basic Command

1. How to color the Git console in Ubuntu?

# git config --global color.ui auto

The color.ui is a meta configuration that includes all the various color.* configurations available with git commands. This is explained in-depth in git help config.


color.ui: This variable determines the default value for variables such as color.diff and color.grep that control the use of color per command family. Its scope will expand as more commands learn configuration to set a default for the --color option. Set it to always if you want all output not intended for machine consumption to use color, to true or auto if you want such output to use color when written to the terminal, or to false or never if you prefer git commands not to use color unless enabled explicitly with some other configuration or the --color option.


2. How to keep password in memory?
# git config --global credential.helper cache
which tells git to keep your password cached in memory for (by default) 15 mins
# git config --global credential.helper "cache --timeout=3600"
which tells git to keep your password cached in memory for 3600 seconds

3. Get diff in file
# git diff
will return the file differences

4. How to resolving file conflicting after Git Pull?
Step 1> Identify which files are in conflict (Git should tell you this)
Step 2> Open each file and examine the diffs; Git demarcates them. Hopefully it will be obvious which version of each block to keep. You may need to discuss it with fellow developers who committed the code.
Step 3> Once you've resolved the conflict in a file, then apply below command in console
# git add file-name
Step 4> Then commit the conflict
# git commit -m "Conflicts Resolved"

5. How to add new file on Git?
# git add
# git commit -m "new file added"


6. How to check the file status in your repository?
# git status

7. How to push you committed file on the remote server?
# git push origin master

8. How to get the Git Update from remote server?
# git pull origin master

9. How to increase Git performance?
# git gc
will give significant speed on your local repository.
Basically, git-gc : it is for cleanup unnecessary files and optimize the local repository.

10. How to get the Git Log?
# git log

11. How to get log on specific file?
# git log "file-name"
ex:
# git log test.txt

12. How to get file from Git of specific version?
# git show commit-no:file-name

ex:
# git show abcdefghijklmnop:test.txt

13. How to know file list from Git of specific version?
# git show commit-no --name-only

ex:
# git show 0ba1a6177178f77cd711bfe1db43fac80f70f3e2 --name-only

14. How to use GUI visualize for Git log?
Please install gitk tool in your OS
# sudo apt-get install gitk
It will install in your OS, after that you are able to view the git log in GUI, where everybody easy to identify the following:
  • Commit with the name, and respective committed files
  • file change in every commit
  • Text search in committed file
  • beautiful file comparison
  • file navigation  
 Run below command to run GUI interface:
# gitk

15. How to remove file/folder from GIT
if you want to remove file, then

# git rm file-name
if you want to remove folder, then
# git rm folder-name -r

# git commit -m "your message"
#git push origin master

16. How to change message after GIT commit
# git commit --amend -m "New commit message"

Tuesday, October 1, 2013

SVN Error - is Not a working copy

Hi,

I got the issue in SVN while doing additions in the SVN repository.

I am getting error Like :

"SVN : 'dir1' is not a working copy.

After a long struggling, i got the solution,  use below command to solve the issue i.e.:

# mv dir1 dir1_
# svn cleanup
# svn revert dir1
reverted 'dir1'
# mv dir1_ dir
# svn add dir1

In that way, i am able to get the my problem solve.

 

Thursday, September 26, 2013

SugarCRM : How to set Relationship between 2 modules


Hi,

To set the relationship between two module,  for example:
Module 1 : Quotes
Module 2 : Accounts

So in Db there is one table that contains relationship i.e. quotes_accounts table.

Now, if you want to insert data in quotes module with taking care of account relationship then there are 2 methods.

Method 1: Lets assume you have data like this,
I am assuming that you have last insert account id is $account_id

$bean = BeanFactory::getBean('Quotes');
$bean->name = $name;
$bean->purchase_order_num = $value['Order ID'];
$bean->billing_address_street = $value['Billing Address'];
$bean->billing_address_city = $value['Billing City'];
$bean->billing_address_state = $value['Billing State'];


//Save the entry into quotes table
$quote_id = $bean->save(); // will return last insert id

//Now to set the relationship into quotes_accounts table
$dataset = array(
'account_id' => $account_id, //last insert id in accounts module
'quote_id' => $quote_id, //last insert id in quotes module

);

//will enter relationship entry into quotes_accounts table:
$bean->set_relationship('quotes_accounts', array(), false, false, $dataset);


Above method is bit lengthy process.

Method 2:
in spite-of creating set_relationship() function, just use firebug tool(available in firefox)
Inspect the "Billing Account Name" textbox element, you will see the hidden element just below of it.
Copy the hidden element id, then assign it as :

$bean->billing_account_id = $account_id ;

Here, billing_account_id is hidden element ID and $account_id is last insert account module id.

then save the bean i.e.
$bean->save();

Now you will see that data inserted into quotes and quotes_accounts table simultaneously.



I hope you got the my point :) 

If you get any doubt,   Please let me know.

Monday, May 13, 2013

Creating custom view for SugarCRM

Hi,
From last few days, i was active on SugarCRM product and searching for the customizing its properties.
I found out how to customize the view layer.

Step 1: Create Custom module in customer dir
i.e. custom/modules//controller.php

controller.php file responsible for the redirection of view file.

ex:


class your-module-nameController extends SugarController {

    public function action_test() {
        $this->view = "welcome";  //call for the view file in views dir
    }
}


Step 2: create views dir i.e. custom/modules//views/view.welcome.php

code:

class your-module-nameViewWelcome extends SugarView {
     function
your-module-nameViewWelcome(){
         parent::SugarView();
     }


    public function preDisplay(){
        $this->dv->tpl = 'custom/modules//tpl/welcome.tpl';
    }


    function display(){
         $smarty = new Sugar_Smarty();
         parent::display();
         $smarty->assign("welcome", 'welcome');
         $smarty->display($this->dv->tpl);
    }
}

Step 3: create tpl file inside custom/modules//tpl/welcome.tpl

{ $welcome } To TPL Page


your will access the page via:

http:///module=&action=test

then you will see your template.

I hope this information would help you :)





Tuesday, November 1, 2011

MySql View DEFINER and SQL Security

Hi,

Some time back, I tried to backup a database from my server and restored it on my localhost mysql server. It had a few views. On taking backup from server i always getting issue i.e. :

mysqldump: Got error: 1449: The user specified as a definer ('msilink'@'localhost') does not exist when using LOCK TABLES

So I opened the dump file and found that the error was being caused by a line which looks like this :

/*!50013 DEFINER=`msilink`@`localhost` SQL SECURITY DEFINER */

This line appeared in every view definition. So the simple reason was that msilink@localhost, user which had created the view (on the server) and when importing the database on local system there was no user named ‘projects’ in MySql.

For that i just open the file and update the line: "50013 DEFINER=`msilink`@`localhost`" with "50013 DEFINER=`root`@`localhost`"

with the following command(In Linux VI Editor):

:%s/50013 DEFINER=`msilink`@`localhost`/50013 DEFINER=`root`@`localhost`/g


then save and close the file. The above solutions worked for me.

Solution is to create a view with SQL security invoker like this :

CREATE
SQL SECURITY INVOKER
VIEW system_users AS SELECT host,user,password FROM mysql.user;

The above statement allows this view to be viewed by any user who invokes the view.
By default the SQL SECURITY is DEFINER which means the definer user can only view it.


:: Alternative Solution ::
Create another user that have all the privileges like as root, viw the following query:

mysql > grant all PRIVILEGES on *.* to msilink@localhost IDENTIFIED BY 'root' WITH GRANT OPTION;

In General:
mysql > grant on to @localhost IDENTIFIED BY '' WITH GRANT OPTION;

That also solve your problem.

Monday, July 18, 2011

CodeIgniter - Routing

Hi,

Implementation of the routing is the interesting idea to manage short URL re-writing.

Way to implement the routing :
Just open the application/config/routes.php, insert the line at the end of the file.

1) if you want that URL would be http://example.com/work/holiday
here, work is the controller name and holiday is the data that would be dynamically changed. So, to implement this just write like this:
$route['work/(:any)'] = 'work/work_detail/$1';
here (:any) = would accept any type of argument,
work/work_detail : class/function relationship
$1 : argument passed

class Implementation:

class Work extends CI_Controller{

function __construct(){
parent::__construct();
}
function work_detail($arg){
echo $arg; //would return holiday
}

2) If your URL is http://example.com/sevice/data, where service is controller and data would dynamic changed,
but client requirement is URL : http://example.com/data only. then you have to manager class/function relationship implicitly.

open routes.php and insert line at the end of the file.
$route['^(?!work|home).*'] = 'page/info/$1';

here, i used regular expression to bypass control from work,home class, means url : example.com/work and example.com/home not there then it would follow page class.

i.e. if URL : http://example.com/data called then specific routing will transfer control to the page/info :: class/function relationship,

it will help in short URL re-writing cases.
Implementation:
Class Page extends CI_Controller{
function __construct(){
parent::__construct();
}

function info($arg){
echo $arg; //would give data
}
}


Bye everybody...

CodeIgniter - an open source Web Application Framework

Hi Everybody,

From last 3 month, i was working on codeIgniter Framework. And i found its very interesting tool to manage MVC structure.

I start my work on version 2.0.2, it's the latest version of CI. Here many new feature introduced like :
# Support for PHP 4 is gone, PHP 5.1 is now a requirement.
# CSRF Protection built into the form helper
# Drivers
# Application Packages
# Scaffolding, having been deprecated for a number of versions, has been removed.
# Removed the deprecated Validation Class.
# Plugins have been removed, in favor of Helpers.
# Added routing overrides to the main index.php file, enabling the normal routing to be overridden on a per “index” file basis.
# Added $route[‘404_override’] to allow 404 pages to be handled by controllers.

which are not available in CI older version i.e. 1.7.x versions.

CI has very good User Guide that provide methods of creating web application with best implementation way.
URL of User-Guid: http://codeigniter.com/user_guide/

At the end i like it so much because of its light weight, good user guid and good support on bug fixing.

Bye :)