Advertisement
Guest User

Untitled

a guest
Feb 26th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. namespace Yac\Core;
  2. class content
  3. {
  4. public contentID;
  5. public bodytext;
  6. public pageID;
  7. public function __construct(contentID = null, bodytext = Null, pageID = Null) -> void
  8. {
  9. let this->contentID = contentID;
  10. let this->bodytext = bodytext;
  11. let this->pageID = pageID;
  12. }
  13.  
  14. public function getContent(alias) -> void
  15. {
  16. var pdo, stmt, result;
  17.  
  18. let pdo = DataBase::register();
  19. let stmt = pdo->prepare("SELECT content.contentID, content.bodytext, content.pageID FROM content INNER JOIN page ON content.pageID = page.pageID WHERE page.alias= :alias");
  20. stmt->bindParam(":alias", alias);
  21. stmt->execute();
  22. if stmt->rowCount() > 0 {
  23. let result = stmt->fetch(PDO::FETCH_OBJ);
  24. let this->contentID = result->contentID;
  25. let this->bodytext = result->bodytext;
  26. let this->pageID = result->pageID;
  27. }
  28. }
  29.  
  30. public function getContentByID(id) -> void
  31. {
  32. var pdo, stmt, result;
  33.  
  34. let pdo = DataBase::register();
  35. let stmt = pdo->prepare("SELECT content.contentID, content.bodytext, content.pageID FROM content WHERE content.pageID= :id");
  36. stmt->bindParam(":id", id);
  37. stmt->execute();
  38. if stmt->rowCount() > 0 {
  39. let result = stmt->fetch(pdo::FETCH_OBJ);
  40. let this->contentID = result->contentID;
  41. let this->bodytext = result->bodytext;
  42. let this->pageID = result->pageID;
  43. }
  44. }
  45.  
  46. public function save() -> void
  47. {
  48. var pdo, stmt;
  49.  
  50. let pdo = DataBase::register();
  51. let stmt = pdo->prepare("INSERT INTO content (contentID, bodytext, pageID)
  52. VALUES (:contentID, :bodytext, :pageID)
  53. ON DUPLICATE KEY
  54. UPDATE contentID = LAST_INSERT_ID(contentID), bodytext = :bodytext, pageID = :pageID");
  55. stmt->bindParam(":contentID", this->contentID);
  56. stmt->bindParam(":bodytext", this->bodytext);
  57. stmt->bindParam(":pageID", this->pageID);
  58. stmt->execute();
  59. }
  60.  
  61. public static function destroy(id) -> void
  62. {
  63. var pdo, stmt;
  64.  
  65. let pdo = DataBase::register();
  66. let stmt = pdo->prepare("DELETE FROM content WHERE pageID = :pageID");
  67. stmt->bindParam(":pageID", id);
  68. stmt->execute();
  69. }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement