From: <al...@us...> - 2007-08-13 01:53:08
|
Revision: 480 http://sciret.svn.sourceforge.net/sciret/?rev=480&view=rev Author: alpeb Date: 2007-08-12 18:53:06 -0700 (Sun, 12 Aug 2007) Log Message: ----------- Show original question for articles that answer a question Modified Paths: -------------- branches/release-candidates/sciret-1.2/actions/SaveArticle.php branches/release-candidates/sciret-1.2/models/Article.php branches/release-candidates/sciret-1.2/models/ArticleGateway.php branches/release-candidates/sciret-1.2/models/ArticleIterator.php branches/release-candidates/sciret-1.2/models/Question.php branches/release-candidates/sciret-1.2/setup/final.sql branches/release-candidates/sciret-1.2/setup/upgrade_1.2.0.sql branches/release-candidates/sciret-1.2/templates/MainView.tpl branches/release-candidates/sciret-1.2/views/MainView.php branches/release-candidates/sciret-1.2/views/ViewArticle.php Modified: branches/release-candidates/sciret-1.2/actions/SaveArticle.php =================================================================== --- branches/release-candidates/sciret-1.2/actions/SaveArticle.php 2007-08-13 01:48:54 UTC (rev 479) +++ branches/release-candidates/sciret-1.2/actions/SaveArticle.php 2007-08-13 01:53:06 UTC (rev 480) @@ -50,9 +50,10 @@ $historyMessage = $this->user->lang('Article created'); if (isset($_POST['questionID'])) { - require 'models/QuestionGateway.php'; - $questionGateway = new QuestionGateway; - $questionGateway->delete($_POST['questionID']); + require 'models/Question.php'; + $question = new Question($_POST['questionID']); + $art->setQuestion($question->getContents()); + $question->delete(); } } $art->setDraft($_POST['draft']); Modified: branches/release-candidates/sciret-1.2/models/Article.php =================================================================== --- branches/release-candidates/sciret-1.2/models/Article.php 2007-08-13 01:48:54 UTC (rev 479) +++ branches/release-candidates/sciret-1.2/models/Article.php 2007-08-13 01:53:06 UTC (rev 480) @@ -20,6 +20,7 @@ var $title; var $URL; var $expDate; + var $question; var $content; var $excerpt; var $published = 1; @@ -48,7 +49,7 @@ if ($id) { // left join because cat_id=0 doesn't exist in the db - $query = 'SELECT is_bookmark, title, url, expires, content, art.cat_id, cat.name AS catLabel, published, draft, user_id, views, created, modified, modified_user_id, votes_1, votes_2, votes_3, votes_4, votes_5, internal ' + $query = 'SELECT is_bookmark, title, url, expires, question, content, art.cat_id, cat.name AS catLabel, published, draft, user_id, views, created, modified, modified_user_id, votes_1, votes_2, votes_3, votes_4, votes_5, internal ' .'FROM articles art LEFT JOIN categories cat ON cat.cat_id=art.cat_id ' .'WHERE art_id = ?'; $result = $this->db->query($query, $id); @@ -58,6 +59,7 @@ $this->title = $row['title']; $this->URL = $row['url']; $this->expDate = $row['expires']; + $this->question = $row['question']; $this->content = $row['content']; $this->catId = $row['cat_id']; $this->catLabel = $row['catLabel']; @@ -80,12 +82,12 @@ function save() { if (!isset($this->id)) { - $query = 'INSERT INTO articles (is_bookmark, title, url, expires, content, cat_id, published, draft, user_id, views, internal, created) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())'; - $result = $this->db->query($query, $this->isBookmark, $this->title, $this->URL, $this->expDate, $this->content, $this->catId, $this->published, $this->draft, $this->userId, $this->views, $this->internal); + $query = 'INSERT INTO articles (is_bookmark, title, url, expires, question, content, cat_id, published, draft, user_id, views, internal, created) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())'; + $result = $this->db->query($query, $this->isBookmark, $this->title, $this->URL, $this->expDate, $this->question, $this->content, $this->catId, $this->published, $this->draft, $this->userId, $this->views, $this->internal); $this->id = $result->getInsertId(); } else { - $query = 'UPDATE articles SET is_bookmark=?, title=?, url=?, expires=?, content=?, cat_id=?, published=?, draft=?, user_id=?, views=?, created=?, modified=?, modified_user_id=?, votes_1=?, votes_2=?, votes_3=?, votes_4=?, votes_5=?, internal=? WHERE art_id=?'; - $this->db->query($query, $this->isBookmark, $this->title, $this->URL, $this->expDate, $this->content, $this->catId, $this->published, $this->draft, $this->userId, $this->views, $this->creationDate, $this->modificationDate, $this->modifiedByUserId, $this->votes1, $this->votes2, $this->votes3, $this->votes4, $this->votes5, $this->internal, $this->id); + $query = 'UPDATE articles SET is_bookmark=?, title=?, url=?, expires=?, question=?, content=?, cat_id=?, published=?, draft=?, user_id=?, views=?, created=?, modified=?, modified_user_id=?, votes_1=?, votes_2=?, votes_3=?, votes_4=?, votes_5=?, internal=? WHERE art_id=?'; + $this->db->query($query, $this->isBookmark, $this->title, $this->URL, $this->expDate, $this->question, $this->content, $this->catId, $this->published, $this->draft, $this->userId, $this->views, $this->creationDate, $this->modificationDate, $this->modifiedByUserId, $this->votes1, $this->votes2, $this->votes3, $this->votes4, $this->votes5, $this->internal, $this->id); } } @@ -163,6 +165,14 @@ $this->expDate = $expDate; } + function getQuestion() { + return $this->question; + } + + function setQuestion($question) { + $this->question = $question; + } + function getContent() { return $this->content; } Modified: branches/release-candidates/sciret-1.2/models/ArticleGateway.php =================================================================== --- branches/release-candidates/sciret-1.2/models/ArticleGateway.php 2007-08-13 01:48:54 UTC (rev 479) +++ branches/release-candidates/sciret-1.2/models/ArticleGateway.php 2007-08-13 01:53:06 UTC (rev 480) @@ -78,21 +78,21 @@ switch ($specialList) { case 'mostViewed': - $query = 'SELECT art.art_id, is_bookmark, q_id, title, url, expires, SUBSTRING(content, 1, '.EXCERPT_LENGTH.') AS excerpt, cat_id, published, draft, user_id, views, created, modified, modified_user_id, votes_1, votes_2, votes_3, votes_4, votes_5, COUNT( f.file_id ) AS num_files ' + $query = 'SELECT art.art_id, is_bookmark, q_id, title, url, expires, question, SUBSTRING(content, 1, '.EXCERPT_LENGTH.') AS excerpt, cat_id, published, draft, user_id, views, created, modified, modified_user_id, votes_1, votes_2, votes_3, votes_4, votes_5, COUNT( f.file_id ) AS num_files ' .'FROM articles art LEFT JOIN files f ON art.art_id = f.art_id ' . $where .'GROUP BY art.art_id ' .'ORDER BY views DESC LIMIT 0, 5'; break; case 'latest': - $query = 'SELECT art.art_id, is_bookmark, q_id, title, url, expires, SUBSTRING(content, 1, '.EXCERPT_LENGTH.') AS excerpt, cat_id, published, draft, user_id, views, created, modified, modified_user_id, votes_1, votes_2, votes_3, votes_4, votes_5, COUNT( f.file_id ) AS num_files ' + $query = 'SELECT art.art_id, is_bookmark, q_id, title, url, expires, question, SUBSTRING(content, 1, '.EXCERPT_LENGTH.') AS excerpt, cat_id, published, draft, user_id, views, created, modified, modified_user_id, votes_1, votes_2, votes_3, votes_4, votes_5, COUNT( f.file_id ) AS num_files ' .'FROM articles art LEFT JOIN files f ON art.art_id = f.art_id ' . $where .'GROUP BY art.art_id ' .'ORDER BY created DESC LIMIT 0, 5'; break; case 'withFullName': - $query = 'SELECT SQL_CALC_FOUND_ROWS art.art_id, is_bookmark, q_id, title, url, expires, SUBSTRING(content, 1, '.EXCERPT_LENGTH.') AS excerpt, cat_id, published, draft, art.user_id, views, created, modified, modified_user_id, votes_1, votes_2, votes_3, votes_4, votes_5, firstname, lastname ' + $query = 'SELECT SQL_CALC_FOUND_ROWS art.art_id, is_bookmark, q_id, title, url, expires, question, SUBSTRING(content, 1, '.EXCERPT_LENGTH.') AS excerpt, cat_id, published, draft, art.user_id, views, created, modified, modified_user_id, votes_1, votes_2, votes_3, votes_4, votes_5, firstname, lastname ' .'FROM articles art LEFT JOIN users u ON art.user_id = u.user_id ' . $where . " ORDER BY $order $direction"; if ($numRecords != -1) { @@ -100,7 +100,7 @@ } break; default: - $query = 'SELECT SQL_CALC_FOUND_ROWS art.art_id, is_bookmark, q_id, title, url, expires, SUBSTRING(content, 1, '.EXCERPT_LENGTH.') AS excerpt, cat_id, published, draft, user_id, views, created, modified, modified_user_id, votes_1, votes_2, votes_3, votes_4, votes_5, COUNT( f.file_id ) AS num_files ' + $query = 'SELECT SQL_CALC_FOUND_ROWS art.art_id, is_bookmark, q_id, title, url, expires, question, SUBSTRING(content, 1, '.EXCERPT_LENGTH.') AS excerpt, cat_id, published, draft, user_id, views, created, modified, modified_user_id, votes_1, votes_2, votes_3, votes_4, votes_5, COUNT( f.file_id ) AS num_files ' .'FROM articles art LEFT JOIN files f ON art.art_id = f.art_id ' . $where .'GROUP BY art.art_id' @@ -140,7 +140,7 @@ if (is_numeric($searchQuery)) { $whereArr[] = 'art.art_id=?'; $where = implode(' AND ', $whereArr); - $query = 'SELECT art.art_id, is_bookmark, q_id, title, url, expires, SUBSTRING(content, 1, '.EXCERPT_LENGTH.') AS excerpt, cat_id, published, draft, art.user_id, views, created, modified, modified_user_id, votes_1, votes_2, votes_3, votes_4, votes_5, COUNT(f.file_id) AS num_files, firstname, lastname ' + $query = 'SELECT art.art_id, is_bookmark, q_id, title, url, expires, question, SUBSTRING(content, 1, '.EXCERPT_LENGTH.') AS excerpt, cat_id, published, draft, art.user_id, views, created, modified, modified_user_id, votes_1, votes_2, votes_3, votes_4, votes_5, COUNT(f.file_id) AS num_files, firstname, lastname ' .'FROM articles art LEFT JOIN files f on art.art_id = f.art_id LEFT JOIN users u ON art.user_id = u.user_id ' ."WHERE $where " .'GROUP BY art.art_id'; @@ -157,7 +157,7 @@ $whereArr[] = 'MATCH (title, content, url) AGAINST(?)'; $where = implode(' AND ', $whereArr); - $query = 'SELECT SQL_CALC_FOUND_ROWS MATCH(title, content, url) AGAINST(?) AS score, art.art_id, is_bookmark, q_id, title, url, expires, SUBSTRING(content, 1, '.EXCERPT_LENGTH.') AS excerpt, cat_id, published, draft, art.user_id, views, created, modified, modified_user_id, votes_1, votes_2, votes_3, votes_4, votes_5, COUNT(f.file_id) AS num_files, firstname, lastname ' + $query = 'SELECT SQL_CALC_FOUND_ROWS MATCH(title, content, url) AGAINST(?) AS score, art.art_id, is_bookmark, q_id, title, url, expires, question, SUBSTRING(content, 1, '.EXCERPT_LENGTH.') AS excerpt, cat_id, published, draft, art.user_id, views, created, modified, modified_user_id, votes_1, votes_2, votes_3, votes_4, votes_5, COUNT(f.file_id) AS num_files, firstname, lastname ' .'FROM articles art LEFT JOIN files f on art.art_id = f.art_id LEFT JOIN users u ON art.user_id = u.user_id ' ."WHERE $where " .'GROUP BY art.art_id'; @@ -309,7 +309,7 @@ if ($where != '') { $where = 'AND '.$where; } - $query = 'SELECT SQL_CALC_FOUND_ROWS art.art_id, is_bookmark, q_id, title, url, expires, SUBSTRING(content, 1, '.EXCERPT_LENGTH.') AS excerpt, cat_id, published, draft, user_id, views, created, modified, modified_user_id, votes_1, votes_2, votes_3, votes_4, votes_5, COUNT(f.file_id) AS num_files ' + $query = 'SELECT SQL_CALC_FOUND_ROWS art.art_id, is_bookmark, q_id, title, url, expires, question, SUBSTRING(content, 1, '.EXCERPT_LENGTH.') AS excerpt, cat_id, published, draft, user_id, views, created, modified, modified_user_id, votes_1, votes_2, votes_3, votes_4, votes_5, COUNT(f.file_id) AS num_files ' .'FROM articles art LEFT JOIN files f on art.art_id = f.art_id ' ."WHERE published=1 $where " .'GROUP BY art.art_id ' Modified: branches/release-candidates/sciret-1.2/models/ArticleIterator.php =================================================================== --- branches/release-candidates/sciret-1.2/models/ArticleIterator.php 2007-08-13 01:48:54 UTC (rev 479) +++ branches/release-candidates/sciret-1.2/models/ArticleIterator.php 2007-08-13 01:53:06 UTC (rev 480) @@ -33,6 +33,7 @@ $article->setTitle($row['title']); $article->setExpDate($row['expires']); $article->setURL($row['url']); + $article->setQuestion($row['question']); $article->setExcerpt($row['excerpt']); $article->setCategoryId($row['cat_id']); $article->setPublished($row['published']); Modified: branches/release-candidates/sciret-1.2/models/Question.php =================================================================== --- branches/release-candidates/sciret-1.2/models/Question.php 2007-08-13 01:48:54 UTC (rev 479) +++ branches/release-candidates/sciret-1.2/models/Question.php 2007-08-13 01:53:06 UTC (rev 480) @@ -44,6 +44,11 @@ } } + function delete() { + $query = "DELETE FROM questions WHERE question_id=?"; + $this->db->query($query, $this->id); + } + function getId() { return $this->id; } Modified: branches/release-candidates/sciret-1.2/setup/final.sql =================================================================== --- branches/release-candidates/sciret-1.2/setup/final.sql 2007-08-13 01:48:54 UTC (rev 479) +++ branches/release-candidates/sciret-1.2/setup/final.sql 2007-08-13 01:53:06 UTC (rev 480) @@ -5,6 +5,7 @@ `title` text collate utf8_unicode_ci NOT NULL, `url` varchar(255) collate utf8_unicode_ci NOT NULL default '', `expires` date NOT NULL, + `question` text collate utf8_unicode_ci NOT NULL, `content` text collate utf8_unicode_ci NOT NULL, `cat_id` int(11) NOT NULL default '0', `published` tinyint(4) NOT NULL default '0', Modified: branches/release-candidates/sciret-1.2/setup/upgrade_1.2.0.sql =================================================================== --- branches/release-candidates/sciret-1.2/setup/upgrade_1.2.0.sql 2007-08-13 01:48:54 UTC (rev 479) +++ branches/release-candidates/sciret-1.2/setup/upgrade_1.2.0.sql 2007-08-13 01:53:06 UTC (rev 480) @@ -5,3 +5,5 @@ UPDATE configuration SET value = '1.2.0' WHERE field = 'version'; ALTER TABLE `users` ADD `password_changed` DATE NOT NULL AFTER `password` ; + +ALTER TABLE `articles` ADD `question` TEXT NOT NULL AFTER `expires` ; Modified: branches/release-candidates/sciret-1.2/templates/MainView.tpl =================================================================== --- branches/release-candidates/sciret-1.2/templates/MainView.tpl 2007-08-13 01:48:54 UTC (rev 479) +++ branches/release-candidates/sciret-1.2/templates/MainView.tpl 2007-08-13 01:53:06 UTC (rev 480) @@ -87,6 +87,11 @@ <i>({art_num}) </i> <img src="images/{articleImage}" /> <a href="{art_link}" {target} style="font-weight:bold; font-size:17px">{art_title}</a> {bookmark_edit}<br /> + <!-- BEGIN question_block --> + <div> + ({questionStr}) + </div> + <!-- END question_block --> <div> {modifOrCreated} {art_date} - {img_stars} {attachment} </div> Modified: branches/release-candidates/sciret-1.2/views/MainView.php =================================================================== --- branches/release-candidates/sciret-1.2/views/MainView.php 2007-08-13 01:48:54 UTC (rev 479) +++ branches/release-candidates/sciret-1.2/views/MainView.php 2007-08-13 01:53:06 UTC (rev 480) @@ -63,6 +63,7 @@ $this->tpl->set_block('main', 'viewAllLink_block', 'viewAllLink'); $this->tpl->set_block('main', 'viewArticlesLink_block', 'viewArticlesLink'); $this->tpl->set_block('main', 'viewBookmarksLink_block', 'viewBookmarksLink'); + $this->tpl->set_block('articles_block', 'question_block', 'question'); $this->tpl->set_block('unanswered_questions_block', 'answerLink_block', 'answerLink'); @@ -169,7 +170,6 @@ 'target' => $article->isBookmark()? 'target="_blank"' : '', 'bookmark_edit' => $article->isBookmark()? '<a href="'.Library::getLink(array('view' => 'ViewBookmark', 'id' => $article->getId())).'" style="font-size:10px">'.$this->user->lang('details').'</a>' : '', 'art_num' => $article->getId(), - 'articleImage' => $article->isBookmark()? 'bookmark.png' : 'article.png', 'art_title' => $article->getTitle(), 'modifOrCreated'=> $article->getModifiedByUserId() > 0? $this->user->lang('Last Modified') : $this->user->lang('Created on'), 'art_date' => $this->user->formatDate($article->getModifiedByUserId() > 0? $article->getModificationDate() : $article->getCreationDate()), @@ -177,6 +177,18 @@ 'attachment' => $article->getNumFiles()? '<img src="images/attach.gif" />' : '', 'art_excerpt' => strip_tags($article->getExcerpt()).($article->isBookmark()? '' : '...'), )); + + if ($article->isBookmark()) { + $this->tpl->set_var('articleImage', 'bookmark.png'); + } elseif ($article->getQuestion()) { + $this->tpl->set_var('articleImage', 'question.png'); + $this->tpl->set_var('questionStr', $article->getQuestion()); + $this->tpl->parse('question', 'question_block'); + } else { + $this->tpl->set_var('articleImage', 'article.png'); + $this->tpl->set_var('question', ''); + } + if ($article->getCategoryId() == 0) { $this->tpl->set_var('art_category', ''); } else { Modified: branches/release-candidates/sciret-1.2/views/ViewArticle.php =================================================================== --- branches/release-candidates/sciret-1.2/views/ViewArticle.php 2007-08-13 01:48:54 UTC (rev 479) +++ branches/release-candidates/sciret-1.2/views/ViewArticle.php 2007-08-13 01:53:06 UTC (rev 480) @@ -45,6 +45,7 @@ $this->tpl->set_block('view_article', 'edit_del_block', 'edit_del'); $this->tpl->set_block('view_article', 'publish_btn_block', 'publish_btn'); $this->tpl->set_block('view_article', 'history_line_block', 'history_line'); + $this->tpl->set_block('view_article', 'question_block', 'question'); $this->tpl->set_block('view_article', 'mailArticle_block', 'mailArticle'); // *** COMMENTS **** @@ -152,6 +153,13 @@ 'usage' => $article->isInternal() ? '<span style="color: red">'.$this->user->lang('Internal use only').'</span>' : $this->user->lang('Publicly available'), )); + if ($article->getQuestion()) { + $this->tpl->set_var('question', $article->getQuestion()); + $this->tpl->parse('question', 'question_block'); + } else { + $this->tpl->set_var('question', ''); + } + if (!$article->isInternal()) { $this->tpl->parse('mailArticle', 'mailArticle_block'); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |