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

class Userprofilelock_Widget_ProfileLockController extends Engine_Content_Widget_Abstract {

  public function indexAction() {
		
		if(empty(Engine_Api::_()->getApi('settings', 'core')->getSetting('userprofilelock.enable', 1)))
			return $this->setNoRender();
			
    // Don't render this if not authorized
    $this->view->viewer = $viewer = Engine_Api::_()->user()->getViewer();
		$userprofilelock_widget = Zend_Registry::isRegistered('userprofilelock_widget') ? Zend_Registry::get('userprofilelock_widget') : null;
    if( !Engine_Api::_()->core()->hasSubject() ) {
      return $this->setNoRender();
    }
	
    // Get subject and check auth
    $this->view->subject = $subject = Engine_Api::_()->core()->getSubject('user');
    if( !$subject->authorization()->isAllowed($viewer, 'view') ) {
      return $this->setNoRender();
    }
		if(empty($userprofilelock_widget))
			return $this->setNoRender();
    
    if($subject->getIdentity() == $viewer->getIdentity())
			return $this->setNoRender();

    $row = $subject->membership()->getRow($viewer);
    if($row && $row->active)
			return $this->setNoRender();
    
    if(empty($subject->profilelock))
			return $this->setNoRender();
  }
}
