当前位置: 首页>>代码示例>>PHP>>正文


PHP ModUtil::available方法代码示例

本文整理汇总了PHP中ModUtil::available方法的典型用法代码示例。如果您正苦于以下问题:PHP ModUtil::available方法的具体用法?PHP ModUtil::available怎么用?PHP ModUtil::available使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ModUtil的用法示例。


在下文中一共展示了ModUtil::available方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: content_needleapi_content

/**
 * Content needle
 * @param $args['nid'] needle id
 * @return array()
 */
function content_needleapi_content($args)
{
    $dom = ZLanguage::getModuleDomain('Content');
    // Get arguments from argument array
    $nid = $args['nid'];
    unset($args);
    // cache the results
    static $cache;
    if (!isset($cache)) {
        $cache = array();
    }
    if (!empty($nid)) {
        if (!isset($cache[$nid])) {
            // not in cache array
            if (ModUtil::available('Content')) {
                $contentpage = ModUtil::apiFunc('Content', 'Page', 'getPage', array('id' => $nid, 'includeContent' => false));
                if ($contentpage != false) {
                    $cache[$nid] = '<a href="' . DataUtil::formatForDisplay(ModUtil::url('Content', 'user', 'view', array('pid' => $nid))) . '" title="' . DataUtil::formatForDisplay($contentpage['title']) . '">' . DataUtil::formatForDisplay($contentpage['title']) . '</a>';
                } else {
                    $cache[$nid] = '<em>' . DataUtil::formatForDisplay(__('Unknown id', $dom)) . '</em>';
                }
            } else {
                $cache[$nid] = '<em>' . DataUtil::formatForDisplay(__('Content not available', $dom)) . '</em>';
            }
        }
        $result = $cache[$nid];
    } else {
        $result = '<em>' . DataUtil::formatForDisplay(__('No needle id', $dom)) . '</em>';
    }
    return $result;
}
开发者ID:robbrandt,项目名称:Content,代码行数:36,代码来源:content.php

示例2: install

    public function install() {
        if (!SecurityUtil::checkPermission('IWdocmanager::', '::', ACCESS_ADMIN)) {
            return LogUtil::registerPermissionError();
        }
        // Checks if module IWmain is installed. If not returns error
        if (!ModUtil::available('IWmain')) {
            return LogUtil::registerError(__('Module IWmain is required. You have to install the IWmain module previously to install it.'));
        }

        // Check if the version needed is correct
        $versionNeeded = '3.0.0';
        if (!ModUtil::func('IWmain', 'admin', 'checkVersion', array('version' => $versionNeeded))) {
            return false;
        }

        if (!DBUtil::createTable('IWdocmanager'))
            return false;
        if (!DBUtil::createTable('IWdocmanager_categories'))
            return false;

        //Create indexes
        $table = DBUtil::getTables();
        $c = $table['IWdocmanager_column'];
        DBUtil::createIndex($c['author'], 'IWdocmanager', 'author');
        DBUtil::createIndex($c['categoryId'], 'IWdocmanager', 'categoryId');

        //Create module vars
        $this->setVar('documentsFolder', 'documents')
                ->setVar('notifyMail', '')
                ->setVar('editTime', '45')
                ->setVar('deleteTime', '20');

        return true;
    }
开发者ID:projectesIF,项目名称:Sirius,代码行数:34,代码来源:Installer.php

示例3: display

    public function display($blockinfo) {
        // Security check (1)
        if (!SecurityUtil::checkPermission('IWmenu:topblock:', "$blockinfo[title]::", ACCESS_READ)) {
            return false;
        }

        // Check if the module is available. (2)
        if (!ModUtil::available('IWmenu')) {
            return false;
        }

        // Get variables from content block (3)
        //Get cached user menu
        $uid = is_null(UserUtil::getVar('uid')) ? '-1' : UserUtil::getVar('uid');

        //Generate menu
        $menu_estructure = ModUtil::apiFunc('IWmenu', 'user', 'getMenuStructure');
        // Defaults (4)
        if (empty($menu_estructure)) {
            return false;
        }

        // Create output object (6)
        $view = Zikula_View::getInstance('IWmenu');

        // assign your data to to the template (7)
        $view->assign('menu', $menu_estructure);

        // Populate block info and pass to theme (8)
        $menu = $view->fetch('IWmenu_block_top.htm');

        //$blockinfo['content'] = $menu;
        //return BlockUtil::themesideblock($blockinfo);
        return $menu;
    }
开发者ID:projectesIF,项目名称:Sirius,代码行数:35,代码来源:Top.php

示例4: display

    /**
     * Display the block.
     *
     * @param array $blockinfo A blockinfo structure.
     * 
     * @return string The rendered block.
     */
    public function display($blockinfo)
    {
        // Check if the Profile module is available or saving of login dates are disabled
        if (!ModUtil::available('Profile')) {
            return false;
        }

        // Security check
        if (!SecurityUtil::checkPermission('Profile:LastSeenblock:', "$blockinfo[title]::", ACCESS_READ)) {
            return false;
        }

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

        $this->view->setCaching(false);

        // get last x logged in user id's
        $users = ModUtil::apiFunc('Profile', 'memberslist', 'getall', array(
            'sortby'    => 'lastlogin',
            'numitems'  => $vars['amount'],
            'sortorder' => 'DESC',
        ));

        $this->view->assign('users', $users);

        $blockinfo['content'] = $this->view->fetch('profile_block_lastseen.tpl');

        return BlockUtil::themeBlock($blockinfo);
    }
开发者ID:projectesIF,项目名称:Sirius,代码行数:37,代码来源:Lastseen.php

示例5: display

 /**
  * Display block
  */
 public function display($blockinfo)
 {
     if (!SecurityUtil::checkPermission('Zgoodies:marqueeblock:', "{$blockinfo['bid']}::", ACCESS_OVERVIEW)) {
         return;
     }
     if (!ModUtil::available('Zgoodies')) {
         return;
     }
     $vars = BlockUtil::varsFromContent($blockinfo['content']);
     $lang = ZLanguage::getLanguageCode();
     // block title
     if (isset($vars['block_title'][$lang]) && !empty($vars['block_title'][$lang])) {
         $blockinfo['title'] = $vars['block_title'][$lang];
     }
     // marquee content
     if (isset($vars['marquee_content'][$lang]) && !empty($vars['marquee_content'][$lang])) {
         $vars['marquee_content_lang'] = $vars['marquee_content'][$lang];
     }
     if (!isset($vars['marquee_content'])) {
         $vars['marquee_content_lang'] = '';
     }
     $this->view->assign('vars', $vars);
     $this->view->assign('bid', $blockinfo['bid']);
     $blockinfo['content'] = $this->view->fetch('blocks/' . $vars['block_template']);
     if (isset($vars['block_wrap']) && !$vars['block_wrap']) {
         if (empty($blockinfo['title'])) {
             return $blockinfo['content'];
         } else {
             return '<h4>' . DataUtil::formatForDisplayHTML($blockinfo['title']) . '</h4>' . "\n" . $blockinfo['content'];
         }
     }
     return BlockUtil::themeBlock($blockinfo);
 }
开发者ID:nmpetkov,项目名称:Zgoodies,代码行数:36,代码来源:Marquee.php

示例6: display

    /**
     * Display block.
     *
     * @param array $blockInfo A blockinfo structure.
     *
     * @return string The rendered block.
     */
    public function display($blockInfo)
    {
        $renderedOutput = '';

        if (SecurityUtil::checkPermission('Accountlinks::', $blockInfo['title']."::", ACCESS_READ)) {
            // Get variables from content block
            $vars = BlockUtil::varsFromContent($blockInfo['content']);

            // Call the modules API to get the items
            if (ModUtil::available($this->name)) {
                $accountlinks = ModUtil::apiFunc($this->name, 'user', 'accountLinks');

                // Check for no items returned
                if (!empty($accountlinks)) {
                    $this->view->setCaching(Zikula_View::CACHE_DISABLED)
                               ->assign('accountlinks', $accountlinks);

                    // Populate block info and pass to theme
                    $blockInfo['content'] = $this->view->fetch('users_block_accountlinks.tpl');

                    $renderedOutput = BlockUtil::themeBlock($blockInfo);
                }
            }
        }

        return $renderedOutput;
    }
开发者ID:projectesIF,项目名称:Sirius,代码行数:34,代码来源:Accountlinks.php

示例7: settingsAction

 /**
  * @Route("/settings", options={"expose" = true})
  * @Template()
  * @Theme("admin")
  *
  * @param Request $request
  *
  * @return array|RedirectResponse
  */
 public function settingsAction(Request $request)
 {
     if (!$this->get('cmfcmf_media_module.security_manager')->hasPermission('settings', 'admin')) {
         throw new AccessDeniedException();
     }
     if ($request->query->get('update', false)) {
         $this->get('zikula.doctrine.schema_tool')->update(MediaModuleInstaller::getEntities());
     }
     $collectionTemplateCollection = $this->get('cmfcmf_media_module.collection_template_collection');
     $form = $this->createForm(new SettingsType($collectionTemplateCollection->getCollectionTemplateTitles()));
     $form->handleRequest($request);
     if ($form->isValid()) {
         $data = $form->getData();
         foreach ($data as $name => $value) {
             \ModUtil::setVar('CmfcmfMediaModule', $name, $value);
         }
         $this->addFlash('status', $this->__('Settings saved!'));
     }
     $scribiteInstalled = \ModUtil::available('Scribite');
     $descriptionEscapingStrategyForCollectionOk = true;
     $descriptionEscapingStrategyForMediaOk = true;
     if ($scribiteInstalled) {
         $mediaBinding = $this->get('hook_dispatcher')->getBindingBetweenAreas("subscriber.cmfcmfmediamodule.ui_hooks.media", "provider.scribite.ui_hooks.editor");
         $collectionBinding = $this->get('hook_dispatcher')->getBindingBetweenAreas("subscriber.cmfcmfmediamodule.ui_hooks.collection", "provider.scribite.ui_hooks.editor");
         $descriptionEscapingStrategyForCollectionOk = !is_object($collectionBinding) || \ModUtil::getVar('CmfcmfMediaModule', 'descriptionEscapingStrategyForCollection') == 'raw';
         $descriptionEscapingStrategyForMediaOk = !is_object($mediaBinding) || \ModUtil::getVar('CmfcmfMediaModule', 'descriptionEscapingStrategyForMedia') == 'raw';
     }
     return ['form' => $form->createView(), 'scribiteInstalled' => $scribiteInstalled, 'descriptionEscapingStrategyForCollectionOk' => $descriptionEscapingStrategyForCollectionOk, 'descriptionEscapingStrategyForMediaOk' => $descriptionEscapingStrategyForMediaOk];
 }
开发者ID:shefik,项目名称:MediaModule,代码行数:38,代码来源:SettingsController.php

示例8: display

 /**
  * Display the block.
  *
  * @param array $blockinfo the blockinfo structure
  *
  * @return string output of the rendered block
  */
 public function display($blockinfo)
 {
     // only show block content if the user has the required permissions
     if (!SecurityUtil::checkPermission('Reviews:ModerationBlock:', "{$blockinfo['title']}::", ACCESS_OVERVIEW)) {
         return false;
     }
     // check if the module is available at all
     if (!ModUtil::available('Reviews')) {
         return false;
     }
     if (!UserUtil::isLoggedIn()) {
         return false;
     }
     ModUtil::initOOModule('Reviews');
     $this->view->setCaching(Zikula_View::CACHE_DISABLED);
     $template = $this->getDisplayTemplate($vars);
     $workflowHelper = new Reviews_Util_Workflow($this->serviceManager);
     $amounts = $workflowHelper->collectAmountOfModerationItems();
     // assign block vars and fetched data
     $this->view->assign('moderationObjects', $amounts);
     // set a block title
     if (empty($blockinfo['title'])) {
         $blockinfo['title'] = $this->__('Moderation');
     }
     $blockinfo['content'] = $this->view->fetch($template);
     // return the block to the theme
     return BlockUtil::themeBlock($blockinfo);
 }
开发者ID:rmaiwald,项目名称:Reviews,代码行数:35,代码来源:Moderation.php

示例9: smarty_function_contentcodeeditor

/**
 * Content
 *
 * @copyright (C) 2007-2010, Content Development Team
 * @link http://github.com/zikula-modules/Content
 * @license See license.txt
 */
function smarty_function_contentcodeeditor($params, $view)
{
    $dom = ZLanguage::getModuleDomain('Content');
    $inputId = $params['inputId'];
    $inputType = isset($params['inputType']) ? $params['inputType'] : null;
    // Get reference to optional radio button that enables the editor (a hack for the HTML plugin).
    // It would have been easier just to read a $var in the template, but this won't work with a
    // Forms plugin - you would just get the initial value from when the page was loaded
    $htmlRadioButton = isset($params['htmlradioid']) ? $view->getPluginById($params['htmlradioid']) : null;
    $textRadioButton = isset($params['textradioid']) ? $view->getPluginById($params['textradioid']) : null;
    $html = '';
    $useBBCode = $textRadioButton == null && $inputType == 'text' && !$view->isPostBack() || $textRadioButton != null && $textRadioButton->checked;
    if ($useBBCode && ModUtil::available('BBCode')) {
        $html = "<div class=\"z-formrow\"><em class=\"z-sub\">";
        $html .= ModUtil::func('BBCode', 'User', 'bbcodes', array('textfieldid' => $inputId, 'images' => 0));
        $html .= "</em></div>";
    } else {
        if ($useBBCode && !ModUtil::available('BBCode')) {
            $html = "<div class=\"z-formrow\"><em class=\"z-sub\">";
            $html .= '(' . __("Please install the BBCode module to enable BBCodes display.", $dom) . ')';
            $html .= "</em></div>";
        }
    }
    return $html;
}
开发者ID:robbrandt,项目名称:Content,代码行数:32,代码来源:function.contentcodeeditor.php

示例10: smarty_function_moduleadminlinks

/**
 * Zikula_View function to display admin links for a module.
 *
 * Example:
 * {moduleadminlinks modname=Example start="[" end="]" seperator="|" class="z-menuitem-title"}
 *
 * Available parameters:
 *   - modname   Module name to display links for.
 *   - start     Start string (optional).
 *   - end       End string (optional).
 *   - seperator Link seperator (optional).
 *   - class     CSS class (optional).
 *
 * @param array       $params  All attributes passed to this function from the template.
 * @param Zikula_View $view    Reference to the Zikula_View object.
 *
 * @return string A formatted string containing navigation for the module admin panel.
 */
function smarty_function_moduleadminlinks($params, $view)
{
    LogUtil::log(__f('Warning! Template plugin {%1$s} is deprecated, please use {%2$s} instead.', array('moduleadminlinks', 'modulelinks')), E_USER_DEPRECATED);

    // set some defaults
    $start     = isset($params['start'])    ? $params['start']    : '[';
    $end       = isset($params['end'])      ? $params['end']      : ']';
    $seperator = isset($params['seperator'])? $params['seperator']: '|';
    $class     = isset($params['class'])    ? $params['class']    : 'z-menuitem-title';

    $modname = $params['modname'];
    unset ($params['modname']);

    if (!isset($modname) || !ModUtil::available($modname)) {
        $modname = ModUtil::getName();
    }

    // check our module name
    if (!ModUtil::available($modname)) {
        $view->trigger_error('moduleadminlinks: '.__f("Error! The '%s' module is not available.", DataUtil::formatForDisplay($modname)));
        return false;
    }

    // get the links from the module API
    $links = ModUtil::apiFunc($modname, 'admin', 'getlinks', $params);

    // establish some useful count vars
    $linkcount = count($links);

    $adminlinks = "<span class=\"$class\">$start ";
    foreach ($links as $key => $link) {
        $id = '';
        if (isset($link['id'])) {
            $id = 'id="' . $link['id'] . '"';
        }
        if (!isset($link['title'])) {
            $link['title'] = $link['text'];
        }
        if (isset($link['disabled']) && $link['disabled'] == true) {
            $adminlinks .= "<span $id>" . '<a class="z-disabledadminlink" title="' . DataUtil::formatForDisplay($link['title']) . '">' . DataUtil::formatForDisplay($link['text']) . '</a> ';
        } else {
            $adminlinks .= "<span $id><a href=\"" . DataUtil::formatForDisplay($link['url']) . '" title="' . DataUtil::formatForDisplay($link['title']) . '">' . DataUtil::formatForDisplay($link['text']) . '</a> ';
        }
        if ($key == $linkcount-1) {
            $adminlinks .= '</span>';
            continue;
        }
        // linebreak
        if (isset($link['linebreak']) && $link['linebreak'] == true) {
            $adminlinks .= "</span>\n ";
            $adminlinks .= "$end</span><br /><span class=\"$class\">$start ";
        } else {
            $adminlinks .= "$seperator</span>\n ";
        }
    }
    $adminlinks .= "$end</span>\n";

    return $adminlinks;
}
开发者ID:,项目名称:,代码行数:77,代码来源:

示例11: display

    /**
     * display block
     */
    public function display($blockinfo)
    {
        // Security check
        if (!SecurityUtil::checkPermission('Admin:adminnavblock', "$blockinfo[title]::$blockinfo[bid]", ACCESS_ADMIN)) {
            return;
        }

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

        // Call the modules API to get the items
        if (!ModUtil::available('Admin')) {
            return;
        }

        $items = ModUtil::apiFunc('Admin', 'admin', 'getall');

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

        // get admin capable modules
        $adminmodules = ModUtil::getAdminMods();
        $adminmodulescount = count($adminmodules);

        // Display each item, permissions permitting
        $admincategories = array();
        foreach ($items as $item) {
            if (SecurityUtil::checkPermission('Admin::', "$item[name]::$item[cid]", ACCESS_READ)) {
                $adminlinks = array();
                foreach ($adminmodules as $adminmodule) {
                    // Get all modules in the category
                    $catid = ModUtil::apiFunc('Admin', 'admin', 'getmodcategory',
                                              array('mid' => ModUtil::getIdFromName($adminmodule['name'])));

                    if (($catid == $item['cid']) || (($catid == false) && ($item['cid'] == $this->getVar('defaultcategory')))) {
                        $modinfo = ModUtil::getInfoFromName($adminmodule['name']);
                        $menutexturl = ModUtil::url($modinfo['name'], 'admin');
                        $menutexttitle = $modinfo['displayname'];
                        $adminlinks[] = array('menutexturl' => $menutexturl,
                                              'menutexttitle' => $menutexttitle);
                    }
                }
                $admincategories[] = array('url' => ModUtil::url('Admin', 'admin', 'adminpanel', array('cid' => $item['cid'])),
                                           'title' => DataUtil::formatForDisplay($item['name']),
                                           'modules' => $adminlinks);
            }
        }

        $this->view->assign('admincategories', $admincategories);

        // Populate block info and pass to theme
        $blockinfo['content'] = $this->view->fetch('admin_block_adminnav.tpl');

        return BlockUtil::themeBlock($blockinfo);
    }
开发者ID:projectesIF,项目名称:Sirius,代码行数:60,代码来源:Adminnav.php

示例12: display

 function display()
 {
     if (ModUtil::available('BBCode') && $this->codeFilter == 'bbcode') {
         $code = '[code]' . $this->text . '[/code]';
         PageUtil::addVar('stylesheet', 'modules/BBCode/style/style.css');
         return ModUtil::apiFunc('BBCode', 'User', 'transform', array('message' => $code));
     } else {
         return $this->transformCode($this->text, true);
     }
 }
开发者ID:robbrandt,项目名称:Content,代码行数:10,代码来源:ComputerCode.php

示例13: initialize

 function initialize(Zikula_Form_View $view)
 {
     $view->caching = false;
     $view->add_core_data();
     $view->assign('avatarpath', ModUtil::getVar('Users', 'avatarpath'));
     $view->assign('avatarpath_writable', is_writable(ModUtil::getVar('Users', 'avatarpath')));
     $view->assign('pnphpbb_installed', ModUtil::available('pnphpbb'));
     $view->assign('forumdir_writable', is_writable(ModUtil::getVar('Avatar', 'forumdir')));
     return true;
 }
开发者ID:robbrandt,项目名称:Avatar,代码行数:10,代码来源:ModifyConfig.php

示例14: smarty_function_selectmodobject

/**
 * render plugin for fetching a particular module object
 *
 * Examples
 *   {selectmodobject module="AutoCustomer" objecttype="customer" id=4 assign="myCustomer"}
 *   {selectmodobject module="AutoCocktails" objecttype="recipe" id=12 assign="myRecipe"}
 *   {selectmodobject recordClass="AutoCocktails_Model_Recipe" id=12 assign="myRecipe"}
 *
 * Parameters:
 *  module      Name of the module storing the desired object (in DBObject mode)
 *  objecttype  Name of object type (in DBObject mode)
 *  recordClass Class name of an doctrine record. (in Doctrine mode)
 *  id          Identifier of desired object
 *  prefix      Optional prefix for class names (defaults to PN) (in DBObject mode)
 *  assign      Name of the returned object
 *
 * @param array       $params All attributes passed to this function from the template.
 * @param Zikula_View $view   Reference to the Zikula_View object.
 *
 * @return void
 */
function smarty_function_selectmodobject($params, Zikula_View $view)
{
    if (isset($params['recordClass']) && !empty($params['recordClass'])) {
        $doctrineMode = true;
    } else {
        // DBObject checks
        if (!isset($params['module']) || empty($params['module'])) {
            $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'module')));
        }
        if (!isset($params['objecttype']) || empty($params['objecttype'])) {
            $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'objecttype')));
        }
        if (!isset($params['prefix'])) {
            $params['prefix'] = 'PN';
        }
        $doctrineMode = false;
    }
    if (!isset($params['id']) || empty($params['id']) || !is_numeric($params['id'])) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'id')));
    }
    if (!isset($params['assign']) || empty($params['assign'])) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'assign')));
    }
    // load object depending on mode: doctrine or dbobject
    if (!$doctrineMode) {
        if (!ModUtil::available($params['module'])) {
            $view->trigger_error(__f('Invalid %1$s passed to %2$s.', array('module', 'selectmodobject')));
        }
        ModUtil::dbInfoLoad($params['module']);
        $classname = "{$params['module']}_DBObject_" . StringUtil::camelize($params['objecttype']);
        if (!class_exists($classname) && System::isLegacyMode()) {
            // BC check for PNObject old style.
            // load the object class corresponding to $params['objecttype']
            if (!($class = Loader::loadClassFromModule($params['module'], $params['objecttype'], false, false, $params['prefix']))) {
                z_exit(__f('Unable to load class [%s] for module [%s]', array(DataUtil::formatForDisplay($params['objecttype']), DataUtil::formatForDisplay($params['module']))));
            }
        }
        // intantiate object model
        $object = new $class();
        $idField = $object->getIDField();
        // assign object data
        // this performs a new database select operation
        // while the result will be saved within the object, we assign it to a local variable for convenience
        $objectData = $object->get(intval($params['id']), $idField);
        if (!is_array($objectData) || !isset($objectData[$idField]) || !is_numeric($objectData[$idField])) {
            $view->trigger_error(__('Sorry! No such item found.'));
        }
    } else {
        $objectData = Doctrine_Core::getTable($params['recordClass'])->find($params['id']);
        if ($objectData === false) {
            $view->trigger_error(__('Sorry! No such item found.'));
        }
    }
    $view->assign($params['assign'], $objectData);
}
开发者ID:projectesIF,项目名称:Sirius,代码行数:76,代码来源:function.selectmodobject.php

示例15: smarty_function_selectmodobject

/**
 * render plugin for fetching a particular module object
 *
 * Examples
 *   {selectmodobject module="AutoCustomer" objecttype="customer" id=4 assign="myCustomer"}
 *   {selectmodobject module="AutoCocktails" objecttype="recipe" id=12 assign="myRecipe"}
 *   {selectmodobject recordClass="AutoCocktails_Model_Recipe" id=12 assign="myRecipe"}
 *
 * Parameters:
 *  module      Name of the module storing the desired object (in DBObject mode)
 *  objecttype  Name of object type (in DBObject mode)
 *  recordClass Class name of an doctrine record. (in Doctrine mode)
 *  id          Identifier of desired object
 *  prefix      Optional prefix for class names (defaults to PN) (in DBObject mode)
 *  assign      Name of the returned object
 *
 * @param array       $params All attributes passed to this function from the template.
 * @param Zikula_View $view   Reference to the Zikula_View object.
 *
 * @return void
 */
function smarty_function_selectmodobject($params, Zikula_View $view)
{
    if (isset($params['recordClass']) && !empty($params['recordClass'])) {
        $doctrineMode = true;
    } else {
        // DBObject checks
        if (!isset($params['module']) || empty($params['module'])) {
            $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'module')));
        }
        if (!isset($params['objecttype']) || empty($params['objecttype'])) {
            $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'objecttype')));
        }
        if (!isset($params['prefix'])) {
            $params['prefix'] = 'PN';
        }
        $doctrineMode = false;
    }
    if (!isset($params['id']) || empty($params['id']) || !is_numeric($params['id'])) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'id')));
    }
    if (!isset($params['assign']) || empty($params['assign'])) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('selectmodobject', 'assign')));
    }
    // load object depending on mode: doctrine or dbobject
    if (!$doctrineMode) {
        if (!ModUtil::available($params['module'])) {
            $view->trigger_error(__f('Invalid %1$s passed to %2$s.', array('module', 'selectmodobject')));
        }
        ModUtil::dbInfoLoad($params['module']);
        $class = "{$params['module']}_DBObject_" . StringUtil::camelize($params['objecttype']);
        // intantiate object model
        $object = new $class();
        $idField = $object->getIDField();
        // assign object data
        // this performs a new database select operation
        // while the result will be saved within the object, we assign it to a local variable for convenience
        $objectData = $object->get(intval($params['id']), $idField);
        if (!is_array($objectData) || !isset($objectData[$idField]) || !is_numeric($objectData[$idField])) {
            $view->trigger_error(__('Sorry! No such item found.'));
        }
    } else {
        if ($params['recordClass'] instanceof \Doctrine_Record) {
            $objectData = Doctrine_Core::getTable($params['recordClass'])->find($params['id']);
            if ($objectData === false) {
                $view->trigger_error(__('Sorry! No such item found.'));
            }
        } else {
            /** @var $em Doctrine\ORM\EntityManager */
            $em = \ServiceUtil::get('doctrine.entitymanager');
            $result = $em->getRepository($params['recordClass'])->find($params['id']);
            $objectData = $result->toArray();
        }
    }
    $view->assign($params['assign'], $objectData);
}
开发者ID:Silwereth,项目名称:core,代码行数:76,代码来源:function.selectmodobject.php


注:本文中的ModUtil::available方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。