PageRenderTime 67ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/models/comment.php

https://github.com/felixding/LonelyThinker
PHP | 82 lines | 61 code | 0 blank | 21 comment | 0 complexity | 058113c5cf13a15b807d34629c3e773d MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /* SVN FILE: $Id: comment.php 42 2009-09-24 12:53:07Z $ */
  3. /**
  4. * Short description for file.
  5. *
  6. * Long description for file
  7. *
  8. * PHP versions 5
  9. *
  10. * Licensed under The BSD License
  11. * Redistributions of files must retain the above copyright notice.
  12. *
  13. * @filesource
  14. * @copyright Copyright 2007-2009, Felix Ding (http://dingyu.me)
  15. * @link http://lonelythinker.org Project LonelyThinker
  16. * @package LonelyThinker
  17. * @author $LastChangedBy: $
  18. * @version $Revision: 42 $
  19. * @modifiedby $LastChangedBy: $
  20. * @lastmodified $Date: 2009-09-24 20:53:07 +0800 (Thu, 24 Sep 2009) $
  21. * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  22. */
  23. class Comment extends AppModel
  24. {
  25. var $name = 'Comment';
  26. var $belongsTo = array('Post');
  27. var $validate = array(
  28. 'name' => array(
  29. 'notEmpty'=>array('rule'=>'notEmpty', 'message'=>'You forgot to tell us your name'),
  30. 'maxLength'=>array('rule'=>array('maxLength', 50), 'message'=>'What? 50 characters are not enough for your name?!')
  31. ),
  32. 'email' => array(
  33. 'email'=>array('rule'=>'email', 'message'=>"Email is required. Don't worry, it won't be public"),
  34. 'maxLength'=>array('rule'=>array('maxLength', 255), 'message'=>'What? 255 characters are not enough for your email address?!')
  35. ),
  36. 'ip' => array('rule'=>'ip', 'message'=>"Well, I don't understand your IP"),
  37. 'body' => array('rule'=>'notEmpty', 'message'=>'Nothing to say?'),
  38. 'post_id' => array('rule'=>'validatePostId', 'message'=>'Hacking attempt!')
  39. );
  40. /**
  41. * before delete a comment, save the delete action as a new event
  42. *
  43. * @return Boolean true on new event created
  44. * @date 2009-03-15
  45. */
  46. public function beforeDelete()
  47. {
  48. App::import('Model', 'Event');
  49. $this->Event = new Event();
  50. $comment = $this->read(null, $this->id);
  51. $name = 'COMMENT_DELETE_FROM_'.strtoupper($comment['Comment']['status']);
  52. $data = array(
  53. 'name' => $name,
  54. 'value'=> $this->id,
  55. 'priority'=> $this->Event->names[$name]
  56. );
  57. if($this->Event->add($data)) return true;
  58. else return false;
  59. }
  60. /**
  61. * the post with speicific id must exist
  62. *
  63. */
  64. public function validatePostId($data)
  65. {
  66. return $this->Post->hasAny(array('Post.id'=>$data, 'Post.status'=>'published', 'Post.comment'=>'on'));
  67. }
  68. /**
  69. * get the resource link of MySQL connection
  70. */
  71. public function getDBOResourceLink()
  72. {
  73. return $this->getDataSource()->connection;
  74. }
  75. }
  76. ?>