Perforce Chronicle 2012.2/486814
API Documentation

Content_View_Helper_ContentSelect Class Reference

Renders a content select control. More...

List of all members.

Public Member Functions

 contentSelect ($id, $value=null, $params=array(), $attribs=array())
 Render the content select markup needed to declare the dijit.

Protected Attributes

 $_dijit = 'p4cms.content.ContentSelect'
 $_module = 'p4cms.content.ContentSelect'

Detailed Description

Renders a content select control.

Allows the user to select one or more content entries. The content select control is a dijit that supports both single and multi-select (toggled via multiple = true/false). Callers can also specify browse options to influence the content select dialog that appears when the browse button is clicked.

Copyright:
2011-2012 Perforce Software. All rights reserved
License:
Please see LICENSE.txt in top-level folder of this distribution.
Version:
2012.2/486814

Member Function Documentation

Content_View_Helper_ContentSelect::contentSelect ( id,
value = null,
params = array(),
attribs = array() 
)

Render the content select markup needed to declare the dijit.

Parameters:
string$idZend provides no documentation for this param.
string$valueZend provides no documentation for this param.
array$paramsZend provides no documentation for this param.
array$attribsZend provides no documentation for this param.
Returns:
string
    {
        if (!array_key_exists('id', $attribs)) {
            $attribs['id'] = $id;
        }
        $id = $attribs['id'];

        // normalize values to an array and remove nulls
        $value = array_values(array_filter((array) $value));

        // lookup entry data (titles, content types) for selected content ids.
        if ($value) {
            $params['entryData'] = array();
            $entries             = P4Cms_Content::fetchAll(
                array(
                    'ids'         => (array) $value,
                    'limitFields' => array('title', 'contentType')
                )
            );

            foreach ($entries as $entry) {
                $params['entryData'][$entry->getId()] = array(
                    'title'     => $entry->getTitle(),
                    'type'      => $entry->getContentTypeId()
                );
            }
        }

        // flatten the browse options, otherwise there are issues with
        // the multidimensional associative array in javascript
        if (array_key_exists('browseOptions', $attribs)) {
            $filter = new P4Cms_Filter_FlattenArray;
            $params['browseOptions'] = $filter->filter($attribs['browseOptions']);
        }

        // json-encode select parameters - prepare dijit is supposed to do this
        // but it corrupts values because it does some very silly quote mangling.
        $params['selected']   = $value;
        $params['validTypes'] = isset($attribs['validTypes']) ? $attribs['validTypes'] : null;
        foreach (array('browseOptions', 'multiple', 'selected', 'entryData', 'validTypes') as $param) {
            if (array_key_exists($param, $params)) {
                $params[$param] = Zend_Json::encode($params[$param]);
            }
        }

        // get the attributes ready for use in a dijit
        $attribs = $this->_prepareDijit($attribs, $params, 'element');

        return "<div " . $this->_htmlAttribs($attribs) . "></div>";
    }

Member Data Documentation

Content_View_Helper_ContentSelect::$_dijit = 'p4cms.content.ContentSelect' [protected]
Content_View_Helper_ContentSelect::$_module = 'p4cms.content.ContentSelect' [protected]

The documentation for this class was generated from the following file: