Fork me on GitHub

Custom Block & Theme Integration  Bottom

  • All,
    I have been writing modules recently and have just begun to delve into writing blocks for the corresponding modules. I have been able to write the block and have it display in the standard theme I'm using (woohoo!!!). Now I want to expand on this and change my theme around a little.
    I have an experimental theme that I want to add a block to but I'm not quite sure of the syntax of the "pnBlockShow()" function.
    I've referenced the pnAPI guide, but there wasn't a lot of information to be had.
    I'm almost there, but I'm getting stuck at the same place I got confused when developing the block.
    I used the "Example" module's pnBlocks directory as a base for mine. I changed the name of the "first" function and there is where I added my code.
    Here is an example of my "first.php" file in the pnBlocks directory of my module (there is only one function so I'll only post it):

    Code

    function EquipmentRequest_firstblock_display($blockinfo)
    {
        // Security check - important to do this as early as possible to avoid
        // potential security holes or just too much wasted processing.  
        // Note that we have EquipmentRequest:Firstblock: as the component.
        if (!pnSecAuthAction(0,
                             'EquipmentRequest:Firstblock:',
                             "$blockinfo[title]::",
                             ACCESS_READ)) {
            return false;
        }

        // Get variables from content block
        $vars = pnBlockVarsFromContent($blockinfo['content']);

        // Defaults
        if (empty($vars['numitems'])) {
            $vars['numitems'] = 5;
        }

        // Check if the EquipmentRequest module is available.
        if (!pnModAvailable('EquipmentRequest')) {
            return false;
        }

        // Load API.  All of the actual work for the creation of the new item is
        // done within the API, so we need to load that in before we can do
        // anything.  If the API fails to load an appropriate error message is
        // posted and the function returns
        if (!pnModAPILoad('EquipmentRequest', 'user')) {
            return false;
        }
       
        // Call the modules API to get the items
        $items = pnModAPIFunc('EquipmentRequest',
                              'user',  
                              'getLastFive',
                              array('uid'=>pnUserGetVar(uid)))

        // Check for no items returned
        if (empty($items)) {
            return;
        }

        /*// Call the modules API to get the numitems
        $countitems = pnModAPIFunc('EquipmentRequest',
                              'user',  
                              'countitems');   
                             
        // Compare the numitems with the blocksetting
        if ($countitems <= $vars['numitems']) {
            $vars['numitems'] = $countitems;
        } */
     
           
        // Create output object
        // Note that for a block the corresponding module must be passed.
        $pnRender =& new pnRender('EquipmentRequest');
       
        // Display each item, permissions permitting
        $shown_results = 0;
        $EquipmentRequestitems = array();
        foreach ($items as $item) {
            $EquipmentRequestitems[]=array('recordID'=>$item['recordID'],'date'=>date("M,jS",strtotime($item['date'])),'url'=>pnModURL('EquipmentRequest','user','viewSingle',array('recordID'=>$item['recordID'])));
        }
        $pnRender->assign('items', $EquipmentRequestitems);
        $pnRender->assign('homeURL',pnModURL('EquipmentRequest','user','main'));
        $pnRender->assign('newRequestLink',pnModURL('EquipmentRequest','user','showForm'));
        // Populate block info and pass to theme
        $blockinfo['content'] = $pnRender->fetch('EquipmentRequest_block_first.htm');

        return themesideblock($blockinfo);
    }

    The syntax of the pnBlockShow() function is as follows (taken from pnAPI guide):

    Code

    pnBlockShow('modname','block','blockinfo')

    Now here's my question, and I apologize if it seems rather rudimentary, but there is hardly any good docs online relating to block devel (hell, even this forum, as helpful as it is, has very few block development related threads):
    Based upon the information given above (which I hope is enough), what parameters do I send the pnBlockShow() function?
    Here's what I have now (which incidentally doesn't work **SHOCKING**):

    Code

    <?php if(!$showBlock=pnBlockShow('EquipmentRequest','firstblock')){
          echo "SOMETHING BLUUUUUUUE";
          }else{
          echo $showBlock;
          } ?>

    Thanks in advance for your help.
  • Aha!
    I have found the solution:
    The part I was having problems with is the block info parameter you're supposed to send to the pnBlockShow() function.
    Here is the working code:

    Code

    <?php pnBlockShow('EquipmentRequest','first',pnBlockGetInfo(30)); ?>

    The "30" is the bid listed in the <prefix>blocks table in the DB.</prefix>

This list is based on users active over the last 60 minutes.