protected function subscribe() { $this->setBuilder($b = new JSONCustomBuilder()); try { if (!isset($_POST['email'])) { throw new \InvalidArgumentException('ERR_NO_EMAIL'); } $email = $_POST['email']; if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { throw new \InvalidArgumentException('ERR_BAD_EMAIL'); } //firstly searching for user with this email in users list if ($uid = $this->dbh->getScalar('user_users', 'u_id', ['u_name' => $email])) { $this->dbh->modify('INSERT INTO mail_subscriptions2users (u_id, subscription_id) SELECT %s as me_id, subscription_id FROM mail_subscriptions WHERE subscription_is_active and subscription_is_default', $uid); } else { if ($this->dbh->getScalar('mail_email_subscribers', 'COUNT(*)', ['me_name' => $email])) { throw new \RuntimeException('ERR_MAIL_EXISTS'); } $meID = $this->dbh->modify(QAL::INSERT, 'mail_email_subscribers', ['me_date' => date('Y-m-d H:i:s'), 'me_name' => $email]); $this->dbh->modify('INSERT INTO mail_email2subscriptions (me_id, subscription_id) SELECT %s as me_id, subscription_id FROM mail_subscriptions WHERE subscription_is_active and subscription_is_default', $meID); } $b->setProperties(['result' => true, 'message' => $this->translate('MSG_SUBSCRIBED')]); } catch (\Exception $e) { $b->setProperties(['result' => false, 'message' => $this->translate($e->getMessage())]); } }
protected function clear() { $this->dbh->modify(QAL::DELETE, $this->getTableName()); $b = new JSONCustomBuilder(); $b->setProperty('result', true)->setProperty('mode', 'clear'); $this->setBuilder($b); }
/** * Save quick upload. * * @throws \Exception * @throws SystemException */ protected function savequickupload() { $transactionStarted = $this->dbh->beginTransaction(); try { $upl_id = isset($_POST['upl_id']) ? intval($_POST['upl_id']) : false; $result = $this->dbh->modify(QAL::INSERT, $this->getTableName(), [$this->getParam('pk') => $this->getParam('linkedID'), 'session_id' => session_id(), 'upl_id' => $upl_id]); if ($result && ($langTable = $this->dbh->getTranslationTablename($this->getTableName()))) { // todo: вставка языковых данных $lang_columns = $this->dbh->getColumnsInfo($langTable); $fields = [$this->getPK() => $result]; foreach ($lang_columns as $colName => $colProps) { if (empty($colProps['index']) or $colProps['index'] != 'PRI') { $fields[$colName] = ''; } } $langs = E()->getLanguage()->getLanguages(); foreach ($langs as $lang_id => $lang_data) { $this->dbh->modify(QAL::INSERT, $langTable, array_merge($fields, ['lang_id' => $lang_id])); } } $transactionStarted = !$this->dbh->commit(); $b = new JSONCustomBuilder(); $b->setProperties(['data' => is_int($result) ? $result : false, 'result' => true, 'mode' => is_int($result) ? 'insert' : 'update']); $this->setBuilder($b); } catch (SystemException $e) { if ($transactionStarted) { $this->dbh->rollback(); } throw $e; } }
/** * Revert this template to the initial template. * * @throws SystemException 'ERR_CONTENT_NOT_REVERTED' */ protected function revertTemplate() { $content = $this->dbh->getScalar('SELECT smap_content as content FROM share_sitemap WHERE smap_id = %s', $this->document->getID()); if (dirname($content) == '.' || !file_exists('templates/content/' . basename($content))) { throw new SystemException('ERR_CONTENT_NOT_REVERTED', SystemException::ERR_CRITICAL, $content); } $this->dbh->modify(QAL::UPDATE, 'share_sitemap', array('smap_content' => basename($content), 'smap_content_xml' => QAL::EMPTY_STRING), array('smap_content' => $content)); $b = new JSONCustomBuilder(); $b->setProperties(array('result' => true, 'mode' => 'none')); $this->setBuilder($b); }
/** * Save data in directory. * @throws SystemException 'ERR_NO_DATA' * @throws SystemException 'ERR_BAD_PID' */ protected function saveDir() { $transactionStarted = $this->dbh->beginTransaction(); try { if (!isset($_POST[$this->getTableName()]) || !isset($_POST[$this->getTableName()][$this->getPK()]) || !isset($_POST[$this->getTableName()]['upl_title']) || !isset($_POST[$this->getTableName()]['upl_pid'])) { throw new SystemException('ERR_NO_DATA'); } $data = $_POST[$this->getTableName()]; if (!$data['upl_pid']) { throw new SystemException('ERR_BAD_PID'); } // получаем instance IFileRepository $repository = $this->repoinfo->getRepositoryInstanceById($data['upl_pid']); $mode = empty($data[$this->getPK()]) ? QAL::INSERT : QAL::UPDATE; if ($mode == QAL::INSERT) { $parentPath = $this->dbh->getScalar($this->getTableName(), ['upl_path'], ['upl_id' => $data['upl_pid']]); if (!$parentPath) { throw new SystemException('ERR_BAD_PID'); } unset($data[$this->getPK()]); $data['upl_name'] = $data['upl_filename'] = Translit::asURLSegment($data['upl_title']); $data['upl_mime_type'] = 'unknown/mime-type'; $data['upl_internal_type'] = FileRepoInfo::META_TYPE_FOLDER; $data['upl_childs_count'] = 0; $data['upl_publication_date'] = date('Y-m-d H:i:s'); $data['upl_path'] = $parentPath . (substr($parentPath, -1) != '/' ? '/' : '') . $data['upl_filename']; $where = false; $repository->createDir($data['upl_path']); } else { $where = ['upl_id' => $data['upl_id']]; /*$currentUplPath = simplifyDBResult($this->dbh->select($this->getTableName(), array('upl_path'), array('upl_id' => $data['upl_id'])), 'upl_path', true); $data['upl_name'] = $data['upl_filename'] = Translit::asURLSegment($data['upl_title']); if($currentUplPath != $data['upl_path']){ rename($currentUplPath, $data['upl_path']); }*/ } $result = $this->dbh->modify($mode, $this->getTableName(), $data, $where); $transactionStarted = !$this->dbh->commit(); $uplID = is_int($result) ? $result : (int) $_POST[$this->getTableName()][$this->getPK()]; $args = [$uplID, date('Y-m-d H:i:s')]; $this->dbh->call('proc_update_dir_date', $args); $b = new JSONCustomBuilder(); $b->setProperties(['data' => $uplID, 'result' => true, 'mode' => is_int($result) ? 'insert' : 'update']); $this->setBuilder($b); } catch (SystemException $e) { if ($transactionStarted) { $this->dbh->rollback(); } throw $e; } }
/** * Approve comment. * * @throws \Exception 'Add comment can auth user only' */ protected function approve() { if (!$this->document->user->isAuthenticated()) { throw new \Exception('Add comment can auth user only'); } list($commentId) = $this->getStateParams(); $tabIndex = intval($_POST['tab_index']); $currTableName = $this->commentTables[$tabIndex]; $result = $this->dbh->modify('UPDATE', $currTableName, ['comment_approved' => 1], ['comment_id' => $commentId]); $b = new JSONCustomBuilder(); $b->setProperties(['result' => $commentId]); $this->setBuilder($b); }
/** * Publish material. */ protected function publish() { list($id) = $this->getStateParams(); $this->dbh->modify('UPDATE ' . $this->getTableName() . ' SET ' . $this->publishFieldName . ' = NOT ' . $this->publishFieldName . ' WHERE ' . $this->getPK() . ' = %s', $id); $b = new JSONCustomBuilder(); $b->setProperties(array('result' => true)); $this->setBuilder($b); }
/** * @copydoc LinkingEditor::changeOrder */ protected function changeOrder($direction) { if (!$this->getOrderColumn()) { //Если не задана колонка для пользовательской сортировки то на выход throw new SystemException('ERR_NO_ORDER_COLUMN', SystemException::ERR_DEVELOPER); } $currentID = $this->getStateParams(); list($currentID) = $currentID; //Определяем order_num текущей страницы $currentOrderNum = $this->dbh->getScalar('SELECT ' . $this->getOrderColumn() . ' ' . 'FROM ' . $this->getTableName() . ' ' . 'WHERE ' . $this->getPK() . ' = %s', $currentID); $orderDirection = $direction == Grid::DIR_DOWN ? QAL::ASC : QAL::DESC; $baseFilter = $this->getFilter(); if (!empty($baseFilter)) { $baseFilter = ' AND ' . str_replace('WHERE', '', $this->dbh->buildWhereCondition($this->getFilter())); } else { $baseFilter = ' AND smap_id = ' . $this->document->getID() . ' '; } //Определяем идентификатор записи которая находится рядом с текущей $request = 'SELECT ' . $this->getPK() . ' as neighborID, ' . $this->getOrderColumn() . ' as neighborOrderNum ' . 'FROM ' . $this->getTableName() . ' ' . 'WHERE ' . $this->getOrderColumn() . ' ' . $direction . ' ' . $currentOrderNum . ' ' . $baseFilter . 'ORDER BY ' . $this->getOrderColumn() . ' ' . $orderDirection . ' Limit 1'; $data = convertDBResult($this->dbh->select($request), 'neighborID'); if ($data) { extract(current($data)); $this->dbh->beginTransaction(); $this->dbh->modify(QAL::UPDATE, $this->getTableName(), array($this->getOrderColumn() => $neighborOrderNum), array($this->getPK() => $currentID)); $this->dbh->modify(QAL::UPDATE, $this->getTableName(), array($this->getOrderColumn() => $currentOrderNum), array($this->getPK() => $neighborID)); $this->dbh->commit(); } $b = new JSONCustomBuilder(); $b->setProperties(array('result' => true, 'dir' => $direction)); $this->setBuilder($b); }
/** * @copydoc Grid::changeOrder */ protected function changeOrder($direction) { $id = $this->getStateParams(); list($id) = $id; if (!$this->recordExists($id)) { throw new SystemException('ERR_404', SystemException::ERR_404); } $order = $this->getOrder(); if ($direction == Grid::DIR_UP) { $order[key($order)] = $order[key($order)] == QAL::ASC ? QAL::DESC : QAL::ASC; } $PID = $this->dbh->getScalar($this->getTableName(), ['smap_pid'], ['smap_id' => $id]); if (!is_null($PID)) { $PID = ' = ' . $PID; } else { $PID = 'IS NULL'; } $orderFieldName = key($order); $request = sprintf('SELECT %s, %s FROM %s WHERE %s %s= ( SELECT %s FROM %s WHERE %s = %s ) AND smap_pid %s %s LIMIT 2 ', $this->getPK(), $orderFieldName, $this->getTableName(), $orderFieldName, $direction, $orderFieldName, $this->getTableName(), $this->getPK(), $id, $PID, $this->dbh->buildOrderCondition($order)); $result = $this->dbh->select($request); if (!$result || sizeof($result) < 2) { throw new SystemException('ERR_CANT_MOVE', SystemException::ERR_NOTICE); } $result = convertDBResult($result, $this->getPK(), true); /** * @todo Тут нужно что то пооптимальней придумать для того чтобы осуществить операцию переноса значений между двумя элементами массива * $a = $b; * $b =$a; */ $keys = array_keys($result); $data = []; $c = $result[current($keys)]; $data[current($keys)] = $result[next($keys)]; $data[current($keys)] = $c; foreach ($data as $id2 => $value) { $order = $value['smap_order_num']; $this->dbh->modify(QAL::UPDATE, $this->getTableName(), [$orderFieldName => $order], [$this->getPK() => $id2]); if ($id2 != $id) { $result = $id2; } } $b = new JSONCustomBuilder(); $b->setProperties(['result' => true, 'dir' => $direction, 'nodeID' => $result]); $this->setBuilder($b); }