From: <al...@us...> - 2008-07-08 03:30:16
|
Revision: 597 http://sciret.svn.sourceforge.net/sciret/?rev=597&view=rev Author: alpeb Date: 2008-07-07 20:30:14 -0700 (Mon, 07 Jul 2008) Log Message: ----------- drop Model and instead grab db connection from DB singleton directly, and use Zend autoloader. First step before moving to the zend framework's Zend_Db_Tables_ classes Modified Paths: -------------- 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/Category.php branches/release-candidates/sciret-1.2/models/CategoryGateway.php branches/release-candidates/sciret-1.2/models/Comment.php branches/release-candidates/sciret-1.2/models/Configuration.php branches/release-candidates/sciret-1.2/models/Favorite.php branches/release-candidates/sciret-1.2/models/FavoriteGateway.php branches/release-candidates/sciret-1.2/models/File.php branches/release-candidates/sciret-1.2/models/History.php branches/release-candidates/sciret-1.2/models/HistoryGateway.php branches/release-candidates/sciret-1.2/models/Link.php branches/release-candidates/sciret-1.2/models/Question.php branches/release-candidates/sciret-1.2/models/QuestionGateway.php branches/release-candidates/sciret-1.2/models/QuestionIterator.php branches/release-candidates/sciret-1.2/models/Todo.php branches/release-candidates/sciret-1.2/models/TodoGateway.php branches/release-candidates/sciret-1.2/models/User.php branches/release-candidates/sciret-1.2/models/UserGateway.php Removed Paths: ------------- branches/release-candidates/sciret-1.2/models/Model.php Modified: branches/release-candidates/sciret-1.2/models/Article.php =================================================================== --- branches/release-candidates/sciret-1.2/models/Article.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/Article.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,23 +9,20 @@ * @packager TheGang */ -require_once 'models/Model.php'; - -class Article extends Model { +class Article { var $id; var $isBookmark = 0; var $questionId; var $catId; var $catLabel; var $title; - var $URL; + var $URL = ''; var $expDate; - var $question; + var $question = ''; var $content; var $excerpt; var $published = 1; var $draft = 0; - var $user; var $userId; var $views = 0; var $creationDate; @@ -44,15 +41,15 @@ var $votes5 = 0; var $internal = 0; + private $user; + function Article($id = false) { - parent::Model(); - if ($id) { // left join because cat_id=0 doesn't exist in the db $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); + $result = DB::getInstance()->query($query, $id); if ($row = $result->fetch()) { $this->id = $id; $this->isBookmark = $row['is_bookmark']; @@ -81,13 +78,73 @@ } function save() { + $db = DB::getInstance(); if (!isset($this->id)) { $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(); + $result = $db->query( $query, array( + $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 = $db->lastInsertId(); } else { - $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); + $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=?'; + DB::getInstance()->query( $query, + array( + $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 + ) + ); } } @@ -213,6 +270,11 @@ $this->views = (int)$views; } + public function getFormatedCreationDate() { + preg_match('/(\d\d\d\d)-(\d\d)-(\d\d)/', $this->getCreationDate(), $matches); + return $matches[2].'/'.$matches[3].'/'.$matches[1]; + } + function getCreationDate() { return $this->creationDate; } @@ -244,11 +306,15 @@ } function getUser() { + if (!isset($this->user)) { + $this->user = new User($this->getUserId()); + } + return $this->user; } - function setUser($userObj) { - $this->user = $userObj; + function setUser(&$userObj) { + $this->user =& $userObj; } function getModificationDate() { @@ -348,7 +414,7 @@ if (!isset($this->files)) { $query = 'SELECT file_id, art_id, filename, comment, hash FROM files WHERE art_id=?'; - $result = $this->db->query($query, $this->id); + $result = DB::getInstance()->query($query, $this->id); $this->files = array(); while ($row = $result->fetch()) { $file = new File; @@ -377,7 +443,7 @@ if (!isset($this->links)) { $query = 'SELECT link_id, art_id, title, url FROM links WHERE art_id=?'; - $result = $this->db->query($query, $this->id); + $result = DB::getInstance()->query($query, $this->id); $this->links = array(); while ($row = $result->fetch()) { $link = new Link; @@ -395,7 +461,7 @@ function getRelatedArticles() { if (!isset($this->relatedArticles)) { $query = 'SELECT art_id, related_art_id FROM articles_related WHERE art_id=?'; - $result = $this->db->query($query, $this->id); + $result = DB::getInstance()->query($query, $this->id); $this->relatedArticles = array(); while ($row = $result->fetch()) { $this->relatedArticles[] = new Article($row['related_art_id']); @@ -420,7 +486,7 @@ $this->getRelatedArticles(); $query = 'DELETE FROM articles_related WHERE art_id=?'; - $this->db->query($query, $this->id); + DB::getInstance()->query($query, $this->id); foreach ($arrRelatedArticles as $relatedArtId) { $article = new Article; @@ -430,13 +496,13 @@ foreach ($this->relatedArticles as $article) { $query = 'INSERT INTO articles_related (art_id, related_art_id) VALUES (?, ?)'; - $this->db->query($query, $this->id, $article->getId()); + DB::getInstance()->query($query, $this->id, $article->getId()); } } function deleteRelatedArticle($artId) { $query = 'DELETE FROM articles_related WHERE art_id=? AND related_art_id=?'; - $this->db->query($query, $this->id, $artId); + DB::getInstance()->query($query, array($this->id, $artId)); } function getComments() { @@ -444,7 +510,7 @@ if (!isset($this->comments)) { $query = 'SELECT comment_id, username, contents, entered, published FROM comments WHERE art_id = ?'; - $result = $this->db->query($query, $this->id); + $result = DB::getInstance()->query($query, $this->id); $this->comments = array(); while ($row = $result->fetch()) { $comment = new Comment; Modified: branches/release-candidates/sciret-1.2/models/ArticleGateway.php =================================================================== --- branches/release-candidates/sciret-1.2/models/ArticleGateway.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/ArticleGateway.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,31 +9,25 @@ * @packager TheGang */ -require_once 'models/Model.php'; -require_once 'models/Article.php'; -require_once 'models/ArticleIterator.php'; - define('EXCERPT_LENGTH', 300); -class ArticleGateway extends Model { +class ArticleGateway { - function getArticles( $catId, - $includeSubCats, - $specialList = false, - $includeUnpublished = false, - $onlyUnpublished = false, - $offset = 0, - $numRecords = -1, - $set = 'all', - $sort = false, - $showExpired = false, - $showDrafts = false) + public static function getArticles( $catId, + $includeSubCats, + $specialList = false, + $includeUnpublished = false, + $onlyUnpublished = false, + $offset = 0, + $numRecords = -1, + $set = 'all', + $sort = false, + $showExpired = false, + $showDrafts = false) { // uncomment for testing //$numRecords = 3; - require_once 'models/CategoryGateway.php'; - $catId = (int)$catId; $whereArr = array(); @@ -111,14 +105,15 @@ break; } - $result = $this->db->query($query); + $result = DB::getInstance()->query($query); if ($numRecords != -1) { $query2 = 'SELECT FOUND_ROWS()'; - $result2 = $this->db->query($query2); - list($totalNumItems) = $result2->fetch(); + $result2 = DB::getInstance()->query($query2); + $rows = $result2->fetch(); + $totalNumItems = $rows['FOUND_ROWS()']; } else { - $totalNumItems = $result->getNumRows(); + $totalNumItems = $result->rowCount(); } return new ArticleIterator($result, $totalNumItems); @@ -144,7 +139,7 @@ .'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'; - $result = $this->db->query($query, $searchQuery); + $result = DB::getInstance()->query($query, $searchQuery); } else { switch ($set) { case 'bookmarks': @@ -164,15 +159,16 @@ if ($numRecords != -1) { $query .= ' LIMIT ' . (int)$offset . ', ' . (int)$numRecords; } - $result = $this->db->query($query, $searchQuery, $searchQuery); + $result = DB::getInstance()->query($query, $searchQuery, $searchQuery); } if ($numRecords != -1) { $query2 = 'SELECT FOUND_ROWS()'; - $result2 = $this->db->query($query2); - list($totalNumItems) = $result2->fetch(); + $result2 = DB::getInstance()->query($query2); + $rows = $result2->fetch(); + $totalNumItems = $rows['FOUND_ROWS()']; } else { - $totalNumItems = $result->getNumRows(); + $totalNumItems = $result->rowCount(); } return new ArticleIterator($result, $totalNumItems); @@ -209,7 +205,7 @@ if ($allWords != '') { $wordList = explode(' ', $allWords); for ($i = 0; $i < count($wordList); $i++) { - $wordList[$i] = $this->db->escape_string($wordList[$i]); + $wordList[$i] = DB::escape_string($wordList[$i]); if ($ocurrences == 'title') { $wordList[$i] = "title LIKE '%{$wordList[$i]}%'"; } elseif ($ocurrences == 'content') { @@ -222,7 +218,7 @@ } if ($exactPhrase != '') { - $exactPhrase = $this->db->escape_string($exactPhrase); + $exactPhrase = DB::escape_string($exactPhrase); if ($ocurrences == 'title') { $whereArr[] = "title LIKE '%$exactPhrase%'"; } elseif ($ocurrences == 'content') { @@ -235,7 +231,7 @@ if ($oneWord != '') { $wordList = explode(' ', $oneWord); for ($i = 0; $i < count($wordList); $i++) { - $wordList[$i] = $this->db->escape_string($wordList[$i]); + $wordList[$i] = DB::escape_string($wordList[$i]); if ($ocurrences == 'title') { $wordList[$i] = "title LIKE '%{$wordList[$i]}%'"; } elseif ($ocurrences == 'content') { @@ -250,7 +246,7 @@ if ($excludeList != '') { $wordList = explode(' ', $excludeList); for ($i = 0; $i < count($wordList); $i++) { - $wordList[$i] = $this->db->escape_string($wordList[$i]); + $wordList[$i] = DB::escape_string($wordList[$i]); if ($ocurrences == 'title') { $wordList[$i] = "title NOT LIKE '%{$wordList[$i]}%'"; } elseif ($ocurrences == 'content') { @@ -317,14 +313,14 @@ if ($numRecords != -1) { $query .= ' LIMIT ' . (int)$offset . ', ' . (int)$numRecords; } - $result = $this->db->query($query); + $result = DB::getInstance()->query($query); if ($numRecords != -1) { $query2 = 'SELECT FOUND_ROWS()'; - $result2 = $this->db->query($query2); + $result2 = DB::getInstance()->query($query2); list($totalNumItems) = $result2->fetch(); } else { - $totalNumItems = $result->getNumRows(); + $totalNumItems = $result->rowCount(); } return new ArticleIterator($result, $totalNumItems); @@ -337,26 +333,26 @@ } $query = 'DELETE FROM articles WHERE art_id=?'; - $this->db->query($query, $id); + DB::getInstance()->query($query, $id); $query = 'DELETE FROM articles_related WHERE art_id=? OR related_art_id=?'; - $this->db->query($query, $id, $id); + DB::getInstance()->query($query, array($id, $id)); $query = 'DELETE FROM comments WHERE art_id=?'; - $this->db->query($query, $id); + DB::getInstance()->query($query, $id); $query = 'DELETE FROM links WHERE art_id=?'; - $this->db->query($query, $id); + DB::getInstance()->query($query, $id); $query = 'DELETE FROM history WHERE art_id=?'; - $this->db->query($query, $id); + DB::getInstance()->query($query, $id); } function numUnpublishedArticles() { $query = "SELECT art_id FROM articles WHERE published = 0"; - $result = $this->db->query($query); + $result = DB::getInstance()->query($query); - return $result->getNumRows(); + return $result->rowCount(); } } Modified: branches/release-candidates/sciret-1.2/models/ArticleIterator.php =================================================================== --- branches/release-candidates/sciret-1.2/models/ArticleIterator.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/ArticleIterator.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,10 +9,7 @@ * @packager TheGang */ -require_once 'models/Model.php'; -require_once 'models/Article.php'; - -class ArticleIterator extends Model { +class ArticleIterator { var $resultSet; var $totalNumItems; @@ -53,13 +50,6 @@ $article->setNumFiles($row['num_files']); } - if (isset($row['firstname'])) { - $tUser = new User; - $tUser->setFirstName($row['firstname']); - $tUser->setLastName($row['lastname']); - $article->setUser($tUser); - } - return $article; } Modified: branches/release-candidates/sciret-1.2/models/Category.php =================================================================== --- branches/release-candidates/sciret-1.2/models/Category.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/Category.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,9 +9,7 @@ * @packager TheGang */ -require_once 'models/Model.php'; - -class Category extends Model { +class Category { var $id; var $label = ''; var $description = ''; @@ -20,11 +18,9 @@ var $iconFileName = ''; function Category($id = false) { - parent::Model(); - if ($id) { $query = 'SELECT cat_id, name, description, parent_id, icon FROM categories WHERE cat_id = ?'; - $result = $this->db->query($query, $id); + $result = DB::getInstance()->query($query, $id); if ($row = $result->fetch()) { $this->id = $id; $this->label = $row['name']; @@ -36,31 +32,32 @@ } function save() { + $db = DB::getInstance(); if (!isset($this->id)) { $query = 'INSERT INTO categories (name, description, parent_id, icon) VALUES(?, ?, ?, ?)'; - $result = $this->db->query($query, $this->label, $this->description, $this->parentId, $this->iconFileName); - $this->id = $result->getInsertId(); + $result = $db->query($query, array($this->label, $this->description, $this->parentId, $this->iconFileName)); + $this->id = $db->lastInsertId(); } else { $query = 'UPDATE categories SET name=?, description=?, parent_id=?, icon=? WHERE cat_id=?'; - $result = $this->db->query($query, $this->label, $this->description, $this->parentId, $this->iconFileName, $this->id); + $result = $db->query($query, array($this->label, $this->description, $this->parentId, $this->iconFileName, $this->id)); } } function delete() { $query = 'SELECT cat_id FROM categories WHERE parent_id=?'; - $result = $this->db->query($query, $this->id); + $result = DB::getInstance()->query($query, $this->id); if ($result->getNumRows() > 0) { return false; } $query = 'DELETE FROM categories WHERE cat_id=?'; - $this->db->query($query, $this->id); + DB::getInstance()->query($query, $this->id); $query = 'UPDATE articles SET cat_id=0 WHERE cat_id=?'; - $this->db->query($query, $this->id); + DB::getInstance()->query($query, $this->id); $query = 'UPDATE questions SET cat_id=0 WHERE cat_id=?'; - $this->db->query($query, $this->id); + DB::getInstance()->query($query, $this->id); return true; } Modified: branches/release-candidates/sciret-1.2/models/CategoryGateway.php =================================================================== --- branches/release-candidates/sciret-1.2/models/CategoryGateway.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/CategoryGateway.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,10 +9,7 @@ * @packager TheGang */ -require_once 'models/Model.php'; -require_once 'models/Category.php'; - -class CategoryGateway extends Model { +class CategoryGateway { var $categories; function getCategories() { @@ -22,7 +19,7 @@ $this->categories[0] = new Category; $query = 'SELECT cat_id, name, description, parent_id, icon FROM categories ORDER BY parent_id, name'; - $result = $this->db->query($query); + $result = DB::getInstance()->query($query); while ($row = $result->fetch()) { $this->categories[$row['cat_id']] = new Category; $this->categories[$row['cat_id']]->setId($row['cat_id']); Modified: branches/release-candidates/sciret-1.2/models/Comment.php =================================================================== --- branches/release-candidates/sciret-1.2/models/Comment.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/Comment.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,9 +9,7 @@ * @packager TheGang */ -require_once 'models/Model.php'; - -class Comment extends Model { +class Comment { var $id; var $userName; var $entered; @@ -20,11 +18,9 @@ var $articleId; function Comment($id = false) { - parent::Model(); - if ($id) { $query = 'SELECT username, contents, entered, art_id, published FROM comments WHERE comment_id=?'; - $result = $this->db->query($query, $id); + $result = DB::getInstance()->query($query, $id); if ($row = $result->fetch()) { $this->userName = $row['username']; $this->contents = $row['contents']; @@ -37,19 +33,20 @@ } function save() { + $db = DB::getInstance(); if (!isset($this->id)) { $query = 'INSERT INTO comments (username, contents, entered, art_id, published) VALUES(?, ?, ?, ?, ?)'; - $result = $this->db->query($query, $this->userName, $this->contents, $this->entered, $this->articleId, $this->published); - $this->id = $result->getInsertId(); + $result = $db->query($query, array($this->userName, $this->contents, $this->entered, $this->articleId, $this->published)); + $this->id = $db->lastInsertId(); } else { $query = 'UPDATE comments SET username=?, contents=?, entered=?, art_id=?, published=? WHERE comment_id=?'; - $this->db->query($query, $this->userName, $this->contents, $this->entered, $this->articleId, $this->published, $this->id); + $db->query($query, array($this->userName, $this->contents, $this->entered, $this->articleId, $this->published, $this->id)); } } function delete() { $query = 'DELETE FROM comments WHERE comment_id = ?'; - $this->db->query($query, $this->id); + DB::getInstance()->query($query, $this->id); } function getId() { Modified: branches/release-candidates/sciret-1.2/models/Configuration.php =================================================================== --- branches/release-candidates/sciret-1.2/models/Configuration.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/Configuration.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,10 +9,8 @@ * @packager TheGang */ -require_once 'models/Model.php'; +class Configuration { -class Configuration extends Model { - var $configurationArray = array( // var name => array(defaultValue, isHidden) 'publishKB' => 1, @@ -25,10 +23,8 @@ ); function Configuration() { - parent::Model(); - $query = 'SELECT field, value FROM configuration'; - $result = $this->db->query($query); + $result = DB::getInstance()->query($query); while ($row = $result->fetch()) { $this->configurationArray[$row['field']] = $row['value']; } @@ -36,11 +32,11 @@ function save() { $query = 'DELETE FROM configuration'; - $result = $this->db->query($query); + $result = DB::getInstance()->query($query); foreach ($this->configurationArray as $field => $value) { $query = 'INSERT INTO configuration (field, value) VALUES (?, ?)'; - $result = $this->db->query($query, $field, $value); + $result = DB::getInstance()->query($query, $field, $value); } } Modified: branches/release-candidates/sciret-1.2/models/Favorite.php =================================================================== --- branches/release-candidates/sciret-1.2/models/Favorite.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/Favorite.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,13 +9,11 @@ * @packager TheGang */ -require_once 'models/Model.php'; - define('FAVORITE_TYPE_ARTICLE', 1); define('FAVORITE_TYPE_LOCATION', 2); define('FAVORITE_TYPE_SEARCHRESULT', 3); -class Favorite extends Model { +class Favorite { var $id; var $userId; var $type; @@ -24,11 +22,10 @@ var $searchStr = ''; function Favorite($id = false) { - parent::Model(); if ($id) { $query = 'SELECT favorite_id, user_id, favorite_type, art_id, cat_id, search_str FROM favorites WHERE favorite_id = ?'; - $result = $this->db->query($query, $id); + $result = DB::getInstance()->query($query, $id); if ($row = $result->fetch()) { $this->id = $id; $this->userId = $row['user_id']; @@ -42,9 +39,10 @@ function save() { if (!isset($this->id)) { + $db = DB::getInstance(); $query = 'INSERT INTO favorites (user_id, favorite_type, art_id, cat_id, search_str) VALUES (?, ?, ?, ?, ?)'; - $result = $this->db->query($query, $this->userId, $this->type, $this->artId, $this->catId, $this->searchStr); - $this->id = $result->getInsertId(); + $result = $db->query($query, array($this->userId, $this->type, $this->artId, $this->catId, $this->searchStr)); + $this->id = $db->lastInsertId(); } } Modified: branches/release-candidates/sciret-1.2/models/FavoriteGateway.php =================================================================== --- branches/release-candidates/sciret-1.2/models/FavoriteGateway.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/FavoriteGateway.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,10 +9,7 @@ * @packager TheGang */ -require_once 'models/Model.php'; -require_once 'models/Favorite.php'; - -class FavoriteGateway extends Model { +class FavoriteGateway { var $favorites; function getFavorites($userId) { @@ -20,7 +17,7 @@ $this->favorites = array(); $query = 'SELECT favorite_id, user_id, favorite_type, art_id, cat_id, search_str FROM favorites WHERE user_id = ?'; - $result = $this->db->query($query, $userId); + $result = DB::getInstance()->query($query, $userId); while ($row = $result->fetch()) { $favorite = new Favorite; @@ -39,36 +36,36 @@ function isArticleFavorite($artId, $userId) { $query = 'SELECT favorite_id FROM favorites WHERE art_id = ? AND user_id = ?'; - $result = $this->db->query($query, $artId, $userId); + $result = DB::getInstance()->query($query, array($artId, $userId)); - return ($result->getNumRows() > 0); + return ($result->rowCount() > 0); } function deleteArticleFavorite($artId, $userId) { $query = 'DELETE FROM favorites WHERE art_id = ? AND user_id = ?'; - $result = $this->db->query($query, $artId, $userId); + $result = DB::getInstance()->query($query, $artId, $userId); } function deleteSearchResultFavorite($queryStr, $userId) { $query = 'DELETE FROM favorites WHERE search_str = ? AND user_id = ?'; - $result = $this->db->query($query, $queryStr, $userId); + $result = DB::getInstance()->query($query, $queryStr, $userId); } function deleteLocationFavorite($catId, $userId) { $query = 'DELETE FROM favorites WHERE cat_id = ? AND user_id = ?'; - $result = $this->db->query($query, $catId, $userId); + $result = DB::getInstance()->query($query, $catId, $userId); } function isSearchResultFavorite($queryStr, $userId) { $query = 'SELECT favorite_id FROM favorites WHERE search_str = ? AND user_id = ?'; - $result = $this->db->query($query, $queryStr, $userId); + $result = DB::getInstance()->query($query, $queryStr, $userId); return ($result->getNumRows() > 0); } function isLocationFavorite($catId, $userId) { $query = 'SELECT favorite_id FROM favorites WHERE cat_id = ? AND user_id = ?'; - $result = $this->db->query($query, $catId, $userId); + $result = DB::getInstance()->query($query, $catId, $userId); return ($result->getNumRows() > 0); } Modified: branches/release-candidates/sciret-1.2/models/File.php =================================================================== --- branches/release-candidates/sciret-1.2/models/File.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/File.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,9 +9,7 @@ * @packager TheGang */ -require_once 'models/Model.php'; - -class File extends Model { +class File { var $id; var $articleId; var $fileName; @@ -19,11 +17,10 @@ var $hash; function File($id = false) { - parent::Model(); if ($id) { $query = 'SELECT art_id, filename, comment, hash FROM files WHERE file_id = ?'; - $result = $this->db->query($query, $id); + $result = DB::$instance->query($query, $id); if (!$row = $result->fetch()) { return; } @@ -38,15 +35,16 @@ function save() { if (!isset($this->id)) { + $db = DB::getInstance(); $query = 'INSERT INTO files (art_id, filename, comment, hash) VALUES (?, ?, ?, ?)'; - $result = $this->db->query($query, $this->articleId, $this->fileName, $this->comment, $this->hash); - $this->id = $result->getInsertId(); + $result = $db->query($query, array($this->articleId, $this->fileName, $this->comment, $this->hash)); + $this->id = $db->lastInsertId(); } } function delete() { $query = 'DELETE FROM files WHERE file_id=?'; - $this->db->query($query, $this->id); + DB::$instance->query($query, $this->id); return @unlink('uploads/files/'.$this->hash); } Modified: branches/release-candidates/sciret-1.2/models/History.php =================================================================== --- branches/release-candidates/sciret-1.2/models/History.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/History.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,9 +9,7 @@ * @packager TheGang */ -require_once 'models/Model.php'; - -class History extends Model { +class History { var $id; var $articleId; var $date; @@ -19,15 +17,12 @@ var $action; var $actionArgs = ''; - function History() { - parent::Model(); - } - function save() { if (!isset($this->id)) { + $db = DB::getInstance(); $query = 'INSERT INTO history (art_id, date, user, action, action_args) VALUES (?, ?, ?, ?, ?)'; - $result = $this->db->query($query, $this->articleId, $this->date, $this->userFullName, $this->action, $this->actionArgs); - $this->id = $result->getInsertId(); + $result = $db->query($query, array($this->articleId, $this->date, $this->userFullName, $this->action, $this->actionArgs)); + $this->id = $db->lastInsertId(); } } Modified: branches/release-candidates/sciret-1.2/models/HistoryGateway.php =================================================================== --- branches/release-candidates/sciret-1.2/models/HistoryGateway.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/HistoryGateway.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,18 +9,11 @@ * @packager TheGang */ -require_once 'models/Model.php'; -require_once 'models/History.php'; +class HistoryGateway { -class HistoryGateway extends Model { - - function HistoryGateway() { - parent::Model(); - } - function getEvents($articleId) { $query = 'SELECT history_id, art_id, date, user, action, action_args FROM history WHERE art_id=? ORDER BY date DESC'; - $result = $this->db->query($query, $articleId); + $result = DB::getInstance()->query($query, $articleId); $historyArr = array(); while ($row = $result->fetch()) { $history = new History; Modified: branches/release-candidates/sciret-1.2/models/Link.php =================================================================== --- branches/release-candidates/sciret-1.2/models/Link.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/Link.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,20 +9,16 @@ * @packager TheGang */ -require_once 'models/Model.php'; - -class Link extends Model { +class Link { var $id; var $articleId; var $title; var $URL; function Link($id = false) { - parent::Model(); - if ($id) { $query = 'SELECT art_id, title, url FROM links WHERE link_id = ?'; - $result = $this->db->query($query, $id); + $result = DB::getInstance()->query($query, $id); if ($row = $result->fetch()) { $this->id = $id; $this->articleId = $row['art_id']; @@ -34,15 +30,16 @@ function save() { if (!isset($this->id)) { + $db = DB::getInstance(); $query = 'INSERT INTO links (art_id, title, url) VALUES (?, ?, ?)'; - $result = $this->db->query($query, $this->articleId, $this->title, $this->URL); - $this->id = $result->getInsertId(); + $result = $db->query($query, array($this->articleId, $this->title, $this->URL)); + $this->id = $db->lastInsertId(); } } function delete() { $query = 'DELETE FROM links WHERE link_id=?'; - $this->db->query($query, $this->id); + DB::getInstance()->query($query, $this->id); } function getId() { Deleted: branches/release-candidates/sciret-1.2/models/Model.php =================================================================== --- branches/release-candidates/sciret-1.2/models/Model.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/Model.php 2008-07-08 03:30:14 UTC (rev 597) @@ -1,21 +0,0 @@ -<?php - -/* -* @copyright Copyright (C) 2005-2007 TheGang http://www.the-gang.net -* @license http://www.fsf.org/copyleft/lgpl.html GNU Lesser General Public License -* @author Alejandro Pedraza -* @since Sciret 1.0 -* @package Sciret -* @packager TheGang -*/ - -class Model { - - var $db; - - function Model() { - $this->db =& DB::DBFactory(DB_ENGINE, DB_HOST, DB_USER, DB_PASSWORD); - } -} - -?> Modified: branches/release-candidates/sciret-1.2/models/Question.php =================================================================== --- branches/release-candidates/sciret-1.2/models/Question.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/Question.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,9 +9,7 @@ * @packager TheGang */ -require_once 'models/Model.php'; - -class Question extends Model { +class Question { var $id; var $userName; var $contents; @@ -20,11 +18,9 @@ var $published; function Question($id = false) { - parent::Model(); - if ($id) { $query = 'SELECT username, contents, cat_id, creation, published FROM questions WHERE question_id=?'; - $result = $this->db->query($query, $id); + $result = DB::$instance->query($query, $id); if ($row = $result->fetch()) { $this->id = $id; $this->userName = $row['username']; @@ -38,15 +34,16 @@ function save() { if (!isset($this->id)) { + $db = DB::getInstance(); $query = 'INSERT INTO questions (username, contents, cat_id, creation, published) VALUES (?, ?, ?, NOW(), ?)'; - $result = $this->db->query($query, $this->userName, $this->contents, $this->categoryId, $this->published); - $this->id = $result->getInsertId(); + $result = $db->query($query, array($this->userName, $this->contents, $this->categoryId, $this->published)); + $this->id = $db->lastInsertId(); } } function delete() { $query = "DELETE FROM questions WHERE question_id=?"; - $this->db->query($query, $this->id); + DB::$instance->query($query, $this->id); } function getId() { Modified: branches/release-candidates/sciret-1.2/models/QuestionGateway.php =================================================================== --- branches/release-candidates/sciret-1.2/models/QuestionGateway.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/QuestionGateway.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,12 +9,8 @@ * @packager TheGang */ -require_once 'models/Model.php'; -require_once 'models/Question.php'; -require_once 'models/QuestionIterator.php'; +class QuestionGateway { -class QuestionGateway extends Model { - function getQuestions($catId, $onlyPublished = false, $onlyUnpublished = false) { require_once 'models/CategoryGateway.php'; @@ -40,7 +36,7 @@ . $where .'ORDER BY creation DESC'; - $result = $this->db->query($query); + $result = DB::getInstance()->query($query); return new QuestionIterator($result); } @@ -48,12 +44,12 @@ function publish($id) { $id = $id? 1 : 0; $query = 'UPDATE questions SET published='.$id; - $this->db->query($query); + DB::getInstance()->query($query); } function delete($id) { $query = 'DELETE FROM questions WHERE question_id = ?'; - $this->db->query($query, $id); + DB::getInstance()->query($query, $id); } } Modified: branches/release-candidates/sciret-1.2/models/QuestionIterator.php =================================================================== --- branches/release-candidates/sciret-1.2/models/QuestionIterator.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/QuestionIterator.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,10 +9,7 @@ * @packager TheGang */ -require_once 'models/Model.php'; -require_once 'models/Question.php'; - -class QuestionIterator extends Model { +class QuestionIterator { var $resultSet; function QuestionIterator($resultSet) { Modified: branches/release-candidates/sciret-1.2/models/Todo.php =================================================================== --- branches/release-candidates/sciret-1.2/models/Todo.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/Todo.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,12 +9,10 @@ * @packager TheGang */ -require_once 'models/Model.php'; - define('TODO_STATUS_PENDING', 0); define('TODO_STATUS_COMPLETED', 1); -class Todo extends Model { +class Todo { var $id; var $userId; var $title; @@ -28,11 +26,9 @@ var $hasRelatedArticles; function Todo($id = false) { - parent::Model(); - if ($id) { $query = 'SELECT user_id, title, content, status, private, creation_date, due_date FROM todos WHERE todo_id = ?'; - $result = $this->db->query($query, $id); + $result = DB::getInstance()->query($query, $id); if ($row = $result->fetch()) { $this->id = $id; $this->userId = $row['user_id']; @@ -49,7 +45,7 @@ function getRelatedArticles() { if (!isset($this->relatedArticles)) { $query = 'SELECT todo_id, related_art_id FROM todos_related WHERE todo_id=?'; - $result = $this->db->query($query, $this->id); + $result = DB::getInstance()->query($query, $this->id); $this->relatedArticles = array(); while ($row = $result->fetch()) { $this->relatedArticles[] = new Article($row['related_art_id']); @@ -65,7 +61,7 @@ function hasRelatedArticles() { if (!isset($this->hasRelatedArticles)) { $query = 'SELECT a.draft FROM articles a, todos_related tr WHERE a.art_id=tr.related_art_id AND todo_id = ?'; - $result = $this->db->query($query, $this->id); + $result = DB::getInstance()->query($query, $this->id); $this->hasRelatedArticles = false; while ($row = $result->fetch()) { if ($row['draft'] == 0) { @@ -86,7 +82,7 @@ $this->getRelatedArticles(); $query = 'DELETE FROM todos_related WHERE todo_id=?'; - $this->db->query($query, $this->id); + DB::getInstance()->query($query, $this->id); foreach ($arrRelatedArticles as $relatedArtId) { $article = new Article; @@ -96,23 +92,24 @@ foreach ($this->relatedArticles as $article) { $query = 'INSERT INTO todos_related (todo_id, related_art_id) VALUES (?, ?)'; - $this->db->query($query, $this->id, $article->getId()); + DB::getInstance()->query($query, $this->id, $article->getId()); } } function deleteRelatedArticle($artId) { $query = 'DELETE FROM todos_related WHERE todo_id=? AND related_art_id=?'; - $this->db->query($query, $this->id, $artId); + DB::getInstance()->query($query, $this->id, $artId); } function save() { + $db = DB::getInstance(); if (!isset($this->id)) { $query = 'INSERT INTO todos (user_id, title, content, status, private, creation_date, due_date) VALUES (?, ?, ?, ?, ?, ?, ?)'; - $result = $this->db->query($query, $this->userId, $this->title, $this->content, $this->status, $this->private, $this->creationDate, $this->dueDate); - $this->id = $result->getInsertId(); + $result = $db->query($query, array($this->userId, $this->title, $this->content, $this->status, $this->private, $this->creationDate, $this->dueDate)); + $this->id = $db->lastInsertId(); } else { $query = 'UPDATE todos SET user_id=?, title=?, content=?, status=?, private=?, creation_date=?, due_date=? WHERE todo_id=?'; - $result = $this->db->query($query, $this->userId, $this->title, $this->content, $this->status, $this->private, $this->creationDate, $this->dueDate, $this->id); + $result = $db->query($query, array($this->userId, $this->title, $this->content, $this->status, $this->private, $this->creationDate, $this->dueDate, $this->id)); } } Modified: branches/release-candidates/sciret-1.2/models/TodoGateway.php =================================================================== --- branches/release-candidates/sciret-1.2/models/TodoGateway.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/TodoGateway.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,10 +9,9 @@ * @packager TheGang */ -require_once 'models/Model.php'; require_once 'models/Todo.php'; -class TodoGateway extends Model { +class TodoGateway { var $todos; function getTodos($userId) { @@ -22,13 +21,13 @@ $query = "SELECT todo_id, user_id, title, content, status, private, creation_date, due_date " ."FROM todos " ."WHERE (user_id=? OR private=0) AND due_date != '0000-00-00' ORDER BY due_date ASC"; - $result = $this->db->query($query, $userId); + $result = DB::getInstance()->query($query, $userId); $this->_fillData($result); $query = "SELECT todo_id, user_id, title, content, status, private, creation_date, due_date " ."FROM todos " ."WHERE (user_id=? OR private=0) AND due_date = '0000-00-00'"; - $result = $this->db->query($query, $userId); + $result = DB::getInstance()->query($query, $userId); $this->_fillData($result); } @@ -53,16 +52,16 @@ function deleteTodo($todoId, $userId) { $query = 'SELECT todo_id FROM todos WHERE todo_id = ? AND user_id = ?'; - $result = $this->db->query($query, $todoId, $userId); + $result = DB::getInstance()->query($query, $todoId, $userId); if (!$result->getNumRows()) { return false; } $query = 'DELETE FROM todos_related WHERE todo_id = ?'; - $result = $this->db->query($query, $todoId); + $result = DB::getInstance()->query($query, $todoId); $query = 'DELETE FROM todos WHERE todo_id = ?'; - $result = $this->db->query($query, $todoId); + $result = DB::getInstance()->query($query, $todoId); return true; } Modified: branches/release-candidates/sciret-1.2/models/User.php =================================================================== --- branches/release-candidates/sciret-1.2/models/User.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/User.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,13 +9,17 @@ * @packager TheGang */ -require_once 'models/Model.php'; +class User { + const ROLE_ANONYMOUS = 1; + const ROLE_REGISTERED = 3; // 2 | ROLE_ANONYMOUS; + const ROLE_ADMIN = 7; // 4 | ROLE_REGISTERED ; -define('ROLE_ANONYMOUS', 1); -define('ROLE_REGISTERED', 2 | ROLE_ANONYMOUS); -define('ROLE_ADMIN', 4 | ROLE_REGISTERED); + /** + * I need these to distinguish this class with Monkeys' User class + */ + public $app = 'sciret'; + public $publicId; -class User extends Model { var $id; var $firstName; var $lastName; @@ -24,14 +28,14 @@ var $password; var $passwordChanged; var $admin = 0; - var $role = ROLE_ANONYMOUS; + var $role = User::ROLE_ANONYMOUS; var $langArr; var $skipTranslations = false; var $preferences = array( 'startBrowsing' => 'all', 'articlesPerPage' => 10, 'dateFormat' => 'Month Day, Year', - 'language' => LANGUAGE_DEFAULT, + 'language' => '', // set in the constructor 'navigationType' => 'catAndSubCats', 'hiddenCategories' => '', ); @@ -40,11 +44,12 @@ var $disallowedPasswordChars = array('"', '@', '#', '%', '^', '&', '*', '(', ')', ','); function User($id = false) { - parent::Model(); + $this->preferences['language'] = Zend_Registry::get('config')->general->language_default; + if ($id) { - $query = 'SELECT firstname, lastname, username, email, password, password_changed, admin, preferences FROM users WHERE user_id = ?'; - $result = $this->db->query($query, $id); + $query = 'SELECT firstname, lastname, username, email, password, password_changed, admin, preferences FROM users WHERE id = ?'; + $result = DB::getInstance()->query($query, $id); if ($row = $result->fetch()) { $this->id = $id; $this->firstName = $row['firstname']; @@ -62,19 +67,28 @@ } } - $this->role = ($this->admin == 1)? ROLE_ADMIN : ROLE_REGISTERED; + $this->setRole(); } } + + $this->init(); } + public function init() { + if ($this->id) { + $this->publicId = $this->id; + } + } + function save() { + $db = DB::getInstance(); if (!isset($this->id)) { $query = 'INSERT INTO users SET firstname=?, lastname=?, username=?, email=?, admin=?, password=MD5(?), password_changed=?, preferences=?'; - $result = $this->db->query($query, $this->firstName, $this->lastName, $this->userName, $this->email, $this->admin, $this->password, $this->passwordChanged, serialize($this->preferences)); - $this->id = $result->getInsertId(); + $result = $db->query($query, array($this->firstName, $this->lastName, $this->userName, $this->email, $this->admin, $this->password, $this->passwordChanged, serialize($this->preferences))); + $this->id = $db->lastInsertId(); } else { - $query = 'UPDATE users SET firstname=?, lastname=?, username=?, email=?, password_changed=?, admin=?, preferences=? WHERE user_id=?'; - $result = $this->db->query($query, $this->firstName, $this->lastName, $this->userName, $this->email, $this->passwordChanged, $this->admin, serialize($this->preferences), $this->id); + $query = 'UPDATE users SET firstname=?, lastname=?, username=?, email=?, password_changed=?, admin=?, preferences=? WHERE id=?'; + $result = $db->query($query, array($this->firstName, $this->lastName, $this->userName, $this->email, $this->passwordChanged, $this->admin, serialize($this->preferences), $this->id)); } } @@ -103,6 +117,7 @@ } function setId($id) { + $this->publicId = $value; $this->id = (int)$id; } @@ -125,7 +140,7 @@ function setAdmin($isAdmin) { $this->admin = $isAdmin? 1 : 0; if ($this->admin == 1) { - $this->role = ROLE_ADMIN; + $this->role = User::ROLE_ADMIN; } } @@ -149,6 +164,10 @@ return $this->password; } + function setRole() { + $this->role = ($this->admin == 1)? User::ROLE_ADMIN : User::ROLE_REGISTERED; + } + function getRole() { return $this->role; } @@ -187,8 +206,8 @@ return false; } - $query = 'UPDATE users SET password=MD5(?), password_changed = \''.date('Y-m-d').'\' WHERE `user_id` = ?'; - $this->db->query($query, $password, $this->id); + $query = 'UPDATE users SET password=MD5(?), password_changed = \''.date('Y-m-d').'\' WHERE `id` = ?'; + DB::getInstance()->query($query, $password, $this->id); $this->passwordChanged = date('Y-m-d'); return true; @@ -199,7 +218,7 @@ } function getPreference($field) { - if ($this->role == ROLE_ANONYMOUS && isset($_COOKIE[$field])) { + if ($this->role == User::ROLE_ANONYMOUS && isset($_COOKIE[$field])) { return $_COOKIE[$field]; } @@ -207,7 +226,7 @@ } function setPreference($field, $value) { - if ($this->role == ROLE_ANONYMOUS) { + if ($this->role == User::ROLE_ANONYMOUS) { setcookie($field, $value, time() + 60*60*24*90); // cookie expires in 90 days } @@ -284,7 +303,7 @@ $file = realpath(dirname(__FILE__)."/../languages/$language.txt"); $filemtime = date('Y-m-d H:i:s', filemtime($file)); $query = 'SELECT last_updated, content FROM language_cache WHERE language=? AND last_updated >= ?'; - $result = $this->db->query($query, $language, $filemtime); + $result = DB::getInstance()->query($query, array($language, $filemtime)); if ($row = $result->fetch()) { $this->langArr = unserialize($row['content']); } @@ -306,9 +325,9 @@ } $query = 'DELETE FROM language_cache WHERE language=?'; - $this->db->query($query, $language); + DB::getInstance()->query($query, $language); $query = 'INSERT INTO language_cache (language, last_updated, content) VALUES(?, ?, ?)'; - $this->db->query($query, $language, date('Y-m-d H:i:s'), serialize($this->langArr)); + DB::getInstance()->query($query, array($language, date('Y-m-d H:i:s'), serialize($this->langArr))); } if (isset($this->langArr[$phrase])) { Modified: branches/release-candidates/sciret-1.2/models/UserGateway.php =================================================================== --- branches/release-candidates/sciret-1.2/models/UserGateway.php 2008-07-08 03:02:12 UTC (rev 596) +++ branches/release-candidates/sciret-1.2/models/UserGateway.php 2008-07-08 03:30:14 UTC (rev 597) @@ -9,21 +9,20 @@ * @packager TheGang */ -require_once 'models/Model.php'; require_once 'models/User.php'; -class UserGateway extends Model { +class UserGateway { - function getValidatedUser($username, $password, $configuration) { + public static function getValidatedUser($username, $password, $configuration) { if (in_array($configuration->getConfigValue('version'), array(0, '1.1.0'))) { - $query = 'SELECT user_id, firstname, lastname, username, email, admin FROM users WHERE username=? AND password=MD5(?)'; + $query = 'SELECT id, firstname, lastname, username, email, admin FROM users WHERE username=? AND password=MD5(?)'; } else { - $query = 'SELECT user_id, firstname, lastname, username, email, password_changed, admin FROM users WHERE username=? AND password=MD5(?)'; + $query = 'SELECT id, firstname, lastname, username, email, password_changed, admin FROM users WHERE username=? AND password=MD5(?)'; } - $result = $this->db->query($query, $username, $password); + $result = DB::getInstance()->query($query, array($username, $password)); if ($row = $result->fetch()) { $user = new User; - $user->setId($row['user_id']); + $user->setId($row['id']); $user->setFirstName($row['firstname']); $user->setLastName($row['lastname']); $user->setUserName($row['username']); @@ -32,6 +31,7 @@ $user->setPasswordChanged($row['password_changed']); } $user->setAdmin($row['admin']); + $user->setRole(); return $user; } @@ -40,12 +40,12 @@ } function getUsersList() { - $query = 'SELECT user_id, firstname, lastname, username, email, admin FROM users'; + $query = 'SELECT id, firstname, lastname, username, email, admin FROM users'; $result = $this->db->query($query); $users = array(); while ($row = $result->fetch()) { $user = new User; - $user->setId($row['user_id']); + $user->setId($row['id']); $user->setFirstName($row['firstname']); $user->setLastName($row['lastname']); $user->setUserName($row['username']); @@ -58,7 +58,7 @@ } function deleteUser($userId) { - $query = 'DELETE FROM users WHERE user_id=?'; + $query = 'DELETE FROM users WHERE id=?'; $this->db->query($query, $userId); $query = 'UPDATE articles SET user_id = 1 WHERE user_id=?'; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |