Monday, December 9, 2013

Jquery : Useful Selectors


Jquery Useful Selectors are: 

1. How to set checked attribute in CheckBox.

$("."+cssClass).attr('checked', True);

2. How to select element on the basis of disable attribute:

$("."+cssClass+":not[disabled]").attr('checked', true);

Note: Above selector solution will be increased ASAP.

ZF2 : Custom config file inside module(s)


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'];

Tuesday, November 12, 2013

Zend Framework 2 Sql Expression


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

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

 $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')";  
  $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:

 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`  
 $sub = new Select('comment_vote');  
 $sub->columns(array('negativeVote' => new \Zend\Db\Sql\Expression('COUNT(')), FALSE)->where(array('vote' => -1 , 'comment_vote.commentId' => ''));  
 $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:

select 'passport' as type,a.user_id from join_user_passport_office as a where a.user_id=7
select 'embassy' as type,b.user_id from join_user_embassy_office as b where b.user_id=7
select 'visa' as type,c.user_id from join_user_visa_office as c where c.user_id=7
select 'ecowas' as type,d.user_id from join_user_ecowas_office as d where d.user_id=7
select 'freezone' as type,e.user_id from join_user_freezone_office as e where e.user_id=7 ;
 $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));

        $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));


Sunday, November 10, 2013

Jquery Plugin : FlexBox


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:

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"
# git log test.txt

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

# git show abcdefghijklmnop:test.txt

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

# 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


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


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.

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

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.


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


class your-module-nameViewWelcome extends SugarView {

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

    function display(){
         $smarty = new Sugar_Smarty();
         $smarty->assign("welcome", 'welcome');

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

{ $welcome } To TPL Page

your will access the page via:


then you will see your template.

I hope this information would help you :)