plugins/generic/customBlockManager/CustomBlockManagerPlugin.inc.php

Go to the documentation of this file.
00001 <?php
00015 import('classes.plugins.GenericPlugin');
00016 
00017 class CustomBlockManagerPlugin extends GenericPlugin {
00018 
00019    function getName() {
00020       return 'CustomBlockManagerPlugin';
00021    }
00022 
00023    function getDisplayName() {
00024       return __('plugins.generic.customBlockManager.displayName');
00025    }
00026 
00027    function getDescription() {
00028       return __('plugins.generic.customBlockManager.description');
00029    }   
00030 
00031    function register($category, $path) {
00032       if (!Config::getVar('general', 'installed')) return false;
00033       if (parent::register($category, $path)) { 
00034          if ( $this->getEnabled() ) {
00035             HookRegistry::register('PluginRegistry::loadCategory', array(&$this, 'callbackLoadCategory'));           
00036          }
00037          $this->addLocaleData();
00038          return true;
00039       }
00040       return false;
00041    }
00042    
00050    function callbackLoadCategory($hookName, $args) {
00051       $category =& $args[0];
00052       $plugins =& $args[1];
00053       switch ($category) {
00054          case 'blocks':
00055             $this->import('CustomBlockPlugin');
00056             
00057             $conference =& Request::getConference();
00058             if ( !$conference ) return false;
00059             
00060             $blocks = $this->getSetting($conference->getId(), 0, 'blocks');
00061             if ( !is_array($blocks) ) break;
00062             $i= 0;
00063             foreach ( $blocks as $block ) {
00064                $blockPlugin = new CustomBlockPlugin($block);
00065                
00066                //default the block to being enabled
00067                if ( $blockPlugin->getEnabled() !== false) {
00068                   $blockPlugin->setEnabled(true);
00069                }
00070                //default the block to the right sidebar
00071                if ( !is_numeric($blockPlugin->getBlockContext())) {
00072                   $blockPlugin->setBlockContext(BLOCK_CONTEXT_RIGHT_SIDEBAR);
00073                }
00074                $plugins[$blockPlugin->getSeq()][$blockPlugin->getPluginPath() . $i] =& $blockPlugin;
00075                
00076                $i++;
00077                unset($blockPlugin);
00078             }
00079             break;
00080       }
00081       return false;
00082    }  
00083 
00087    function getEnabled() {
00088       $conference =& Request::getConference();
00089       $conferenceId = $conference?$conference->getId():0;
00090       return $this->getSetting($conferenceId, 0, 'enabled');
00091    }
00092 
00096    function setEnabled($enabled) {
00097       $conference =& Request::getConference();
00098       $conferenceId = $conference?$conference->getId():0;
00099       $this->updateSetting($conferenceId, 0, 'enabled', $enabled);
00100    }
00101 
00105    function getManagementVerbs() {
00106       $verbs = array();
00107       if ($this->getEnabled()) {
00108          $verbs[] = array(
00109             'disable',
00110             __('manager.plugins.disable')
00111          );
00112          $verbs[] = array(
00113             'settings',
00114             __('plugins.generic.customBlockManager.settings')
00115          );       
00116       } else {
00117          $verbs[] = array(
00118             'enable',
00119             __('manager.plugins.enable')
00120          );
00121       }
00122       return $verbs;
00123    }
00124 
00128    function manage($verb, $args) {
00129       $returner = true;
00130 
00131       $templateMgr =& TemplateManager::getManager();
00132       $templateMgr->register_function('plugin_url', array(&$this, 'smartyPluginUrl'));
00133 
00134       $pageCrumbs = array(
00135          array(
00136             Request::url(null, null, 'user'),
00137             'navigation.user'
00138          ),
00139          array(
00140             Request::url(null, null, 'manager'),
00141             'user.role.manager'
00142          )
00143       );
00144       
00145       $conference =& Request::getConference();
00146       
00147       switch ($verb) {
00148          case 'enable':
00149             $this->setEnabled(true);
00150             break;
00151          case 'disable':
00152             $this->setEnabled(false);
00153             break;
00154          case 'settings':
00155             $pageCrumbs[] = array(
00156                Request::url(null, null, 'manager', 'plugins'),
00157                __('manager.plugins'),
00158                true
00159             );
00160             $templateMgr->assign('pageHierarchy', $pageCrumbs);
00161 
00162             $this->import('SettingsForm');
00163             $form = new SettingsForm($this, $conference->getId());
00164             $form->readInputData();
00165             
00166             if (Request::getUserVar('addBlock')) {
00167                // Add a block
00168                $editData = true;
00169                //$blocks = is_null($form->getData('blocks'))?array():$form->getData('blocks');
00170                $blocks = $form->getData('blocks');
00171                array_push($blocks, '');
00172                $form->_data['blocks'] = $blocks;
00173 
00174             } else if (($delBlock = Request::getUserVar('delBlock')) && count($delBlock) == 1) {
00175                // Delete an block
00176                $editData = true;
00177                list($delBlock) = array_keys($delBlock);
00178                $delBlock = (int) $delBlock;
00179                $blocks = $form->getData('blocks');
00180                if (isset($blocks[$delBlock]) && !empty($blocks[$delBlock])) {
00181                   $deletedBlocks = explode(':', $form->getData('deletedBlocks'));
00182                   array_push($deletedBlocks, $blocks[$delBlock]);
00183                   $form->setData('deletedBlocks', join(':', $deletedBlocks));
00184                }
00185                array_splice($blocks, $delBlock, 1);
00186                $form->_data['blocks'] = $blocks;
00187             } else if ( Request::getUserVar('save') ) {
00188                $editData = true;
00189                $form->execute();
00190             } else {
00191                $form->initData();
00192             }
00193 
00194             if ( !isset($editData) && $form->validate()) {
00195                $form->execute();
00196                $form->display();
00197                exit;
00198             } else {
00199                $form->display();
00200                exit;
00201             }
00202             $returner = true;
00203             break;
00204          }
00205          $returner = false;            
00206    }
00207 }
00208 
00209 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7