/**
  * Build pull down menu options of available rule parents
  *
  * @param object $entity The rule entity object
  * @param int $language Language selection identifier; default: 0
  * @param int $parent_id Category to display rules from; default: 0
  * @param string $mode Display menu for add or edit mode
  * @return null
  * @access protected
  */
 protected function build_parent_select_menu($entity, $language = 0, $parent_id = 0, $mode = 'edit')
 {
     $language = $mode == 'edit' ? $entity->get_language() : $language;
     $parent_id = $mode == 'edit' ? $entity->get_parent_id() : $parent_id;
     // Prepare rule pull-down field
     $rule_menu_items = $this->rule_operator->get_rules($language);
     $padding = '';
     $padding_store = array();
     $right = 0;
     // Process each rule menu item for pull-down
     /* @var $rule_menu_item \phpbb\boardrules\entity\rule */
     foreach ($rule_menu_items as $rule_menu_item) {
         if ($rule_menu_item->get_left_id() < $right) {
             $padding .= '&nbsp;&nbsp;';
             $padding_store[$rule_menu_item->get_parent_id()] = $padding;
         } else {
             if ($rule_menu_item->get_left_id() > $right + 1) {
                 $padding = isset($padding_store[$rule_menu_item->get_parent_id()]) ? $padding_store[$rule_menu_item->get_parent_id()] : '';
             }
         }
         $right = $rule_menu_item->get_right_id();
         // Set output block vars for display in the template
         $this->template->assign_block_vars('rulemenu', array('RULE_ID' => $rule_menu_item->get_id(), 'RULE_TITLE' => $padding . $rule_menu_item->get_title(), 'S_DISABLED' => $mode == 'edit' && ($rule_menu_item->get_left_id() > $entity->get_left_id() && $rule_menu_item->get_right_id() < $entity->get_right_id() || $rule_menu_item->get_id() == $entity->get_id()) ? true : false, 'S_RULE_PARENT' => $rule_menu_item->get_id() == $parent_id));
     }
 }
 /**
  * Display the rules page
  *
  * @return \Symfony\Component\HttpFoundation\Response A Symfony Response object
  * @access public
  */
 public function display()
 {
     // When board rules are disabled, redirect users back to the forum index
     if (empty($this->config['boardrules_enable'])) {
         redirect(append_sid("{$this->root_path}index.{$this->php_ext}"));
     }
     // Add boardrules controller language file
     $this->user->add_lang_ext('phpbb/boardrules', 'boardrules_controller');
     $last_right_id = null;
     // Used to help determine when to close nesting structures
     $depth = 0;
     // Used to track the depth of nesting level
     $cat_counter = 1;
     // Numeric counter used for categories
     $rule_counter = 'a';
     // Alpha counter used for rules
     // Grab all the rules in the current user's language
     $entities = $this->rule_operator->get_rules($this->user->get_iso_lang_id());
     /* @var $entity \phpbb\boardrules\entity\rule */
     foreach ($entities as $entity) {
         if ($entity->get_right_id() - $entity->get_left_id() > 1) {
             // Rule categories
             $is_category = true;
             $anchor = $entity->get_anchor() ?: $this->user->lang('BOARDRULES_CATEGORY_ANCHOR', $cat_counter);
             // Increment nesting level depth counter
             $depth++;
             // Increment category counter
             $cat_counter++;
             // Reset rule counter
             $rule_counter = 'a';
         } else {
             // Rules
             $is_category = false;
             $anchor = $entity->get_anchor() ?: $this->user->lang('BOARDRULES_RULE_ANCHOR', $cat_counter - 1 . $rule_counter);
             // Increment rule counter
             $rule_counter++;
         }
         // Determine how deeply nested we are and use closing tags as necessary
         $diff = $last_right_id !== null ? $entity->get_left_id() - $last_right_id : 1;
         if ($diff > 1) {
             for ($i = 1; $i < $diff; $i++) {
                 $depth--;
                 // decrement the nesting level depth counter
                 $this->template->assign_block_vars('rules', array('S_CLOSE_LIST' => true));
             }
         }
         // Set last_right_id value with the current item's value
         $last_right_id = $entity->get_right_id();
         // Assign values to template vars for this rule entity
         $this->template->assign_block_vars('rules', array('TITLE' => $entity->get_title(), 'MESSAGE' => $entity->get_message_for_display(), 'U_ANCHOR' => $anchor, 'S_IS_CATEGORY' => $is_category));
     }
     // By this point, if any nested structures are still open, attempt to close them
     if ($depth > 0) {
         for ($i = 0; $i < $depth; $i++) {
             $this->template->assign_block_vars('rules', array('S_CLOSE_LIST' => true));
         }
     }
     // Assign values to template vars for the rules page
     $this->template->assign_vars(array('S_BOARD_RULES' => true, 'S_CATEGORIES' => $cat_counter > 1 ? true : false, 'BOARDRULES_EXPLAIN' => $this->user->lang('BOARDRULES_EXPLAIN', $this->config['sitename'])));
     // Assign breadcrumb template vars for the rules page
     $this->template->assign_block_vars('navlinks', array('U_VIEW_FORUM' => $this->helper->route('phpbb_boardrules_main_controller'), 'FORUM_NAME' => $this->user->lang('BOARDRULES')));
     // Send all data to the template file
     return $this->helper->render('boardrules_controller.html', $this->user->lang('BOARDRULES'));
 }