Perforce Chronicle 2012.2/486814
API Documentation

Category_Form_Content Class Reference

This is the category form to display while editing content. More...

Inheritance diagram for Category_Form_Content:
P4Cms_Form_SubForm

List of all members.

Public Member Functions

 init ()
 Defines the elements that make up the content config form.

Detailed Description

This is the category form to display while editing content.

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

Category_Form_Content::init ( )

Defines the elements that make up the content config form.

Called automatically when the form object is created.

    {
        // set the title of this form.
        $this->setLegend('Categories');

        // add a field to pick the content categories.
        // take the flat list of all categories and transform it into
        // a multi-dimensional array of options suitable for use with 
        // the nested checkbox
        $options    = array();
        $categories = Category_Model_Category::fetchAll();
        foreach ($categories as $category) {

            // explode parent id into ancestors if we have a parent.
            $ancestors = $category->getDepth()
                ? explode("/", $category->getParentId())
                : array();

            // build out the heirarchy of array keys for this
            // category, advancing the option pointer as we go.
            $option =& $options;
            foreach ($ancestors as $ancestor) {
                $key = $ancestor . "/";
                if (!array_key_exists($key, $option)) {
                    $option[$key] = array();
                }
                $option =& $option[$key];
            }
            $option[$category->getId()] = $category->getTitle();
        }

        $this->addElement(
            'NestedCheckbox',
            'categories',
            array(
                'multiOptions'  => $options,
                'emptyText'     => 'No Categories'
            )
        );

        // add a button to add more categories.
        // (if current user has permission to add categories)
        $user = P4Cms_User::fetchActive();
        if ($user->isAllowed('categories', 'add')) {
            $router     = Zend_Controller_Front::getInstance()->getRouter();
            $formHref   = $router->assemble(
                array(
                    'module'        => 'category',
                    'controller'    => 'manage',
                    'action'        => 'add',
                    'format'        => 'partial',
                    'short'         => true,
                    'formIdPrefix'  => 'addCategoryDialog' . $this->getIdPrefix()
                )
            );
            $this->addElement(
                'TooltipDialogButton',
                'addCategory',
                array(
                    'label'     => 'Add Category',
                    'href'      => $formHref,
                    'class'     => 'add-button',
                    'ignore'    => true
                )
            );
        }
    }

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