views_handler_argument_dates_various.inc

  1. 3.x modules/node/views_handler_argument_dates_various.inc
  2. 2.x modules/node/views_handler_argument_dates_various.inc

Handlers for various date arguments.

File

modules/node/views_handler_argument_dates_various.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Handlers for various date arguments.
  5. *
  6. * @ingroup views_argument_handlers
  7. */
  8. /**
  9. * Argument handler for a full date (CCYYMMDD)
  10. */
  11. class views_handler_argument_node_created_fulldate extends views_handler_argument_date {
  12. /**
  13. * Constructor implementation
  14. */
  15. function construct() {
  16. parent::construct();
  17. $this->format = 'F j, Y';
  18. $this->arg_format = 'Ymd';
  19. $this->formula = views_date_sql_format($this->arg_format, "***table***.$this->real_field");
  20. }
  21. /**
  22. * Provide a link to the next level of the view
  23. */
  24. function summary_name($data) {
  25. $created = $data->{$this->name_alias};
  26. return format_date(strtotime($created . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
  27. }
  28. /**
  29. * Provide a link to the next level of the view
  30. */
  31. function title() {
  32. return format_date(strtotime($this->argument . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
  33. }
  34. }
  35. /**
  36. * Argument handler for a year (CCYY)
  37. */
  38. class views_handler_argument_node_created_year extends views_handler_argument_date {
  39. /**
  40. * Constructor implementation
  41. */
  42. function construct() {
  43. parent::construct();
  44. $this->arg_format = 'Y';
  45. $this->formula = views_date_sql_extract('YEAR', "***table***.$this->real_field");
  46. }
  47. }
  48. /**
  49. * Argument handler for a year plus month (CCYYMM)
  50. */
  51. class views_handler_argument_node_created_year_month extends views_handler_argument_date {
  52. /**
  53. * Constructor implementation
  54. */
  55. function construct() {
  56. parent::construct();
  57. $this->format = 'F Y';
  58. $this->arg_format = 'Ym';
  59. $this->formula = views_date_sql_format($this->arg_format, "***table***.$this->real_field");
  60. }
  61. /**
  62. * Provide a link to the next level of the view
  63. */
  64. function summary_name($data) {
  65. $created = $data->{$this->name_alias};
  66. return format_date(strtotime($created . "15" . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
  67. }
  68. /**
  69. * Provide a link to the next level of the view
  70. */
  71. function title() {
  72. return format_date(strtotime($this->argument . "15" . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
  73. }
  74. }
  75. /**
  76. * Argument handler for a month (MM)
  77. */
  78. class views_handler_argument_node_created_month extends views_handler_argument_date {
  79. /**
  80. * Constructor implementation
  81. */
  82. function construct() {
  83. parent::construct();
  84. $this->formula = views_date_sql_extract('MONTH', "***table***.$this->real_field");
  85. $this->format = 'F';
  86. $this->arg_format = 'm';
  87. }
  88. /**
  89. * Provide a link to the next level of the view
  90. */
  91. function summary_name($data) {
  92. $month = str_pad($data->{$this->name_alias}, 2, '0', STR_PAD_LEFT);
  93. return format_date(strtotime("2005" . $month . "15" . " 00:00:00 UTC" ), 'custom', $this->format, 'UTC');
  94. }
  95. /**
  96. * Provide a link to the next level of the view
  97. */
  98. function title() {
  99. $month = str_pad($this->argument, 2, '0', STR_PAD_LEFT);
  100. return format_date(strtotime("2005" . $month . "15" . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
  101. }
  102. function summary_argument($data) {
  103. // Make sure the argument contains leading zeroes.
  104. return str_pad($data->{$this->base_alias}, 2, '0', STR_PAD_LEFT);
  105. }
  106. }
  107. /**
  108. * Argument handler for a day (DD)
  109. */
  110. class views_handler_argument_node_created_day extends views_handler_argument_date {
  111. /**
  112. * Constructor implementation
  113. */
  114. function construct() {
  115. parent::construct();
  116. $this->formula = views_date_sql_extract('DAY', "***table***.$this->real_field");
  117. $this->format = 'j';
  118. $this->arg_format = 'd';
  119. }
  120. /**
  121. * Provide a link to the next level of the view
  122. */
  123. function summary_name($data) {
  124. $day = str_pad($data->{$this->name_alias}, 2, '0', STR_PAD_LEFT);
  125. // strtotime respects server timezone, so we need to set the time fixed as utc time
  126. return format_date(strtotime("2005" . "05" . $day . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
  127. }
  128. /**
  129. * Provide a link to the next level of the view
  130. */
  131. function title() {
  132. $day = str_pad($this->argument, 2, '0', STR_PAD_LEFT);
  133. return format_date(strtotime("2005" . "05" . $day . " 00:00:00 UTC"), 'custom', $this->format, 'UTC');
  134. }
  135. function summary_argument($data) {
  136. // Make sure the argument contains leading zeroes.
  137. return str_pad($data->{$this->base_alias}, 2, '0', STR_PAD_LEFT);
  138. }
  139. }
  140. /**
  141. * Argument handler for a week.
  142. */
  143. class views_handler_argument_node_created_week extends views_handler_argument_date {
  144. /**
  145. * Constructor implementation
  146. */
  147. function construct() {
  148. parent::construct();
  149. $this->arg_format = 'w';
  150. $this->formula = views_date_sql_extract('WEEK', "***table***.$this->real_field");
  151. }
  152. /**
  153. * Provide a link to the next level of the view
  154. */
  155. function summary_name($data) {
  156. $created = $data->{$this->name_alias};
  157. return t('Week @week', array('@week' => $created));
  158. }
  159. }

Related topics