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

class Stories_Widget_AllStoriesController extends Engine_Content_Widget_Abstract
{
	public function indexAction()
	{
		$this->view->isAjax = $this->_getParam('is_ajax', 0);
		//$this->view->identity = $this->_getParam('identity',0);
		$this->view->viewer = $viewer = $this->view->viewer();
		if (!$viewer->getIdentity()) {
			return $this->setNoRender();
		}

		$this->view->title = $this->_getParam('title');

		//get all stories
		$user_id = $viewer->getIdentity();
		$userarchivedstories = $this->_getParam('userarchivedstories', null);
		$stories_widget = Zend_Registry::isRegistered('stories_widget') ? Zend_Registry::get('stories_widget') : null;

		$highlight = $this->_getParam('highlight', null);
		if (!empty($_SESSION['story_id'])) {
			$item = Engine_Api::_()->getItem('stories_story', $_SESSION['story_id']);
			if ($item) {
				$this->view->user_id = $item->owner_id;
				$this->view->story_id = $_SESSION['story_id'];
			}
			unset($_SESSION['story_id']);
		}
		if(empty($stories_widget)) {
			return $this->setNoRender();
		}
		
		if ($this->view->isAjax)
			$this->view->story = Engine_Api::_()->stories()->userData($highlight, $userarchivedstories, $user_id, $this->view);
	}
}
