Monday, December 6, 2010

CodeIgniter #1

I have not done yet with ZendFramework, Now I am asked to learn CodeIgniter lol. What I think about CodeIgniter is, it is more friendly than ZendFramework haha... I am not sure tho, I found it was easier for me to understand it, I think it is because I have learn the structure of ZendFramework and learn about MVC on ZendFramework before CodeIgniter.

I wish to write more about CodeIgniter, but I have many things else to do... I wish I am not so busy.

Friday, November 12, 2010

Learning ZendFramework Part #2

My progress today for my first zend framework project is that, I have been able to set up ZF on netbeans lol. Its cool so far even tho I am still a bit confuse.

For the tutorial, I can not explain here yet, I am still busy with other stuff, but I am open for any question.

Wednesday, November 10, 2010

Learning ZendFramework Part #1

So, since the past 3 days I start to learn ZendFramework, and I stuck didn't know what to do how to make php.exe readable by ZF, and the error message appear is :
php.exe is not recognized as an internal or external command operable program or batch file
Thanks to a friend for helping me out, it works now! and below is the step to fix the issue:
  1. go to ZendFramework directory /bin/zf.bat
  2. Edit zf.bat and change the path on the line 42:
    - REM "%PHP_BIN%" -d safe_mode=Off -f "%ZF_SCRIPT%" -- %*
    + D:\server\php\php.exe -d safe_mode=Off -f "%ZF_SCRIPT%" -- %*
And of course the path would be depend on where you put your php folder. That is it!

I will update more about my Zend Framework project later.

Sunday, September 26, 2010

Example of hook_comment & drupal_mail

Below is the example of drupal mail in the hook comment
function MODULENAME_comment(&$a1, $op){
    switch($op){
      case 'insert' :
        $nid = $a1['nid'];
        $node = node_load($nid);
        $account = user_load($node->uid);
 

        //Collect $params contents values to be used on hook_mail
        $params['commentator'] = $a1->name;
        $params['title'] = $node->title;
        $params['type'] = $node->type;
        $params['nid'] = $node->nid;
        $params['language'] = $account->language;
        $params['nodeauthor'] = $node->name;
        drupal_mail('MODULENAME', 'commentnotice', $account->mail, user_preferred_language($account), $params);    
    }
}


// define the drupal hook_mail
function MODULENAME_mail($key, &$message, $params){
  switch($key){
    case 'commentnotice' :
      $language = $message['language'];
      $message['subject'] = t('Notification from @site', array('@site' => variable_get('site_name', NULL)), $language);
      $message['body'] = t('Dear @username \n\n@commentator commented on your @type', array('@username' => $params['nodeauthor'], '@commentator' => $params['commentator'], '@type' => $params['type']), $language->language);
      break;
  }
}

Wednesday, September 1, 2010

Removing some content from profile page

If there is some content on profile page you dont want to display, for example, you want to remove user summary, you can do it by using hook_profile_form

/**
 * Implementation of hook_profile_alter().
 */
function helper_profile_alter(&$account) {

  //var_dump($account->content);
  unset($account->content['summary']['#title']); //remove summary
  unset($account->content['summary']['member_for']); 
}

Example of hook form alter

This is an example for altering form

function helper_form_alter(&$form, &$form_state, $form_id) {   
    //var_dump($form_id);
    switch ($form_id){
        case 'user_profile_form' :
            unset ($form['user_terms']); // remove user_term form
            unset ($form['locale']); //remove locale form
            break;
    }

}

Thursday, August 19, 2010

Hook form alter

Example of hook_form alter

/*
 * implementation of hook_form_alter
 * remove user term form by
 * removing user_term fieldset
 */
function helper_form_alter(&$form, $form_state, $form_id) {
  //if ($form_id == 'user-profile-form') {
      $form['user_terms']['#type']['fieldset'] = FALSE;
    //}
    dsm($form_id);
  }

Example of theme links option #2


<?php
global $user;
$uid = $user->uid;
$app = 0;
$friend_req = db_result(db_query("SELECT  COUNT(*) AS counts FROM {user_relationships} ur WHERE ur.requestee_id = %d AND ur.approved = %d", $uid, $app));
$message = privatemsg_unread_count();
$links = array();
if($friend_req >= 1){
  $links[] = array(
    'title' => format_plural($friend_req, t('1 Friendship request'), t('@count Friendship requests')),
    'href' => 'relationships/requests',
    'attributes' => array('class' => 'friend-requests'),
  );
}

if($message >= 1){
  $message_count = format_plural($message, t('1 New message'), t('@count New messages'));
  $links[] = array(
    'title' => format_plural($message, t('1 New message'), t('@count New messages')),
    'href' => 'messages',
    'attributes' => array('class' => 'messages'),
  );
}
if($links){
  print theme('links', $links);
}

?>


Example of theme links

Below is the example of used of theme_links

<?php
$friend_req = $row->counts; //says db_query has been defined
$message = privatemsg_unread_count(); // count new privatemsg

if($friend_req >= 1){
    $friend_req_count = format_plural($friend_req, t('1 Friendship request'), t('@count Friendship requests'));
}

if($message >= 1){
    $message_count = format_plural($message, t('1 New message'), t('@count New messages'));   
}




//define $links as array
$links = array();
$links[] = array('title' => $friend_req_count, 'href' => 'relationships/requests', 'attributes' => array('class' => 'friend-requests'));
$links[] = array('title' => $message_count, 'href' => 'messages', 'attributes' => array('class' => 'messages'));
 
//use theme links to display link
print theme('links', $links);

?>

Example of format_plural combined with theme item_list

Below it the example of used of Drupal format_plural combined with theme item_list for showing notifications of new messages and friendship request using privatemsg module and user_relationships module.

<?php
global $user;
$uid = $user->uid;
$app = 0;
$row = db_fetch_object(db_query("SELECT  COUNT(*) AS counts FROM {user_relationships} ur WHERE ur.requestee_id = %d AND ur.approved = %d", $uid, $app));
$friend_req= $row->counts;
$message = privatemsg_unread_count();

$items = array();

if($friend_req >= 1){
    $friend_req_count = format_plural($friend_req, t('1 Friendship request'), t('@count Friendship requests'));
    $items[] = l($friend_req_count, 'relationships/requests', array('attributes' => array('class' => 'friend-requests')));
}

if($message >= 1){
    $message_count = format_plural($message, t('1 New message'), t('@count New messages'));
    $items[] = l($message_count, 'messages', array('attributes' => array('class' => 'messages')));
}

if(COUNT($items) >= 1){
    print theme('item_list', $items);
}