'Committee', 'taskforce' => 'Taskforce', 'board' => 'Board' ); public function __construct($Doc, $DBObj) { parent::__construct($Doc, $DBObj); $this->actions['exportToCsv'] = 'doExportToCsv'; return $this; } public function doExportToCsv() { $fields = array( 'member' => 'Member Name', 'type' => 'Member type(s)', 'position' => 'Group Position', 'email' => 'Email', 'primary_phone' => 'Phone', ); require_once('Structures/DataGrid/Renderer/CSV.php'); $csv = new Structures_DataGrid_Renderer_CSV(); $csv->setStreaming(true); $opt = array('order_by' => 'last_name, first_name'); /** @var $res MDB2_Result_Common */ $volunteerMember = VolunteerMember::getInstance()->setId(null)->setParentId($this->DBObj->id); $res = $volunteerMember->_getRes4Grid($volunteerMember->_getWhat4Grid($opt), $opt); $row = $res->fetchRow(); if (!$row) { Session::setData($this->_getPage4SaveMessage(), 'msg', 'No data for export'); $this->doBack(); return $this; } header('Last-Modified: ' . gmdate('D,d M YH:i:s') . ' GMT'); header('Cache-Control: no-cache, must-revalidate'); header('Pragma: no-cache'); header("Content-type: text/comma-separated-values"); header('Content-disposition: attachment; filename=search_results.csv'); echo $csv->_recordToCsv(array_values($fields)); echo $csv->_recordToCsv($this->_prepareRow($row, $fields)); while (($row = $res->fetchRow())) { echo $csv->_recordToCsv($this->_prepareRow($row, $fields)); } exit; } protected function _getMemberTypes($member) { $types = array(); if (!empty($member['id_mncar_type'])) { $types[] = 'MNCAR: ' . $member['mncar_type'] . ' ('. $member['mncar_status'] . ')'; } if (!empty($member['id_mncar_l_type'])) { $types[] = 'MNCAR-L: ' . $member['mncar_l_type'] . ' (' . $member['mncar_l_status'] . ')'; } if (!empty($member['id_misc_type'])) { $types[] = 'Misc.: ' . $member['misc_type'] . ' (' . $member['misc_status'] . ')'; } return implode(' | ', $types); } protected function _prepareRow($row, $fields) { $out = array(); $positions = VolunteerMember::getInstance()->setId(null)->setParentId($this->DBObj->id)->getGroupPositions(); foreach ($fields as $key => $field) { switch ($key) { case 'member': $out[$key] = $row['first_name'] . ' ' . (empty($row['middle_initial']) ? '' : $row['middle_initial'] . '. ') . $row['last_name']; break; case 'type': $out[$key] = $this->_getMemberTypes($row); break; case 'position': $out[$key] = $positions[$row['type']]; break; default: $out[$key] = $row[$key]; break; } } return $out; } function doList() { $filterForm = $this->getFilterForm(); $this->DBObj->setFilter( array( 'query' => $filterForm->getElementValue('query'), 'type' => implode('',$filterForm->getElementValue('type'))) ); $filterForm->exec(); return parent::doList(); } function getFilterForm() { $form = $this->_getBaseForm('get'); $form->tpl = BASE_PATH . '/tpl/Volunteer/Admin/filter.tpl'; $form->setRendType(FORM_RENDERER_ARRAY_SMARTY); $form->addElement( 'text', 'query' ); $form->addElement( 'select', 'type', 'Type:', array('' => 'All') + $this->_volunteerTypes, 'onchange = "this.form.submit();"' ); $form->addElement('submit', 'submit_btn', 'Search', array('class' => 'btn')); $form->addElement( 'button', 'cancel_btn', 'Cancel', array( 'class' => 'btn', 'onclick' => "document.location.href='" . Constant::get('BASE_URL') . '/' . CURR_PAGE . "'" ) ); return $form; } function _bindFormFields(Form $form) { if (!in_array($this->_action, array('new', 'insert'))) { $siteUrl = BASE_URL . '/' . Volunteer::ALIAS . '/' . $this->DBObj->id; $form->addElement( 'extended_text', 'siteUrl', 'User End Link', array( 'value' => $siteUrl, 'onclick' => 'document.getElementById("siteUrl").select();', 'onchange' => '$("#siteUrl").val("' . $siteUrl . '")', 'readonly' => 'readonly', 'style' => 'width: 724px', ), null, '  Launch Page' ); } $form->addElement('text', 'title', 'Title'); $form->addElement('select', 'type', 'Type', array('' => 'Select One') + $this->_volunteerTypes); $form->addElement('html_editor_basic', 'mission', 'Mission'); $form->addElement( 'grid', 'goals', 'Goals', array(array('title' => 'Title', 'name' => 'title')), array('title' => $this->DBObj->getGoals()) ); $form->addRuleRequired(array('title', 'type')); $form->setDefaults($this->DBObj->getData()); $this->Doc->addItemProp('JSs', 'js/app/adminVolunteer.js'); $this->Doc->addInitFunction( 'App_AdminVolunteer_Form.initialize', array(array('type' => $this->DBObj->getData('type'))) ); return $form; } function _doListBind(&$DB_List) { $DB_List->insertColLast( 'sorter', array( 'title' => '#', 'order_by' => 'sorter', 'width' => '30', 'tpl' => BASE_PATH . '/tpl/Volunteer/Admin/cells/sorter.tpl', 'params' => array('sorter') ) ); $DB_List->insertColLast( 'title', array( 'title' => 'Title', 'order_by' => 'title', 'tpl' => DB_LIST_CELL_TEXT, 'params' => array('title') ) ); $DB_List->insertColLast( 'type', array( 'title' => 'Type', 'order_by' => 'type', 'tpl' => BASE_PATH . '/tpl/Volunteer/Admin/cells/type.tpl', 'params' => array('type') ) ); $DB_List->insertColLast( 'membersCount', array( 'title' => 'Members', 'order_by' => 'membersCount', 'tpl' => BASE_PATH . '/tpl/Volunteer/Admin/cells/members.tpl', 'params' => array('type') ) ); $DB_List->insertColLast( 'options', array( 'title' => 'Options', 'tpl' => BASE_PATH . '/tpl/Volunteer/Admin/cells/options.tpl', 'edit_link' => Constant::get('BASE_URL') . '/' . CURR_PAGE . '?action=edit&id=', 'del_link' => Constant::get('BASE_URL') . '/' . CURR_PAGE . '?action=del&id=', 'params' => array('id'), ) ); $DB_List->def_order_by = 'sorter, title'; return $this; } function addLink() { $addLink = array( 'tpl' => 'center_link.tpl', 'link_list' => array(array('link' => Constant::get('BASE_URL').'/'.CURR_PAGE.'?action=new', 'title' => 'Add new '.$this->DBObj->itemName, ), array('link' => Constant::get('BASE_URL').'/'.CURR_PAGE.'?action=reorder', 'title' => 'Reorder Committee & Taskforce ' . $this->DBObj->itemsName, ),), ); $this->Doc->addContent($addLink); $helpText = '
Please note: Board groups cannot be re-ordered because they show in a pre-determined area on the user end, ' . 'whereas Committee and Taskforce groups show under one dropdown menu, under Resources > Our Volunteers.' . ' Therefore, their order can be adjusted within that dropdown menu.
'; $this->Doc->addItem(array('tpl' => 'text.tpl', 'text' => $helpText)); } function _getReorderForm() { $form = $this->_getBaseForm(); $list = array(); $list4Grid = $this->DBObj->getList4Grid(array('order_by' => 'sorter', 'addonWhere' => 'AND `type` IN ("committee", "taskforce")')); foreach ($list4Grid['list'] as $val) { $list[$val['id']] = (strlen($val[$this->fldReorderTitle]) > $this->reorderTitleSize) ? substr($val[$this->fldReorderTitle], 0, $this->reorderTitleSize - 3) . '...' : $val[$this->fldReorderTitle]; } $orderList = Form::createElement('select_edit', 'order_list', false, $list); $orderList->updateAttributes(array('size' => $this->reorderListSize)); $orderList->delAction('add'); $orderList->delAction('del'); $orderList->delAction('edit'); $form->addElement($orderList); $form->addElement('hidden', 'id_parent', $this->DBObj->id_parent); return $form; } }