<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/

class Core_Widget_SavecollectionSheetController extends Engine_Content_Widget_Abstract
{
    public function indexAction()
    {
        // Check if feature is enabled
        $api = Engine_Api::_()->getApi('savecollection', 'core');
        if (!$api->isEnabled()) {
            return $this->setNoRender();
        }

        // Check if viewer is authenticated
        $viewer = Engine_Api::_()->user()->getViewer();
        if (!$viewer || !$viewer->getIdentity()) {
            return $this->setNoRender();
        }

        // Load viewer's collections for the sheet (up to 10, ordered by usage)
        $collections = $api->getCollectionsForSheet($viewer);

        $this->view->collections = $collections;
        $this->view->viewerId = $viewer->getIdentity();
    }
}
