DB_Grid($Doc, $DBObj); $this->actions['reorder'] = 'doReorderForm'; $this->actions['reorder_save'] = 'doReorderSave'; $this->actions['enable'] = 'doEnable'; } function _getBaseForm($method = 'post') { require_once 'class/Form/Form.class.php'; $form = new Form($this->Doc, 'form', $method); $form->cancelUrl = BASE_URL . '/' . CURR_PAGE . '?action=cancel&id_poll=' . $this->DBObj->id_poll; $form->registerElementType('grid_answer', 'app/Poll/Question/grid_answer.php', 'HTML_QuickForm_grid_answer'); return $form; } function _bindFormFields($form) { $langs = $this->DBObj->langs; $langs_count = count($langs); $id_poll =& $form->addElement('hidden', 'id_poll', $this->DBObj->id_poll); $title_title = _('Question'); if ($langs_count > 1) { $form->addElement('header', 'title_header', $title_title); } $title = array(); foreach ($langs as $lng) { if ($langs_count > 1) { $field_title = $lng['title']; } else { $field_title = $title_title; } $field_name = "title[{$lng['name']}]"; $title[$lng['name']] =& $form->addElement('text', $field_name, $field_title, array()); $required_note = _('Question is required') . ($langs_count > 1 ? " ({$lng['title']})" : ''); $form->addRule($field_name, $required_note, 'required'); $form->addRule($field_name, $required_note, 'required', null, 'client'); } $cols = array(); foreach ($langs as $lng) { //$cols[] = array('name' => $lng['name'], 'title' => $lng['title']); $cols[] = array('name' => $lng['name'], 'title' => $lng['title']); } $ansewrs =& $form->addElement('grid_answer', 'answers', 'Answers', $cols, null, array('style' => 'width:300px;')); $ansewrs->_tplOptions = '{del} | {up} | {down}'; $required_note = _('Answers is required'); $form->addRule('answers', $required_note, 'required'); $enabled =& $form->addElement('advcheckbox', 'enabled', 'Enabled', null, null, array('n', 'y')); $data = $this->DBObj->getData(); if (!is_array($data)) { $data = array(); } if (!is_array($data['answers']) || empty($data['answers'])) { foreach ($langs as $lng) { $data['answers'][$lng['name']] = array(0 => ''); } } $form->setDefaults($data); $form->addFormRule(array(&$this, 'validateForm')); return $form; } function validateForm($data) { //vdie($data); $error = array(); foreach ($data['answers'] as $al) { if (empty($al)) { $error['answers'] = 'Answers is required'; break; } else { foreach ($al as $v) { if (empty($v)) { $error['answers'] = 'Answers is required'; } } } } return empty($error) ? true : $error; } function _getNewForm() { $form = parent::_getNewForm(); //$form->addRule('image', _('Изображение обязательно'), 'uploadedfile'); return $form; } function _doListBind(&$DB_List) { $DB_List->def_order_by = 'sorter'; $DB_List->bindCols(); $DB_List->urlVarNames[] = 'id_poll'; $DB_List->insertColFirst( 'sorter', array( 'title' => '#', 'width' => 40, 'order_by' => 'sorter', 'tpl' => DB_LIST_CELL_SORTER, 'params' => array('sorter'), ) ); $DB_List->insertColAfter( 'title', array( 'title' => _('Question'), 'width' => 450, 'order_by' => 'title', 'tpl' => DB_LIST_CELL_TEXT, 'params' => array('title'), ), 'sorter' ); $DB_List->insertColAfter('enabled', array( 'title' => 'Enabled', 'width' => 100, 'order_by' => 'enabled', 'tpl' => DB_LIST_CELL_LINK_ENUM, 'values' => array('y' => 'Yes', 'n' => 'No'), 'url' => BASE_URL . '/' . CURR_PAGE . '?action=enable&id_poll=' . $this->DBObj->id_poll . '&id=', 'target' => '', 'params' => array('enabled', 'id'), ), 'title' ); $opt = $DB_List->getCol('options'); $link = BASE_URL . '/' . CURR_PAGE; $opt['edit_link'] = $link . "?action=edit&id_poll={$this->DBObj->id_poll}&id="; $opt['del_link'] = $link . "?action=del&id_poll={$this->DBObj->id_poll}&id="; $DB_List->setCol('options', $opt); $DB_List->bind(); return true; } function doList() { /*$filtFrm = $this->getFilterForm(); $this->DBObj->setFilter($filtFrm->getElementValue('query')); $filtFrm->exec();*/ parent::doList(); } function addLink() { $link = Constant::get('BASE_URL') . '/' . CURR_PAGE; $addLink = array( 'tpl' => 'center_link.tpl', 'link_list' => array( array('link' => $this->getBackUrl(PARENT_PAGE), 'title' => $this->DBObj->getPollName()), array('link' => $link . '?action=new&id_poll=' . $this->DBObj->id_poll, 'title' => 'Add new Question'), array('link' => $link . '?action=reorder&id_poll=' . $this->DBObj->id_poll, 'title' => _('Reorder Questions')), ) ); $this->Doc->addContent($addLink); } function _getReorderFrom() { $form = $this->_getBaseForm(); $list = array(); $list4Grid = $this->DBObj->getList4Grid(array('order_by' => 'sorter')); foreach ($list4Grid['list'] as $val) { $list[$val['id']] = substr($val['title'], 0, 80); } $orderList = Form::createElement('select_edit', 'order_list', false, $list, array('style' => 'width:600px;')); $orderList->delAction('add'); $orderList->delAction('del'); $orderList->delAction('edit'); $form->addElement($orderList); $form->addElement('hidden', 'id_poll', $this->DBObj->id_poll); return $form; } function doReorderForm() { $form = $this->_getReorderFrom(); $form->setTitle('Reorder Questions'); $form->addElement('hidden', 'action', 'reorder_save'); $form->exec(); } function doReorderSave() { $form = $this->_getReorderFrom(); $this->DBObj->reorder($form->getElementValue('order_list')); $this->doBack(); } function doEnable() { Session::setData(CURR_PAGE, 'msg', 'Question is updated'); $this->DBObj->changeOption('enabled'); $this->doBack(); return true; } }