Example #1
0
 /**
  * Builds the ShopCategory menu recursively.
  *
  * Do not call this directly, use {@link getShopCategoryMenuHierarchic()}
  * instead.
  * @static
  * @param    integer  $parent_id    The parent ShopCategory ID.
  * @param    integer  $level        The nesting level.
  *                                  Should start at 0 (zero).
  * @param    integer  $selected     The optional selected ShopCategory ID.
  * @return   string                 The HTML code with all <option> tags,
  *                                  or the empty string on failure.
  */
 static function getShopCategoryMenuHierarchicRecurse($parent_id, $level, $selected = 0)
 {
     $arrChildShopCategories = ShopCategory::getChildCategoriesById($parent_id);
     if (!is_array($arrChildShopCategories || empty($arrChildShopCategories))) {
         return '';
     }
     $result = '';
     foreach ($arrChildShopCategories as $objCategory) {
         $id = $objCategory->id();
         $name = $objCategory->name();
         $result .= "<option value='{$id}'" . ($selected == $id ? \Html::ATTRIBUTE_SELECTED : '') . '>' . str_repeat('.', $level * 3) . htmlentities($name) . "</option>\n";
         if ($id != $parent_id) {
             $result .= ShopCategory::getShopCategoryMenuHierarchicRecurse($id, $level + 1, $selected);
         }
     }
     return $result;
 }