tmgmt.entity.message.inc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. /*
  3. * @file
  4. * Contains message entity class.
  5. */
  6. /**
  7. * Entity class for the tmgmt_message entity.
  8. *
  9. * @ingroup tmgmt_job
  10. */
  11. class TMGMTMessage extends Entity {
  12. /**
  13. * The ID of the message..
  14. *
  15. * @var integer
  16. */
  17. public $mid;
  18. /**
  19. * The ID of the job.
  20. *
  21. * @var integer
  22. */
  23. public $tjid;
  24. /**
  25. * The ID of the job item.
  26. *
  27. * @var integer
  28. */
  29. public $tjiid;
  30. /**
  31. * User uid.
  32. *
  33. * @var integer
  34. */
  35. public $uid;
  36. /**
  37. * The message text.
  38. *
  39. * @var string
  40. */
  41. public $message;
  42. /**
  43. * An array of string replacement arguments as used by t().
  44. *
  45. * @var array
  46. */
  47. public $variables;
  48. /**
  49. * The time when the message object was created as a timestamp.
  50. *
  51. * @var integer
  52. */
  53. public $created;
  54. /**
  55. * Type of the message (debug, status, warning or error).
  56. *
  57. * @var string
  58. */
  59. public $type;
  60. /**
  61. * {@inheritdoc}
  62. */
  63. public function __construct(array $values = array()) {
  64. parent::__construct($values, 'tmgmt_message');
  65. if (empty($this->created)) {
  66. $this->created = REQUEST_TIME;
  67. }
  68. if (empty($this->type)) {
  69. $this->type = 'status';
  70. }
  71. }
  72. /**
  73. * {@inheritdoc}
  74. */
  75. public function defaultLabel() {
  76. $created = format_date($this->created);
  77. switch ($this->type) {
  78. case 'error':
  79. return t('Error message from @time', array('@time' => $created));
  80. case 'status':
  81. return t('Status message from @time', array('@time' => $created));
  82. case 'warning':
  83. return t('Warning message from @time', array('@time' => $created));
  84. case 'debug':
  85. return t('Debug message from @time', array('@time' => $created));
  86. }
  87. }
  88. /**
  89. * Returns the translated message.
  90. *
  91. * @return
  92. * The translated message.
  93. */
  94. public function getMessage() {
  95. $text = $this->message;
  96. if (is_array($this->variables) && !empty($this->variables)) {
  97. $text = t($text, $this->variables);
  98. }
  99. return $text;
  100. }
  101. /**
  102. * Loads the job entity that this job message is attached to.
  103. *
  104. * @return TMGMTJob
  105. * The job entity that this job message is attached to or FALSE if there was
  106. * a problem.
  107. */
  108. public function getJob() {
  109. if (!empty($this->tjid)) {
  110. return tmgmt_job_load($this->tjid);
  111. }
  112. return FALSE;
  113. }
  114. /**
  115. * Loads the job entity that this job message is attached to.
  116. *
  117. * @return TMGMTJobItem
  118. * The job item entity that this job message is attached to or FALSE if
  119. * there was a problem.
  120. */
  121. public function getJobItem() {
  122. if (!empty($this->tjiid)) {
  123. return tmgmt_job_item_load($this->tjiid);
  124. }
  125. return FALSE;
  126. }
  127. }