<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/
class Authorization_Form_Admin_Level_Abstract extends Engine_Form
{
  protected $_moderator;

  protected $_admin;

  protected $_public;

  protected $_nonBooleanFields =array();

  protected $_nonBooleanFormElements = array(
    'Engine_Form_Element_Text',
    'Engine_Form_Element_Select',
    'Engine_Form_Element_MultiCheckbox'
  );

  public function setModerator($moderator)
  {
    $this->_moderator = (bool) $moderator;
    return $this;
  }

  public function isModerator()
  {
    return (bool) $this->_moderator;
  }

  public function setAdmin($admin)
  {
    $this->_admin = (bool) $admin;
    return $this;
  }

  public function isAdmin()
  {
    return (bool) $this->_admin;
  }

  public function setPublic($public)
  {
    $this->_public = (bool) $public;
    return $this;
  }

  public function isPublic()
  {
    return (bool) $this->_public;
  }

  public function setNonBooleanFormElements($nonBooleanFormElements)
  {
    if( !is_array($nonBooleanFormElements) ) {
      return;
    }
    $this->_nonBooleanFormElements = $nonBooleanFormElements;
    return $this;
  }

  // Form elements with NonBoolean values
  public function nonBooleanFields()
  {
    $formElements = $this->getElements();
    foreach( $formElements as $element ) {
      if( engine_in_array($element->getType(), $this->_nonBooleanFormElements) ) {
        $this->_nonBooleanFields[] = $element->getName();
      }
    }
    return $this->_nonBooleanFields;
  }

  public function init()
  {
    // Change description decorator
    $this->loadDefaultDecorators();
    $this->getDecorator('Description')->setOptions(array('tag' => 'h4', 'placement' => 'PREPEND'));

    // Prepare user levels
    $levelOptions = array();
    foreach( Engine_Api::_()->getDbtable('levels', 'authorization')->fetchAll() as $level ) {
      $levelOptions[$level->level_id] = $level->getTitle();
    }

    // Element: level_id
    $this->addElement('Select', 'level_id', array(
      'label' => 'Member Level',
      'multiOptions' => $levelOptions,
      'onchange' => 'javascript:fetchLevelSettings(this.value);',
      'ignore' => true,
    ));




    // Add submit
    $this->addElement('Button', 'submit', array(
      'label' => 'Save Changes',
      'type' => 'submit',
      'ignore' => true,
      'order' => 100000,
    ));
  }
}
