MLTR live concert in Nepal

MLTR (Michael Learns to Rock) just finished their live concert in Nepal, which was really awesome. It was cold and all fans were enjoying the songs.

First 45 minutes me and my friend was searching for the ticket counter, which turned out to be on the opposite side of the main road, infront of the Kathmandu Mall. We bought 2 Golden tickets, which costs us Rs. 4000 (Rs. 2000 each). There was tight security for the MLTR members, so it could be said that APF (Armed Police Force) were doing their duty at their full capability.

There were three separate entrance gate, Platinum (Rs. 2500), Gold (Rs. 2000) and Silver (Rs. 1000). We entered through the entrance for Golden Gate. As we entered through the Golden Gate their were some checkings and in a minute we were in the Tudhikhel ground starting to sing the song, though I don’t know which song it was but I liked it. All of the songs there were around 3 songs that I liked the much which are someday, 25 Minutes, Breaking my heart.

We hadn’t camera this time with us so I missed the snaps this time. Though watching MLTR live has really made my day worth. The fans were not allowed to take the professional camera (DSLRs) but were allowed to take the digital cameras.

The music system was good but at some moment there were some chirpping sound which could be heard very clearly when there was no music.

The last song played by MLTR was someday, somewhere which all of us enjoyed very much then the show was announced as finished and all fans started to return back their home. There were taxi’s waiting for passengers and also there were heavy APF vehicles as well as Fire Brigade. Inside the Tudhikhel ground there was the arrangement for the electricity and foodstalls. Electricity backup was provided by the heavy generators and foodstalls were of several varities such as Newaries, Popcorn, water drinks etc. Though I didn’t find any stall for the heavy drinks etc. I saw people throwing the water bottles and papers here and there after use. There was no arrangement for the dustbins.

Technically the show was successfull. There were so many fans enjoying the moments with MLTR. The light system was good. The were two large screens for the people in Silver tickets. There was heavy APF security.

hook_menu path not working in Drupal (6,7)

Right From Drupal website :

This hook enables modules to register paths in order to define how URL requests are handled. Paths may be registered for URL handling only, or they can register a link to be placed in a menu (usually the Navigation menu). A path and its associated information is commonly called a “menu router item”. This hook is rarely called (for example, when modules are enabled), and its results are cached in the database.

Suppose we defined a custom a wildcard menu path as shown below

<?php
  $items['my-module/%mymodule_abc/edit'] = array(
    'page callback' => 'mymodule_abc_edit',
    'page arguments' => array(1),
  );
?>

When path ‘my-module/123/edit’ is requested, your load function mymodule_abc_load() will be invoked with the argument ’123′, and should load and return an “abc” object with internal id 123:

<?php
  function mymodule_abc_load($abc_id) {
    return db_query("SELECT * FROM {mymodule_abc} WHERE abc_id = :abc_id", array(':abc_id' => $abc_id))->fetchObject();
  }
?>

This ‘abc’ object will then be passed into the callback functions defined for the menu item, such as the page callback function mymodule_abc_edit() to replace the integer 1 in the argument array.

For more information please visit actual source for this article
Drupal hook_menu article

[Solved] How to use hook_entity_view in drupal7 ?

I work in a team of developers and we separately develop modules in drupal. We are assigned to create entities, and there was time once I need to alter the view which was output of some other entity module. So, I am sharing here my experience how I did that.

Lets say we have two custom entity module
1. product module – creates a product entity
2. customer module – creates a customer entity

I need to alter the output of product entity module from customer module entity. In Drupal6 it was quite easy using node_api and then adding our own content in node->content, once we verified the correct content type. In Drupal7 we do it using the hook_entity_view.

To use hook_entity_view the product module should implement the single line of code highlighted in line 17. More information on hook_entity_view

function product_page_view( $product, $view_mode='full' ) {
// Remove previously built content, if exists.
  $product->content = array();

  if ($view_mode == 'teaser') {
    $product->content['title_en'] = array(
        '#markup' => filter_xss($product->title_en),
        '#weight' => -5,
    );
  }

// Build fields content.
  field_attach_prepare_view(PRODUCT_ENTITY, array($product->pid => $product), $view_mode);

  entity_prepare_view(PRODUCT_ENTITY, array($product->pid => $product));

  module_invoke_all('entity_view', $product, 'product', 'full', $GLOBALS['language_content']->language);

  $product->content += field_attach_view(PRODUCT_ENTITY, $product, $view_mode);

  /*
   * Specify the theme to use and set the #element. Note that the
   * key you use to pass the entity object must match the key you
   * set in in the variables in entity_theme().
   *
   */
  $product->content += array(
      '#theme' => 'product',
      '#element' => $product,
      '#view_mode' => 'full',
      '#language' => NULL,
  );

  return $product->content;
}

After implementating that code in product entity module. There is one more step. We now finally need to use hook_entity_view hook in customer module, which is similar to using other hooks in drupal. i.e. modulename_entity_view().

Below code is roughly a random sample code, that I picked up and altered the variables to depict product and customer relationships.

we might be using the same hook to alter the output of more than one entity module so, I am checking here the $type variable and then depending on the cases, I have used my output logic.

Here I have simply added my own content to the output of product entity module. This is done by the code from line 13-18.

function customer_entity_view( $entity, $type, $view_mode, $langcode ) {
  $t = 0;
  switch ($type) {
    case 'product':
      $productStatus = entity_get_controller(PRODUCT_ENTITY)->getProductStatus($product->pid);

      if ($productStatus == 'yes') {
        $output = drupal_get_form('customer_product_page_form', $product->pid);
        $body = drupal_render($output);

	// Alter the output of product entity module
	// Add your customer output to the output of product entity module
        $entity->content['product'] = array(
            '#prefix' => '<div id="customer_product_info">', // used by javascripts to populate sliders
            '#suffix' => '</div>',
            '#markup' => $body,
            '#weight' => -10,
        );
      }
      break;
    default:break;
  }
}

If there is anything that you don’t understand. Please mention it in the comments. I will try to make them clear as far as possible.

Automatic ajax call using jQuery

Total used files :

  • index.php
  • jquery.js
  • random.php

I am using jQuery’s setInterval() method to automatically make the ajax call in every 2 seconds.

index.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Refresh Page itself</title>
    <script type="text/javascript" src="jquery.js"></script>
    <script>
      $(document).ready(function(){
        var callAjax = function(){
          $.ajax({
            method:'get',
            url:'random.php',
            success:function(data){
              $("#sample").html(data);
            }
          });
        }
        setInterval(callAjax,2000);
      });
    </script>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <?php
    print "Below number changes in 2 seconds interval, View-Source of this page to see the usuage of jquery for content refresh.<div id='sample'>100 </div>";
    ?>
  </body>
</html>

In above code, the interesting code is in line 17,

setInterval(callAjax,2000);

which calls the callAjax function in every 2 seconds. Here 2000 is supplied in milliseconds.

line 11 – sets the url to “random.php”

line 13 – replaces the #sample div with the response from the “random.php” file that is the output of

print 5*rand(1,100);

And this is the code for “random.php” that is called by ajax call in every 2 seconds.
random.php

<?php
print 5*rand(1,100);

You can test the demo online at http://www.samundra.com.np/refresh/