Guest User

Untitled

a guest
Nov 23rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. <?php
  2. class User extends AppModel {
  3. public $name = 'User';
  4. public $displayField = 'username';
  5.  
  6. public $validate = array(
  7. 'username' => array(
  8. 'alphaNumeric' => array(
  9. 'rule' => 'alphaNumeric',
  10. 'require' => true,
  11. 'message' => 'Please enter a username'
  12. ),
  13. 'maxLength' => array(
  14. 'rule' => array('maxLength', 15),
  15. 'Username should be no longer than 15 characters'
  16. )
  17. ),
  18. 'email' => array(
  19. 'rule' => 'email',
  20. 'require' => true,
  21. 'message' => 'Please enter a valid email'
  22. ),
  23. 'password' => array(
  24. 'rule' => array('minLength', 5),
  25. 'message' => 'Password must be at least 5 characters long',
  26. 'require' => true
  27. ),
  28. 'view' => array(
  29. )
  30.  
  31. );
  32.  
  33. public $actsAs = array('Containable', 'Acl' => array('type' => 'requester'));
  34.  
  35. public $hasMany = array(
  36. 'Topic' => array(
  37. 'className' => 'Topic',
  38. 'order' => array(
  39. 'Topic.created' => 'DESC',
  40. )
  41. ),
  42. 'Post' => array(
  43. 'className' => 'Post',
  44. 'order' => array(
  45. 'Post.created' => 'DESC',
  46. )
  47. ),
  48. 'Comment' => array (
  49. 'className' => 'Comment',
  50. 'order' => array(
  51. 'Comment.created' => 'DESC',
  52. )
  53. ),
  54. 'Vote' => array (
  55. 'className' => 'Vote',
  56. 'foreignKey' => 'user_id'
  57. )
  58. );
  59.  
  60. public $belongsTo = array(
  61. 'Group' => array(
  62. 'className' => 'Group',
  63. 'foreignKey' => 'group_id'
  64. )
  65. );
  66.  
  67. public static function get($field = null) {
  68. $user = Configure::read('User');
  69. if (empty($user) || (!empty($field) && !array_key_exists($field, $user))) {
  70. return false;
  71. }
  72. }
  73.  
  74. function parentNode() {
  75. if (!$this->id && empty($this->data)) {
  76. return null;
  77. }
  78. if (isset($this->data['User']['group_id'])) {
  79. $groupId = $this->data['User']['group_id'];
  80. } else {
  81. $groupId = $this->field('group_id');
  82. }
  83. if (!$groupId) {
  84. return null;
  85. } else {
  86. return array('Group' => array('id' => $groupId));
  87. }
  88. }
  89.  
  90. function bindNode($user) {
  91. return array('model' => 'Group', 'foreign_key' => $user['User']['group_id'] );
  92. }
  93. }
Add Comment
Please, Sign In to add comment