ADD при сохранении статьи сохраняются ID упомянутых точек

This commit is contained in:
Krivchikov Dmitry 2015-09-18 17:51:29 +03:00
parent 101dd5832a
commit 7c2d54f9b6
2 changed files with 42 additions and 0 deletions

View File

@ -100,6 +100,27 @@ class ArticlesController extends Controller
$article->allowComments = $allowComments; $article->allowComments = $allowComments;
$article->save(); $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'); App::redirect('/articles');
} }

View File

@ -0,0 +1,21 @@
<?php
class ArticlePoints extends Model
{
function __construct($fromArray = array())
{
$this->_tableName_ = 'articlePoints';
parent::__construct($fromArray);
}
static function model()
{
return new self();
}
function deleteByArticle($id)
{
App::DB()->query('DELETE FROM `' . $this->_tableName_ . '` WHERE `articleId` = ' . $id);
}
}