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

  public function indexAction() {

    $dashboard_id = $this->_getParam('dashboard_id', null);
    if(empty($dashboard_id))
        return $this->setNoRender();
    
    $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
    $this->view->viewer_id = $viewerId = $viewer->getIdentity();

    $core_dashboard = Engine_Api::_()->getItem('core_dashboard', $dashboard_id);
    if(empty($core_dashboard->enabled))
      return $this->setNoRender();

    $this->view->dashboardlinks = $dashboardlinks = Engine_Api::_()->getDbTable('dashboardlinks', 'core')->getInfo(array('sublink' => 0, 'enabled' => 1, 'dashboard_id' => $dashboard_id));

    $finalArray = array();
    foreach( $dashboardlinks as $item ) {
      $results = Engine_Api::_()->getDbTable('dashboardlinks', 'core')->getInfo(array('sublink' => $item->dashboardlink_id, 'enabled' => 1));
      foreach($results as $result) {
        $finalArray[] = $result->getIdentity();
      }
    }

    if(engine_count($finalArray) == 0)
      return $this->setNoRender();
  }
}
