public function index($params) { $this->setPageTitle(OW::getLanguage()->text('spdownload', 'category_index_page_title')); $this->setPageHeading(OW::getLanguage()->text('spdownload', 'category_index_page_heading')); $category = array(); if (!empty($params) && isset($params['categoryId'])) { $category = SPDOWNLOAD_BOL_CategoryDao::getInstance()->findById($params['categoryId']); } $downloads = SPDOWNLOAD_BOL_CategoryService::getInstance()->getCategoryList(); $downloadCategories = array(); foreach ($downloads as $key => $value) { $downloadCategories[$value->id] = $value->name; } $form = new Form('add_category'); $this->addForm($form); // Create selectbox $fieldTo = new SelectBox('parent_category'); foreach ($downloadCategories as $key => $label) { $fieldTo->addOption($key, $label); } if (!empty($params) && isset($params['categoryId'])) { $fieldTo->setValue($category->parentId); } $fieldTo->setLabel(OW::getLanguage()->text('spdownload', 'ad_parent_category')); $form->addElement($fieldTo); $fieldCate = new TextField('category'); $fieldCate->setLabel(OW::getLanguage()->text('spdownload', 'ad_label_category')); if (!empty($params) && isset($params['categoryId'])) { $fieldCate->setValue($category->name); } $fieldCate->setRequired(); $fieldCate->setHasInvitation(true); $form->addElement($fieldCate); $submit = new Submit('add'); $submit->setValue(OW::getLanguage()->text('spdownload', 'form_add_category_submit')); $form->addElement($submit); if (OW::getRequest()->isPost()) { if ($form->isValid($_POST)) { $data = $form->getValues(); if ($data['parent_category'] == null) { $data['parent_category'] = 0; } if (!empty($params) && isset($params['categoryId'])) { SPDOWNLOAD_BOL_CategoryService::getInstance()->addCategory($data['category'], $data['parent_category'], $params['categoryId']); } else { SPDOWNLOAD_BOL_CategoryService::getInstance()->addCategory($data['category'], $data['parent_category']); } $this->redirect(OW::getRouter()->urlForRoute('spdownload.category_list')); } } }
public static function Factory($name, $valueList, $label = '', $required = false, $selected = array(), $attrList = array()) { $element = new SelectBox($name); $element->setValue($valueList); $element->setLabel($label); $element->setRequired($required); $element->setOptionList($attrList); $element->setSelectedValueList($selected); return $element; }