Skip to main content
Improve title and add relevant tag
Link
Pierre.Vriens
  • 36k
  • 40
  • 50
  • 182

Displaying How to display multiple blocks using a custom calendar module?

deleted 188 characters in body; edited title
Source Link
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

D7 module development - displaying Displaying multiple blocks / mysql

function churchcal_block_info() {
 
    $blocks = array();
    
    $blocks['monthly_calendar'] = array(
        'info' => t('Display the monthly calendar.'),
        'cache' => DRUPAL_NO_CACHE,
    );
    
    
    
    //get calendars
    include('db.php');
    $result = mysql_query("SELECT * FROM churchcal_calendars WHERE set_default != '1'");
        while($row = mysql_fetch_array($result)) {
            
            $cal_name = $row['name'];
            $sys_cal_name = strtolower(str_replace(' ', '_', $cal_name));
            
            $blocks['churchcal_' . $sys_cal_name] = array(
                'info' => t('Display calendar for ' . $cal_name . '.'),
                'cache' => DRUPAL_NO_CACHE,
            );
            
            
        }
    
    
    
    return $blocks;
    
}

 

function churchcal_block_view($block_name = '') {
    
    if ($block_name == 'monthly_calendar') {
    
        $content = monthlyCalendar();
        
        $block = array (
            'subject' => t(''),
            'content' => $content,
        );
        
    }
        
        //get calendars
        include('db.php');
        $result = mysql_query("SELECT * FROM churchcal_calendars WHERE set_default != '1'");
            while($row = mysql_fetch_array($result)) {
                
                
                $cal_name = $row['name'];
                $sys_cal_name = strtolower(str_replace(' ', '_', $cal_name));
                $cal_id = $row['id'];
                
                if($block_name == 'churchcal_' . $sys_cal_name) {
                    
                    $content .= churchCal($cal_id);
                    
                    $block = array(
                        'subject' => t('Upcoming Events'),
                        'content' => $content,
                    );
                
            }
        
        
        return $block;
        
    }
}

How can I display a calendar for each calendar in the db? How can I display a calendar for each calendar in the db?

D7 module development - displaying multiple blocks / mysql

function churchcal_block_info() {
 
    $blocks = array();
    
    $blocks['monthly_calendar'] = array(
        'info' => t('Display the monthly calendar.'),
        'cache' => DRUPAL_NO_CACHE,
    );
    
    
    
    //get calendars
    include('db.php');
    $result = mysql_query("SELECT * FROM churchcal_calendars WHERE set_default != '1'");
        while($row = mysql_fetch_array($result)) {
            
            $cal_name = $row['name'];
            $sys_cal_name = strtolower(str_replace(' ', '_', $cal_name));
            
            $blocks['churchcal_' . $sys_cal_name] = array(
                'info' => t('Display calendar for ' . $cal_name . '.'),
                'cache' => DRUPAL_NO_CACHE,
            );
            
            
        }
    
    
    
    return $blocks;
    
}

 

function churchcal_block_view($block_name = '') {
    
    if ($block_name == 'monthly_calendar') {
    
        $content = monthlyCalendar();
        
        $block = array (
            'subject' => t(''),
            'content' => $content,
        );
        
    }
        
        //get calendars
        include('db.php');
        $result = mysql_query("SELECT * FROM churchcal_calendars WHERE set_default != '1'");
            while($row = mysql_fetch_array($result)) {
                
                
                $cal_name = $row['name'];
                $sys_cal_name = strtolower(str_replace(' ', '_', $cal_name));
                $cal_id = $row['id'];
                
                if($block_name == 'churchcal_' . $sys_cal_name) {
                    
                    $content .= churchCal($cal_id);
                    
                    $block = array(
                        'subject' => t('Upcoming Events'),
                        'content' => $content,
                    );
                
            }
        
        
        return $block;
        
    }
}

How can I display a calendar for each calendar in the db?

Displaying multiple blocks

function churchcal_block_info() {
    $blocks = array();
    $blocks['monthly_calendar'] = array(
        'info' => t('Display the monthly calendar.'),
        'cache' => DRUPAL_NO_CACHE,
    );
    
    //get calendars
    include('db.php');
    $result = mysql_query("SELECT * FROM churchcal_calendars WHERE set_default != '1'");
        while($row = mysql_fetch_array($result)) {      
            $cal_name = $row['name'];
            $sys_cal_name = strtolower(str_replace(' ', '_', $cal_name));
            $blocks['churchcal_' . $sys_cal_name] = array(
                'info' => t('Display calendar for ' . $cal_name . '.'),
                'cache' => DRUPAL_NO_CACHE,
            );
        }
    
    return $blocks;
}

function churchcal_block_view($block_name = '') {
    if ($block_name == 'monthly_calendar') {
        $content = monthlyCalendar();
        $block = array (
            'subject' => t(''),
            'content' => $content,
        );
    }
        
        //get calendars
        include('db.php');
        $result = mysql_query("SELECT * FROM churchcal_calendars WHERE set_default != '1'");
            while($row = mysql_fetch_array($result)) {
                $cal_name = $row['name'];
                $sys_cal_name = strtolower(str_replace(' ', '_', $cal_name));
                $cal_id = $row['id'];
                
                if($block_name == 'churchcal_' . $sys_cal_name) {
                    $content .= churchCal($cal_id);
                    $block = array(
                        'subject' => t('Upcoming Events'),
                        'content' => $content,
                    );
            }
        
        return $block;
    }
}

How can I display a calendar for each calendar in the db?

Source Link

D7 module development - displaying multiple blocks / mysql

I have created a calendar module in Drupal 7. In addition to the default calendar on the website, my client can create a new calendar for events specific to a particular page.

Say that they want to add "Youth" and "College and Career" calendars; the db table looks like this:

table: churchcal_calendars

------id------|------name-----|------set_default------

------1-------------Main---------------1--------

------2-------------Youth--------------0---------

------3-------College and Career---------0-----------

In my churchcal.module file, I have set hook_block_info and hook_block_view:

function churchcal_block_info() {

    $blocks = array();
    
    $blocks['monthly_calendar'] = array(
        'info' => t('Display the monthly calendar.'),
        'cache' => DRUPAL_NO_CACHE,
    );
    
    
    
    //get calendars
    include('db.php');
    $result = mysql_query("SELECT * FROM churchcal_calendars WHERE set_default != '1'");
        while($row = mysql_fetch_array($result)) {
            
            $cal_name = $row['name'];
            $sys_cal_name = strtolower(str_replace(' ', '_', $cal_name));
            
            $blocks['churchcal_' . $sys_cal_name] = array(
                'info' => t('Display calendar for ' . $cal_name . '.'),
                'cache' => DRUPAL_NO_CACHE,
            );
            
            
        }
    
    
    
    return $blocks;
    
}



function churchcal_block_view($block_name = '') {
    
    if ($block_name == 'monthly_calendar') {
    
        $content = monthlyCalendar();
        
        $block = array (
            'subject' => t(''),
            'content' => $content,
        );
        
    }
        
        //get calendars
        include('db.php');
        $result = mysql_query("SELECT * FROM churchcal_calendars WHERE set_default != '1'");
            while($row = mysql_fetch_array($result)) {
                
                
                $cal_name = $row['name'];
                $sys_cal_name = strtolower(str_replace(' ', '_', $cal_name));
                $cal_id = $row['id'];
                
                if($block_name == 'churchcal_' . $sys_cal_name) {
                    
                    $content .= churchCal($cal_id);
                    
                    $block = array(
                        'subject' => t('Upcoming Events'),
                        'content' => $content,
                    );
                
            }
        
        
        return $block;
        
    }
}

The "monthly_calendar" is the main calendar, and there is no problem with that block.

Beneath the monthly calendar is the code for the additional calendars. I can see each calendar in admin/structure/block page (for the example "Display calendar for Youth", "Display calendar for College and Career"). That part works great. However, I can only see one calendar, and that is whichever is first in the db with default != 1. In this example, the Youth calendar would display, but not the College and Career. So, it tells me that hook_block_info is correct and there is a problem with hook_block_view.

How can I display a calendar for each calendar in the db?