_info['id'] = $this->_info['name'] = $id = rtrim($name, '[]'); $this->_info['categoryId'] = $id . '-category'; $this->_info['queryId'] = $id . '-query'; $this->_info['chooseId'] = $id . '-choose'; $this->_info['chosenId'] = $id . '-chosen'; if (!empty($value) && isset($value[0]['code'])) { $value = Qs_Array::fetchColAll($value, 'code'); } $this->_info['value'] = empty($value) ? [] : (array) $value; if (empty($attribs)) { $attribs = []; } foreach (['categories', 'categoryCode', 'codes', 'chosenCodes', 'htmlAfterElement'] as $field) { if (array_key_exists($field, $attribs)) { $this->_info[$field] = $attribs[$field]; unset($attribs[$field]); } } if (empty($this->_info['chosenCodes'])) { $this->_info['chosenCodes'] = []; } $this->_info['attribs'] = $attribs; return $this; } protected function getInfo($field = null, $default = null) { return Qs_Array::get($this->_info, $field, $default); } public function formNaics($name, $value = null, $attribs = null) { $this->_initInfo($name, $value, $attribs); return $this->render(); } protected function render() { $this->_initResources(); $html = Html::renderContainer('div', $this->renderLeftColumn(), ['class' => 'span8']); $html .= Html::renderContainer('div', $this->renderRightColumn(), ['class' => 'span4 chosen-codes']); $attribs['class'] = Html::addClass($this->getInfo('attribs[class]'), 'row-fluid'); return Html::renderContainer('div', $html, $attribs); } protected function renderLeftColumn() { $html = Html::renderContainer('div', $this->renderFilter(), ['class' => 'span6']); $html = Html::renderContainer('div', $html, ['class' => 'row-fluid']); $html .= Html::renderContainer('div', $this->renderCategoryCodes(), ['class' => 'row-fluid']); return $html; } protected function renderFilter() { $id = $this->getInfo('queryId'); $html = Html::renderContainer('label', 'Filter by Keyword', ['for' => $id]); $html .= Html::renderTag('input', ['type' => 'text', 'id' => $id, 'class' => 'text', 'maxlength' => 255]); return $html; } protected function renderCategoryCodes() { $id = $this->getInfo('chooseId'); $html = Html::renderContainer('label', 'Choose a Vendor Classifications', ['for' => $id]); $html .= Html::renderContainer('div', $this->renderCheckboxes(), ['id' => $id, 'class' => 'group-list']); $note = ''; $html .= Html::renderContainer('div', $note, ['class' => 'notice']); return $html; } protected function renderCheckboxes() { if (!($codes = $this->getInfo('codes', []))) { return Html::renderContainer('div', 'There are no codes matching this selection', [ 'class' => 'alert alert-info text-center', ]); } $items = []; foreach ($codes as $code) { $items[] = $this->renderCode($code); } $ipc = ceil(count($items) / 2); $html = Html::renderContainer('ul', implode(PHP_EOL, array_splice($items, 0, $ipc)), ['class' => 'unstyled span6']); $html .= Html::renderContainer('ul', implode(PHP_EOL, $items), ['class' => 'unstyled span6']); return Html::renderContainer('div', $html, ['class' => 'row-fluid']); } protected function renderCode(array $code) { $id = 'naics-checkbox-' . $code['code']; $liAttribs = [ 'data-choose-item' => $code['code'], 'class' => '', ]; $inputAttribs = [ 'type' => 'checkbox', 'id' => $id, 'value' => $code['code'], ]; $value = $this->getInfo('value'); if (in_array($code['code'], $value)) { $liAttribs['class'] = Html::addClass($liAttribs['class'], 'checked'); $inputAttribs['checked'] = 'checked'; } $html = Html::renderTag('input', $inputAttribs); $html .= Html::renderContainer('label', $code['code'], ['for' => $id, 'class' => 'number hidden']); $html .= Html::renderContainer('label', $this->renderCodeTitle($code), [ 'for' => $id, 'class' => 'title', 'data-code-title' => $code['code'], ]); return Html::renderContainer('li', $html, $liAttribs); } protected function renderCodeTitle(array $code) { /** @noinspection PhpUndefinedMethodInspection */ return $this->view->naicsTitle($code); } protected function renderRightColumn() { $html = Html::renderContainer('h4', 'Chosen Vendor Classifications'); $html .= Html::renderContainer('p', 'You can choose up to 10 Vendor Classifications', ['class' => 'description']); $html .= $this->renderChosenCodes(); $html .= Html::renderContainer('a', 'Remove all codes', [ 'data-btn-remove-all' => '', 'class' => 'remove-all' . ($this->getInfo('chosenCodes') ? '' : ' hidden'), 'href' => '#', ]); $html .= $this->getInfo('htmlAfterElement'); return $html; } protected function renderChosenCodes() { $html = ''; foreach ($this->getInfo('chosenCodes') as $code) { $html .= $this->renderChosenCode($code); } return Html::renderContainer('ol', $html, ['data-chosen-list' => '']); } protected function renderChosenCode($code) { $html = Html::renderTag('input', [ 'type' => 'hidden', 'name' => $this->getInfo('name') . '[]', 'value' => $code['code'], ]); $html .= Html::renderContainer('span', $code['code'], ['class' => 'code-number hidden']); $html .= Html::renderContainer('span', '- ' . $this->renderCodeTitle($code), ['class' => 'code-title']); $icon = Html::renderContainer('i', '', ['class' => 'fa fa-times']); $html .= Html::renderContainer('a', $icon, ['data-remove-btn' => $code['code'], 'href' => '#']); return Html::renderContainer('li', $html, ['data-chosen-item' => $code['code']]); } protected function _initResources() { /** @var \Qs_Doc $doc */ $doc = Zend_Registry::get('doc'); $doc->addScript('js/jquery.blockUI.js'); $doc->addScript('js/app/license/form/element/naicsCodes.js'); $options = [ 'id' => $this->getInfo('id') . '-element', 'name' => $this->getInfo('name'), 'nodes' => [ 'category' => '#' . $this->getInfo('categoryId'), 'query' => '#' . $this->getInfo('queryId'), 'chooseContainer' => '#' . $this->getInfo('chooseId'), 'chosenItems' => '[data-chosen-item]', 'chosenList' => '[data-chosen-list]', 'removeButtons' => '[data-remove-btn]', 'removeAllButton' => '[data-btn-remove-all]', 'paymentSummary' => '[data-payment-summary]', ], 'chosenItemTemplate' => $this->renderChosenCode(['code' => '{code}', 'title' => '{title}']), 'blockUiOptions' => [ 'message' => 'Please wait ...', 'overlayCSS' => ['backgroundColor' => '#EFEFEF'], 'css' => [ 'backgroundColor' => '#F8F8F8', 'border' => 'solid black 1px', 'fontSize' => '14px', 'width' => '70%', 'padding' => '10px', ], ], ]; $doc->addInitObject('app.license.form.element.NaicsCodes', [$options]); return $this; } }