'new']; if (($companyId = $this->_getDataObj()->getFilter('companyId'))) { $linkOptions['companyId'] = $companyId; } $links['new'] = ['title' => 'Add New ' . $this->getConfig('itemName'), 'url' => $this->url($linkOptions)]; $linkOptions = $this->_getDataObj()->getFilter(); $linkOptions['action'] = 'exportCsv'; $links['exportCsv']= ['title' => 'Export to CSV', 'url' => $this->url($linkOptions)]; return $links; } protected function _doNew() { $options = []; if (($companyId = Qs_Request::getRequestValue('companyId'))) { $options['defaults']['companyId'] = $companyId; } $form = $this->_getNewForm($options); $form->setDefaults(); $this->_addFormItem($form); $this->_postNew(); return $this; } protected function _initFromForm(Qs_Form $form) { $data = $form->getValues(); $form->dfClearUnusedValues($data); $data['bought'] = 'y'; if (array_key_exists('companyId', $data) && !$data['companyId']) { $data['companyId'] = null; } $this->_getDataObj()->initFromForm($data); return $this; } /** * @param int|null $companyId * @return string (format for string: http://BASE_URL/NEED_PAGE?status=active&companyId=%d or http://BASE_URL/NEED_PAGE?status=active&companyId=$companyId) */ public static function getActiveCompanyUsersUrl($companyId = null) { $url = static::getPage('url') . '?status=' . rawurlencode(Entity::STATUS_ACTIVE) . '&companyId='; if ($companyId) { $url .= rawurlencode($companyId); } else { $url .= '%d'; } return $url; } public static function getCommunicationListUsersUrl($communicationListId = null) { $url = static::getPage('url') . '?listId='; if ($communicationListId) { $url .= $communicationListId; } else { $url .= '%d'; } return $url; } public static function getLeadershipUsersUrl($leadershipId = null) { $url = static::getPage('url') . '?leadershipGroupId='; if ($leadershipId) { $url .= $leadershipId; } else { $url .= '%d'; } return $url; } public static function getLeadershipMemberReorderUrl() { return static::getPage('url') . '?action=reorder'; } protected function _doExportCsv() { $dataObj = $this->_getDataObj(); if ($dataObj->hasFilter()) { $form = $this->_getFilterForm(); if ($form->validate()) { $dataObj->addFilter($form->getValues()); } } $options = ['order' => [$this->_getList()->getOrderBy()]]; $dataObj->setSelectOptions($options); $stmt = $dataObj->getList4ExportStatement($options); $rowCallback = function () use ($stmt, $dataObj) { $row = $stmt->fetch(); if ($row) { $dataObj->prepareExportRow($row); } return $row; }; $helper = new ExportCsv([ 'fileName' => $this->getConfig('itemsName') . ' {date}.csv', 'columns' => $dataObj->getExportColumns(), 'rowCallback' => $rowCallback, ]); $helper->export(); $this->_postExportCsv(); exit; } protected function _postExportCsv() { $this->_log(); return $this; } protected function _postInsert() { $this->_sendApprovalEmail(); return parent::_postInsert(); } protected function _postUpdate() { $this->_sendApprovalEmail(); return parent::_postUpdate(); } protected function _sendApprovalEmail() { if ('production' != constant('APPLICATION_ENV')) { // Notification should be enabled on the live website return $this; } $obj = $this->_getDataObj(); if (Entity::STATUS_ACTIVE != $obj->getData('status') || $obj->isApprovalEmailSent()) { return $this; } $data = $obj->clearData()->getData(); $subject = SettingsObj::get('userRegistrationEmailSubject'); $from = SettingsObj::getEmailFrom('userRegistrationEmailFrom'); $to = $data['email']; $body = SettingsObj::get('userRegistrationEmailBody'); $data['link'] = BASE_URL_LANGUAGE; $link = Qs_SiteMap::findFirst(['isMainLoginPage' => 'y'], array('type' => 'User\\Login\\'), null, 'url'); if (false !== $link) { $data['link'] = $link; } $obj->prepareEmailData($data); foreach ($data as $field => $value) { if (is_array($value)) { continue; } $value = htmlspecialchars($value); $body = str_replace('{' . $field . '}', $value, $body); } $this->_sendMail(compact('subject', 'from', 'to', 'body')); $obj->setApprovalEmailSent(); return $this; } protected function _getEditForm(array $options = array()) { /** в імпортованих юзерів немає мила та нікнейма, тому для них не вимагати мило, нікнейм і пароль */ $options['requireEmail'] = (bool) $this->_getDataObj()->getData('email'); $options['requireNickname'] = (bool) $this->_getDataObj()->getData('nickname'); return $this->_getFormInstance('edit', $options); } public static function getEditUrl($id = '%d') { return static::getPage('url') . '?' . urldecode(http_build_query(['action' => 'edit', 'id' => $id])); } public static function getViewUrl($id = '%d') { return static::getPage('url') . '?' . urldecode(http_build_query(['action' => 'view', 'id' => $id])); } protected function _doView() { $this->_getDataObj()->setUserListColumns(['id', 'title']); return parent::_doView(); } protected function _prepareViewItem(array &$item) { if ($this->isActionAllowed('edit')) { $item['editUrl'] = $this->url(['action' => 'edit', 'id' => $this->_getDataObj()->getPrimaryKey()]); } return parent::_prepareViewItem($item); } }