public function actionDeleteComment() { if (empty($_POST['id']) || !App::isAdmin()) { return $this->redirect('/article'); } $currentArticleUrl = Article::findById(Comment::findById($_POST['id'])->article_id)->url; Comment::deleteComment($_POST['id']); $this->redirect('/article/show/' . $currentArticleUrl); }
public function actionModify() { $article; if (isset($_GET['id'])) { $article = Article::findById($_GET['id']); } else { $article = new Article(); //fix $article->title = ''; $article->content = ''; $article->img_preview_url = ''; $article->author_id = 1; $article->save(); } $this->view->render('modifyArticle', ['article' => $article], 'admin'); }
public static function saveArticle($params) { if (isset($params['id'])) { $article = Article::findById($params['id']); } else { $article = new Article(); } if ($article->checkRequiredColumns($params)) { $url = Text::translitUrl($params['title']); $article->author_id = 1; $article->title = $params['title']; $article->url = $url; $article->url_crc = crc32($url); $article->content = $params['content']; $article->img_preview_url = $params['img_preview_url']; $article->save(); } _debug('saving article...'); _debug('url: ' . $url . ' (crc: ' . crc32($url) . ')', true); }
/** * testSaveAssociatedHasMany method * * @return void */ public function testSaveAssociatedHasMany() { $this->loadFixtures('Article', 'Comment'); $TestModel = new Article(); $TestModel->belongsTo = $TestModel->hasAndBelongsToMany = array(); $result = $TestModel->saveAssociated(array('Article' => array('id' => 2), 'Comment' => array(array('comment' => 'First new comment', 'published' => 'Y', 'user_id' => 1), array('comment' => 'Second new comment', 'published' => 'Y', 'user_id' => 2)))); $this->assertFalse(empty($result)); $result = $TestModel->findById(2); $expected = array('First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment'); $this->assertEquals($expected, Hash::extract($result['Comment'], '{n}.comment')); $result = $TestModel->saveAssociated(array('Article' => array('id' => 2), 'Comment' => array(array('comment' => 'Third new comment', 'published' => 'Y', 'user_id' => 1))), array('atomic' => false)); $this->assertFalse(empty($result)); $result = $TestModel->findById(2); $expected = array('First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment', 'Third new comment'); $this->assertEquals($expected, Hash::extract($result['Comment'], '{n}.comment')); $TestModel->beforeSaveReturn = false; $result = $TestModel->saveAssociated(array('Article' => array('id' => 2), 'Comment' => array(array('comment' => 'Fourth new comment', 'published' => 'Y', 'user_id' => 1))), array('atomic' => false)); $this->assertEquals(array('Article' => false), $result); $result = $TestModel->findById(2); $expected = array('First Comment for Second Article', 'Second Comment for Second Article', 'First new comment', 'Second new comment', 'Third new comment'); $this->assertEquals($expected, Hash::extract($result['Comment'], '{n}.comment')); }