Perforce Chronicle 2012.2/486814
API Documentation

Content_ListWidgetController Class Reference

A widget that displays a list of content, defaulting to the most recently added content, sorted so that the newest content is first. More...

Inheritance diagram for Content_ListWidgetController:
P4Cms_Widget_ControllerAbstract

List of all members.

Public Member Functions

 indexAction ()
 Display the content list.

Static Public Member Functions

static getConfigSubForm ($widget)
 Get config sub-form to present additional options when configuring a widget of this type.

Detailed Description

A widget that displays a list of content, defaulting to the most recently added content, sorted so that the newest content is first.

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

static Content_ListWidgetController::getConfigSubForm ( widget) [static]

Get config sub-form to present additional options when configuring a widget of this type.

Parameters:
P4Cms_Widget$widgetthe widget instance being configured.
Returns:
Zend_Form_SubForm|null the sub-form to integrate into the default widget config form or null for no sub-form.
    {
        return new Content_Form_ListWidget;
    }
Content_ListWidgetController::indexAction ( )

Display the content list.

    {
        $sortFields = array();
        if ($this->getOption('primarySortField')) {
            $sortFields[$this->getOption('primarySortField')] = array(
                $this->getOption('primarySortOrder') ?: P4Cms_Record_Query::SORT_DESCENDING
            );
        }
        
        if ($this->getOption('secondarySortField')) {
            $sortFields[$this->getOption('secondarySortField')] = array(
                $this->getOption('secondarySortOrder') ?: P4Cms_Record_Query::SORT_DESCENDING
            );
        }

        // if no options were specified, provide default
        if (empty($sortFields)) {
            $sortFields[P4Cms_Record_Query::SORT_DATE] = array(P4Cms_Record_Query::SORT_DESCENDING);
        }

        $query = P4Cms_Record_Query::create()
            ->setSortBy($sortFields);

        $contentType = $this->getOption('contentType');
        if ($contentType instanceof Zend_Config) {
            $contentType = $contentType->toArray();
        }

        $types = $this->getConfigSubForm($this)
                      ->getElement('contentType')
                      ->setValue($contentType)
                      ->getNormalizedTypes();

        if (count($types)) {
            $filter = new P4Cms_Record_Filter;
            $filter->add(
                'contentType',
                $types,
                P4Cms_Record_Filter::COMPARE_EQUAL
            );
            $query->addFilter($filter);
        }

        if ($this->getOption('count')) {
            $query->setMaxRows($this->getOption('count'));
        }

        $fields = array();
        if ($this->getOption('showIcons')) {
            $fields['icon'] = array(
                'field' => 'title',
                'decorators' => array(
                    'contentIcon',
                    'contentLink',
                    array(
                        'decorator' => 'htmlTag', 
                        'options'   => array(
                            'tag'       => 'span',
                            'class'     => 'content-list-icon-field'
                        )
                    )
                )
            );
        }
        $fields['title'] = array(
            'decorators' => array(
                'value', 
                'contentLink',
                array(
                    'decorator' => 'htmlTag', 
                    'options'   => array(
                        'tag'       => 'span',
                        'class'     => 'content-list-title-field'
                    )
                )
            )
        );

        $this->view->query   = $query;
        $this->view->options = array('fields' => $fields);
    }

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