PageRenderTime 55ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/models/tag.php

https://github.com/felixding/LonelyThinker
PHP | 50 lines | 25 code | 1 blank | 24 comment | 0 complexity | e7f7ae0e91d78059c1dc6b24c70726e5 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /* SVN FILE: $Id: tag.php 39 2009-07-16 10:03:24Z $ */
  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: 39 $
  19. * @modifiedby $LastChangedBy: $
  20. * @lastmodified $Date: 2009-07-16 18:03:24 +0800 (Thu, 16 Jul 2009) $
  21. * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  22. */
  23. class Tag extends AppModel
  24. {
  25. var $name = 'Tag';
  26. var $hasAndBelongsToMany = array(
  27. 'Post'=>array(
  28. 'conditions' => array('Post.status' => 'published'),
  29. 'order' => 'Post.created DESC'
  30. )
  31. );
  32. var $validate = array(
  33. 'title' => array('rule'=>'notEmpty', 'message'=>'You forgot to name a title for the tag'),
  34. 'slug' => array(
  35. 'notEmpty'=>array('rule'=>'notEmpty', 'message'=>'You forgot to give a slug for the tag'),
  36. 'isUnique'=>array('rule'=>'isUnique', 'message'=>'This slug has already been taken'),
  37. 'custom'=>array('rule' =>array('custom', '/^[a-z0-9(\s)]{3,}$/'), 'message'=>'A valid slug must be 3 characters long at least, and consist of lower case English words, numbers and white spaces inbetween only')
  38. )
  39. );
  40. /**
  41. * callbacks
  42. */
  43. public function beforeSave()
  44. {
  45. $this->data['Tag']['slug'] = Inflector::slug($this->data['Tag']['slug'], '-');
  46. return true;
  47. }
  48. }
  49. ?>