Pages

Friday 7 August 2015

What's the difference between passing by reference vs. passing by value?

What is the difference between
  1. a parameter passed by reference?
  2. a parameter passed by value?
I  know many of you have the answer of it but here we will learn with example:

Say I want to share a web page with you  using passed by reference and pass by value, lets see how we can achieve this?

If I tell you the URL, I'm passing by reference. You can use that URL to see the same web page I can see. If that page is changed, we both see the changes. If you delete the URL, all you're doing is destroying your reference to that page - you're not deleting the actual page itself.
If I print out the page and give you the printout, I'm passing by value. Your page is a disconnected copy of the original. You won't see any subsequent changes, and any changes that you make (e.g. scribbling on your printout) will not show up on the original page. If you destroy the printout, you have actually destroyed your copy of the object - but the original web page remains intact.

Tuesday 16 October 2012

User Hierarchy Module For SugarCRM 6.5


Let's build User Hierarchy Module for SugarCRM  Version 6.* :

Step 1) Download Zucker_Hierarchy_module_1.1

Step 2) Edit manifest.php and update the acceptable version:

$manifest=array(
'acceptable_sugar_versions'=>array("regex_matches" => array("6.5.*")), 
 
Refer a Link  and do the changes as demonstrated in manifest.php.

Step 3) Replace all database instance From $db = &PearDatabase::getInstance();to $db = & DBManagerFactory::getInstance();

Step 4) User-Hierarchy menu not displayed properly on admin page ,So we need to add the ['Administration'] level to an array in the /custom/administration.php file. The entire file will look like this:
PHP Code:
<?php // User hierarchy menu foreach ($admin_group_header as $i => $group) {
    if (
$group[0] == 'LBL_USERS_TITLE') {
        
$admin_group_header[$i][3]['Administration']['user_hierarchy'] = array(
            
$image_path 'Users',
            
'LBL_USER_HIERARCHY_TITLE',
            
'LBL_USER_HIERARCHY',
            
'./index.php?module=UserHierarchy&action=ShowHierarchy'
        
);
    }
?>
Step 5) To set permission to user ,Branch vise edit List-view page and paste below code in file: \include\ListView\ListViewData.php at line no. 300. 
 
include_once("modules/UserHierarchy/UserHierarchy.php");

// [begin: UserHierarchy]
global $current_user;
if($_REQUEST['module']=='Leads'){
if($current_user->user_name!='superuser') {
if (class_exists('UserHierarchy')) {
$ret_array = UserHierarchy::query_array_with_hierarchy_filter($ret_array);
}
} else {
//do nothing
}

} else {
if (class_exists('UserHierarchy')) {
$ret_array = UserHierarchy::query_array_with_hierarchy_filter($ret_array);
}
}
// [end: UserHierarchy]


I think that's it. Hope that helps a bit.

Wednesday 16 May 2012

Goo.gl API: PHP

Shorten URL using Google URL Shortener API:


01 <?php

02$longUrl = 'http://facebook.com';
03$apiKey = 'Your Api Key here';
04//You can get API key here : http://code.google.com/apis/console/
05
06$postData = array('longUrl' => $longUrl, 'key' => $apiKey);
07$jsonData = json_encode($postData);
08
09$curlObj = curl_init();
10
11curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url');
12
13curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
14
15curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
16
17curl_setopt($curlObj, CURLOPT_HEADER, 0);
18
19curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
20
21curl_setopt($curlObj, CURLOPT_POST, 1);
22
23curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);
24
25$response = curl_exec($curlObj);
26
27$json = json_decode($response);
28
29curl_close($curlObj);
30echo 'Shortened URL ->'.$json->id;
31?>

Tuesday 15 May 2012

How to change drupal block theme

Are you looking to change Drupal Block theme? Dont worry. Here is the way you can do that.
You need one module and that is Block Theme. Download and install this module. No need to set any user permissions for this module.
After installation go to configure it at this URL /admin/settings/blocktheme
In Custom block template textbox enter following and save configuration.
myblock|Some name
Where the first name is the machine-readable name of your template which may contain only
alphanumerical characters, -, or _ . The second name is the user-friendly name that appears
in the selectionbox on the block edit form.
After this save configuration.
If your theme already has block.tpl.php then make a copy of it an rename it as “blocktheme-myblock.tpl.php”.
If block.tpl.php file does not exist in your theme (Yes, some themes do not have block.tpl.php) directory copy code below and name it as “block.tpl.php” also make one more copy of this code below and rename it as “blocktheme-myblock.tpl.php”. This blockthem-myblock.tpl.php is the theme file applied for the block you select and block.tpl.php will be applied for remaining blocks.
Code.
01<?php
02// $Id: block.tpl.php,v 1.3 2007/08/07 08:39:36 goba Exp $
03?>
04<div id="block-<?php print $block->module .'-'. $block->delta; ?>" class="clear-block block block-<?php print $block->module ?>">
05
06<?php if (!empty($block->subject)): ?>
07  <h2><?php print $block->subject ?></h2>
08<?php endif;?>
09
10  <div class="content"><?php print $block->content ?></div>
11</div>
Thats it.
Now go to /admin/build/block and configure any block you want to apply a theme to. On clicking a Configure link you will find one more section “Block Theme”. Select a theme from dropdown and Save block.
IMP: Do not forget to clear cached data from “/admin/settings/performance”.
Comments/Suggestions are welcome.