PageRenderTime 43ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Contacts/Model/Message.php

https://github.com/kareypowell/croogo
PHP | 125 lines | 63 code | 10 blank | 52 comment | 0 complexity | 90fde405d8c0c61b5fb6e07a6d420d29 MD5 | raw file
  1. <?php
  2. App::uses('ContactsAppModel', 'Contacts.Model');
  3. /**
  4. * Message
  5. *
  6. * @category Model
  7. * @package Croogo.Contacts.Model
  8. * @version 1.0
  9. * @author Fahad Ibnay Heylaal <contact@fahad19.com>
  10. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  11. * @link http://www.croogo.org
  12. */
  13. class Message extends ContactsAppModel {
  14. /**
  15. * Model name
  16. *
  17. * @var string
  18. * @access public
  19. */
  20. public $name = 'Message';
  21. /**
  22. * Behaviors
  23. *
  24. * @var array
  25. * @access public
  26. */
  27. public $actsAs = array(
  28. 'Croogo.BulkProcess' => array(
  29. 'actionsMap' => array(
  30. 'read' => 'bulkRead',
  31. 'unread' => 'bulkUnread',
  32. ),
  33. ),
  34. 'Croogo.Trackable',
  35. 'Search.Searchable',
  36. );
  37. /**
  38. * Validation
  39. *
  40. * @var array
  41. * @access public
  42. */
  43. public $validate = array(
  44. 'name' => array(
  45. 'rule' => 'notEmpty',
  46. 'message' => 'This field cannot be left blank.',
  47. ),
  48. 'email' => array(
  49. 'rule' => 'email',
  50. 'message' => 'Please provide a valid email address.',
  51. ),
  52. 'title' => array(
  53. 'rule' => 'notEmpty',
  54. 'message' => 'This field cannot be left blank.',
  55. ),
  56. 'body' => array(
  57. 'rule' => 'notEmpty',
  58. 'message' => 'This field cannot be left blank.',
  59. ),
  60. );
  61. /**
  62. * Model associations: belongsTo
  63. *
  64. * @var array
  65. * @access public
  66. */
  67. public $belongsTo = array(
  68. 'Contact' => array(
  69. 'className' => 'Contacts.Contact',
  70. 'foreignKey' => 'contact_id',
  71. 'conditions' => '',
  72. 'fields' => '',
  73. 'order' => '',
  74. 'counterCache' => true,
  75. ),
  76. );
  77. /**
  78. * Filter fields
  79. *
  80. * @var array
  81. * @access public
  82. */
  83. public $filterArgs = array(
  84. 'contact_id' => array(
  85. 'type' => 'value',
  86. ),
  87. 'status' => array(
  88. 'type' => 'value',
  89. ),
  90. );
  91. /**
  92. * Mark messages as read in bulk
  93. *
  94. * @param array $ids Array of Message Ids
  95. * @return boolean True if successful, false otherwise
  96. */
  97. public function bulkRead($ids) {
  98. return $this->updateAll(
  99. array($this->escapeField('status') => 1),
  100. array($this->escapeField() => $ids)
  101. );
  102. }
  103. /**
  104. * Mark messages as Unread in bulk
  105. *
  106. * @param array $ids Array of Message Ids
  107. * @return boolean True if successful, false otherwise
  108. */
  109. public function bulkUnread($ids) {
  110. return $this->updateAll(
  111. array($this->escapeField('status') => 0),
  112. array($this->escapeField() => $ids)
  113. );
  114. }
  115. }