Exemplo n.º 1
0
/**
 * Pop a field of an array and assign its value to a template variable.
 *
 * Available attributes:
 *  - array  (string) Name of the template array variable to process
 *  - field  (string) Name of the array field to assign then unset
 *  - unset  (bool)   Flag to specify if the field must be unset or not (default: true)
 *  - assign (string) Name of the assign variable to setup (optional)
 *
 * Example:
 *
 *  Having an $objarray in our template, we want to process its fields in different
 *  sections of the template, so we get the needed fields separately on the desired positions,
 *  clearing the array in the process.
 *
 *  For instance, the $hooks array resulted of notify the 'display_view' hooks, can be
 *  processed individually using this plugin:
 *
 *  <samp>{array_pop array='hooks' field='EZComments'}</samp>
 *  <samp>{array_pop array='hooks' field='EZComments' assign='comments'}</samp>
 *
 *  And display later the remaining ones with a foreach.
 *
 * @param array       $params All attributes passed to this function from the template.
 * @param Zikula_View $view   Reference to the {@link Zikula_View} object.
 *
 * @return mixed False on failure, void if the value is assigned, or the value extracted itself.
 */
function smarty_function_array_pop($params, Zikula_View $view)
{
    if (!isset($params['array']) || !$params['array']) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('assign_cache', 'var')));
        return false;
    }
    if (!isset($params['field']) || !$params['field']) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('assign_cache', 'value')));
        return false;
    }
    $unset = isset($params['unset']) ? (bool) $params['unset'] : true;
    $value = null;
    $array = $view->getTplVar($params['array']);
    if ($array && isset($array[$params['field']])) {
        $value = $array[$params['field']];
        if ($unset) {
            unset($array[$params['field']]);
        }
        $view->assign($params['array'], $array);
    }
    if (isset($params['assign']) && $params['assign']) {
        $view->assign($params['assign'], $value);
    } else {
        return $value;
    }
}
Exemplo n.º 2
0
/**
 * Smarty function to display the category menu for admin links. This also adds the
 * navtabs.css to the page vars array for stylesheets.
 *
 * Admin
 * {admincategorymenu}
 *
 * @see          function.admincategorymenu.php::smarty_function_admincategorymenu()
 * @param        array       $params      All attributes passed to this function from the template
 * @param        \Zikula_View $view        Reference to the Zikula_View object
 * @return       string      the results of the module function
 */
function smarty_function_admincategorymenu($params, \Zikula_View $view)
{
    PageUtil::addVar('stylesheet', ThemeUtil::getModuleStylesheet('ZikulaAdminModule'));
    $modinfo = ModUtil::getInfoFromName($view->getTplVar('toplevelmodule'));
    $acid = ModUtil::apiFunc('ZikulaAdminModule', 'admin', 'getmodcategory', array('mid' => $modinfo['id']));
    $path = array('_controller' => 'ZikulaAdminModule:Admin:categorymenu', 'acid' => $acid);
    $subRequest = $view->getRequest()->duplicate(array(), null, $path);
    return $view->getContainer()->get('http_kernel')->handle($subRequest, \Symfony\Component\HttpKernel\HttpKernelInterface::SUB_REQUEST)->getContent();
}
Exemplo n.º 3
0
/**
 * Assign an array field to a variable or display it in the output.
 *
 * Available attributes:
 *  - array  (mixed)  Name of the template array variable or the array itself to process
 *  - field  (string) Name of the array field to assign
 *  - assign (string) Name of the assign variable to setup (optional)
 *
 * Example:
 *
 *  Having an $objarray in our template, we want to check if a field is set
 *  or extract one field on another var to process it apart.
 *
 *  For instance, we need the localized output of a category. We have the
 *  $category variable, and we pass the display_name to the plugin, to get the local name:
 *
 *  <samp>{array_field array=$category.display_name field=$lang assign='displayname'}</samp>
 *
 *  And if you need to be sure that the value is set, you must test it:
 *
 *  <samp>{if $displayname}</samp>
 *
 *  In the other hand, if you have a field that exists for sure, that is in the first level
 *  of the array and you want to extract it to another variable, you can do:
 *
 *  <samp>{array_field array='category' field='id' assign='cid'}</samp>
 *
 * @param array       $params All attributes passed to this function from the template.
 * @param Zikula_View $view   Reference to the {@link Zikula_View} object.
 *
 * @return Void
 */
function smarty_function_array_field($params, Zikula_View $view)
{
    if (!isset($params['array'])) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('assign_cache', 'var')));
        return false;
    }
    if (!isset($params['field'])) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('assign_cache', 'value')));
        return false;
    }
    $array = is_array($params['array']) ? $params['array'] : $view->getTplVar($params['array']);
    $field = isset($params['field']) ? $params['field'] : '';
    $assign = isset($params['assign']) ? $params['assign'] : null;
    $value = null;
    if ($field && is_array($array) && isset($array[$field])) {
        $value = $array[$field];
    }
    if ($assign) {
        $view->assign($params['assign'], $value);
    } else {
        return $value;
    }
}