User Profiles On Registrations - Per Role

Technologies: 

Dear Dhongis,

We have almost all sites where we have multiple roles and we need a different profile for each role. This was so far rocket science since we did not have a mechanism to create different looking registration forms per user role. We handled this situation post login when we asked people to create profiles as per their roles.

Also, we have an issue of assigning roles when logically a person should be able to choose their role and admins should simple approve or disapprove of it.

Walking by the PC
One September Afternoon
I found the solution
But not very soon

How to send email from loclahost Drupal hosted in Ubuntu?

Technologies: 

Consider a situation in which you have installed Drupal in your Ubuntu machine. Now you would like to start sending email from localhost.If you have not setup Mail Transfer Agent(MTA) than you will not be able to send email from localhost.

What is Mail Transfer Agent(MTA)?

Wikipedia Says:

Utility Methods

Technologies: 

function_exists: function_exists — Return TRUE if the given function has been defined

Syntax:

bool function_exists ( string $function_name )

Example:

<?php
if (function_exists('payroll_getcomponents')) {
    echo(
"payroll_getcomponents functions is available");
}else{
    echo(
"payroll_getcomponents functions is NOT available");
}
?>

profile2_load_by_user: Loads the profile data of a user. Takes user id as input

Syntax:

profile2_load_by_user($account, $type_name = NULL)

Example:
<?php

How to Set Filters for a View in Drupal 7 programmatically

Technologies: 

Accessing a view programmatically

<?php
$view = views_get_view('view_name');
$view->init();
$view->set_display('default'); // or display id like page_1, block_1
$view->set_arguments(array($ARGS));
//display_name = 'default' or 'page' and so on
//filter_name is the name of the filter
//debug($view->display['display_name']->handler->options['filters']['filter_name']);
$view->display['default']->handler->options['filters']['date_filter']['value']['min']='2012-05-01';
$view->display['default']->handler->options['filters']['date_filter']['value']['max']='2012-06-30';

Google Drive for Project Management

This post highlights the important features Google has brought into it's Drive tool (formerly Google Docs and Spreadsheets) which has made online collaboration easier than before and enabled the use of Spreadsheets as a serious project management tool.

Without going into obvious features, what I would like to highlight is the fact that Google Drive not supports Pivoted spreadsheets. This means that while you maintain your raw data, you can also auto generate elegant status reports with all the power of pivots. An example report for one of my active project is here:

Inspecting Objects: Simple Trick

Technologies: 

How often have you felt the need to display a PHP Object in a readable manner? We are all very familiar with the use of the print_r() function. However, print_r() gives a difficult to read output and we end up matching braces to figure out the exact structure of complex objects. Here is a small trick which you can use to see the print_r() output in a 'Display for Humans' format.

echo '<pre>';
print_r($object);
echo '</pre>';

Let's see an example(borrowed from PHP.net):

<?php

Creating a Drupal 7 Node Programmatically


<?php
/**
* Basic Node Creation Example for Drupal 7
*
* This example:
* - Assumes a standard Drupal 7 installation
* - Does not verify that the field values are correct
*/
$body_text = 'This is the body text I want entered with the node.';

$node = new stdClass();
$node->type = 'article';
node_object_prepare($node); //Creates default settings for the node of a type
$node->title = 'Node Created Programmatically on ' . date('c');
$node->language = LANGUAGE_NONE; //String constant value for "und"

/* If u have body text do the following below

Add Sites to search in Apache Multicore Configurations

Solr is the popular, blazing fast open source enterprise search platform from the Apache Lucene project. Its major features include powerful full-text search, hit highlighting, faceted search, dynamic clustering, database integration, rich document (e.g., Word, PDF) handling, and geospatial search. Solr is highly scalable, providing distributed search and index replication, and it powers the search and navigation features of many of the world's largest internet sites.
--
Source: http://lucene.apache.org/solr/

Dates using PHP

Technologies: 

Time and again date parsing issue comes up and I find myself looking all over the net for finding ways to do the same. This post is created to compile all such ways as I encounter:

Parsing Dates

If your date format is: yyyy-mm-dd, you can simply use strtotime and date function to get the desired date format

$data[] = date( 'd-m-Y', strtotime('2012-03-21')); //get the format as 21-03-2012

Get Dates Using Strotime
strtotime can recognize certain keywords.
<?php
echo strtotime('now');
echo strtotime('+4 days');

Extract Result Data From Drupal View

Technologies: 

The code to do the trick is provided below:

<?php
    $view
= views_get_view('view_name');
   
$view->init();
   
$view->set_display('default'); // or display id like page_1, block_1
    //$view->set_arguments(array('arg_data'));
    //$view->set_arguments(array(arg(0),'arg_data2'));  // 2nd  Argument
   
$view->pre_execute();
   
$view->execute();
   
//print_r($view->result);
   
drupal_set_message("Field data value: ".$view->result[0]->node_data_field_as_it_appears_in_views_query_sql);
?>

Update for Drupal 7:

<?php