From 7c2d54f9b64a3a2d8164f0184f5f389654e512cf Mon Sep 17 00:00:00 2001 From: Krivchikov Dmitry Date: Fri, 18 Sep 2015 17:51:29 +0300 Subject: [PATCH] =?UTF-8?q?ADD=20=D0=BF=D1=80=D0=B8=20=D1=81=D0=BE=D1=85?= =?UTF-8?q?=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D0=B8=20=D1=81=D1=82=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=D0=B8=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D1=8F?= =?UTF-8?q?=D1=8E=D1=82=D1=81=D1=8F=20ID=20=D1=83=D0=BF=D0=BE=D0=BC=D1=8F?= =?UTF-8?q?=D0=BD=D1=83=D1=82=D1=8B=D1=85=20=D1=82=D0=BE=D1=87=D0=B5=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ground/controllers/ArticlesController.php | 21 +++++++++++++++++++++ ground/models/ArticlePoints.php | 21 +++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 ground/models/ArticlePoints.php diff --git a/ground/controllers/ArticlesController.php b/ground/controllers/ArticlesController.php index 31b8a7f..bae9d01 100644 --- a/ground/controllers/ArticlesController.php +++ b/ground/controllers/ArticlesController.php @@ -100,6 +100,27 @@ class ArticlesController extends Controller $article->allowComments = $allowComments; $article->save(); + preg_match_all("((\[#(\d+)[>\|](.*?)\])|(\[#(\d+)\]))", $text, $links); + $links = isset($links[0]) ? $links[0] : FALSE; + var_dump($links); + + ArticlePoints::model()->deleteByArticle($article->id); + if ($links) { + foreach ($links as $link) { + $idAndLink = mb_substr($link, 2, -1); + $delimiter = strpos($idAndLink, '|') === FALSE ? '>' : '|'; + $idAndLink = explode($delimiter, $idAndLink); + $linkId = $idAndLink[0]; + + if (Point::model()->getByPK($linkId)) { + ArticlePoints::model()->add(array( + 'articleId' => $article->id, + 'pointId' => $linkId, + )); + } + } + } + App::redirect('/articles'); } diff --git a/ground/models/ArticlePoints.php b/ground/models/ArticlePoints.php new file mode 100644 index 0000000..8158287 --- /dev/null +++ b/ground/models/ArticlePoints.php @@ -0,0 +1,21 @@ +_tableName_ = 'articlePoints'; + parent::__construct($fromArray); + } + + static function model() + { + return new self(); + } + + function deleteByArticle($id) + { + App::DB()->query('DELETE FROM `' . $this->_tableName_ . '` WHERE `articleId` = ' . $id); + } +}