Perforce Chronicle 2012.2/486814
API Documentation

Widget_Module Class Reference

Integrate the widget module with the rest of the application. More...

Inheritance diagram for Widget_Module:
P4Cms_Module_Integration

List of all members.

Static Public Member Functions

static init ()
 Perform early integration work (before load).
static load ()
 Explicitly add the views/scripts path because the widget and region.phtml files aren't in conventional locations.

Detailed Description

Integrate the widget module with the rest of the application.

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 Widget_Module::init ( ) [static]

Perform early integration work (before load).

Reimplemented from P4Cms_Module_Integration.

    {
        // update widgets when a site is created.
        P4Cms_PubSub::subscribe('p4cms.site.created',
            function(P4Cms_Site $site)
            {
                $adapter = $site->getStorageAdapter();
                P4Cms_Widget::installDefaults($adapter);
            }
        );

        // update widgets when a module/theme is enabled.
        $installDefaults = function(P4Cms_Site $site, P4Cms_PackageAbstract $package)
        {
            $adapter = $site->getStorageAdapter();
            P4Cms_Widget::installPackageDefaults($package, $adapter, true);
        };

        P4Cms_PubSub::subscribe('p4cms.site.module.enabled', $installDefaults);
        P4Cms_PubSub::subscribe('p4cms.site.theme.enabled',  $installDefaults);

        // update widgets when a module/theme is disabled
        $removeDefaults = function(P4Cms_Site $site, P4Cms_PackageAbstract $package)
        {
            $adapter = $site->getStorageAdapter();
            P4Cms_Widget::removePackageDefaults($package, $adapter);
        };

        P4Cms_PubSub::subscribe('p4cms.site.module.disabled', $removeDefaults);
        P4Cms_PubSub::subscribe('p4cms.site.theme.disabled',  $removeDefaults);

        // organize widget records when pulling changes.
        P4Cms_PubSub::subscribe(
            'p4cms.site.branch.pull.groupPaths',
            function($paths, $source, $target, $result)
            {
                $paths->addSubGroup(
                    array(
                        'label'         => 'Widgets',
                        'basePaths'     => $target->getId() . '/widgets/...',
                        'inheritPaths'  => $target->getId() . '/widgets/...',
                        'pullByDefault' => true,
                        'count'         =>
                            function($group, $count, $options) use ($target)
                            {
                                return $group->getPaths($options)->filter(
                                    'depotFile',
                                    $target->getId() . '/widgets/',
                                    array(
                                        P4Cms_Model_Iterator::FILTER_COPY,
                                        P4Cms_Model_Iterator::FILTER_STARTS_WITH
                                    )
                                )->count();
                            },
                        'details'       =>
                            function($paths) use ($source, $target)
                            {
                                $pathsById = array();
                                foreach ($paths as $path) {
                                    if (strpos($path->depotFile, $target->getId() . '/widgets/') === 0) {
                                        $pathsById[P4Cms_Widget::depotFileToId($path->depotFile)] = $path;
                                    }
                                }

                                $details = new P4Cms_Model_Iterator;
                                $entries = Site_Model_PullPathGroup::fetchRecords(
                                    array_keys($pathsById), 'P4Cms_Widget', $source, $target
                                );
                                foreach ($entries as $entry) {
                                    $path      = $pathsById[$entry->getId()];
                                    $label     = str_replace(array('-', '_'), ' ', $entry->getValue('region'));
                                    $label     = ucwords($label) . ' - ' . $entry->getValue('title');
                                    $details[] = new P4Cms_Model(
                                        array(
                                            'conflict' => $path->conflict,
                                            'action'   => $path->action,
                                            'label'    => $label
                                        )
                                    );
                                }

                                $details->setProperty(
                                    'columns',
                                    array('label' => 'Widget', 'action' => 'Action')
                                );

                                return $details;
                            }
                    )
                );
            }
        );
    }
static Widget_Module::load ( ) [static]

Explicitly add the views/scripts path because the widget and region.phtml files aren't in conventional locations.

Reimplemented from P4Cms_Module_Integration.

    {
        $view = Zend_Layout::getMvcInstance()->getView();
        $view->addScriptPath(dirname(__FILE__) . '/views/scripts/');
    }

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