public function onModules( ModulesEvent $event )
    {
        $saved      = 0;
        $model      = $event->getTarget();
        $mapper     = $model->getMapper();
        $modules    = $event->getParams();

        foreach ( $modules as $name => $enabled )
        {
            if ( empty( $name ) )
            {
                continue;
            }

            $name   = (string) $name;
            $module = $model->findByName( $name );

            if ( empty( $module ) )
            {
                $module = $model->create( array(
                    'module'    => $name,
                    'enabled'   => $enabled,
                ) );
            }
            else
            {
                $module->enabled = $enabled;
            }

            $saved += $mapper->save( $module );
        }

        return $saved;
    }