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); + } +}