googleplushangoutevent_List_Table

The Yakadanda Google+ Hangout Events googleplushangoutevent List Table class.

Defined (1)

The class is defined in the following location(s).

/lib/_list-table.php  
  1. class googleplushangoutevent_List_Table extends WP_List_Table { 
  2. function __construct() { 
  3. global $status, $page; 
  4.  
  5. // Set parent defaults 
  6. parent::__construct(array( 
  7. 'singular' => 'event',  
  8. 'plural' => 'events',  
  9. 'ajax' => false 
  10. )); 
  11.  
  12. function column_default($item, $column_name) { 
  13. switch ($column_name) { 
  14. case 'author': 
  15. $url = isset($item["\0*\0modelData"]['creator']['id']) ? 'https://plus.google.com/' . $item["\0*\0modelData"]['creator']['id'] : 'mailto:' . $item["\0*\0modelData"]['creator']['email']; 
  16. return '<a href="' . $url . '">' . $item["\0*\0modelData"]['creator']['displayName'] . '</a>'; 
  17. case 'time': 
  18. $start = isset($item["\0*\0modelData"]['start']['dateTime']) ? $item["\0*\0modelData"]['start']['dateTime'] : $item["\0*\0modelData"]['start']['date']; 
  19. $end = isset($item["\0*\0modelData"]['end']['dateTime']) ? $item["\0*\0modelData"]['end']['dateTime'] : $item["\0*\0modelData"]['end']['date']; 
  20. $timezone = isset($item['timeZoneLocation']) ? $item['timeZoneLocation'] : $item['timeZoneCalendar']; 
  21. return $this->get_time($start, $end, $timezone); 
  22. case 'location': 
  23. return isset($item['location']) ? '<a href="http://maps.google.com/?q='. $item['location'] .'">' . $item['location'] . '</a>' : '<a href="' . $item['hangoutLink'] . '">Hangout</a>'; 
  24. case 'date': 
  25. return $this->get_date($item['created'], $item['updated']); 
  26. default: 
  27. return print_r($item, true); // Show the whole array for troubleshooting purposes 
  28.  
  29. function column_title($item) { 
  30. // Build row actions 
  31. $actions = array( 
  32. 'extend' => sprintf(__('<a href="?page=%s&action=%s&id=%s" class="cta--secondary">Extend</a>', 'yakadanda-google-hangout-events'), $_REQUEST['page'], 'extend', $item['id']),  
  33. 'delete' => sprintf(__('<a href="?page=%s&action=%s&id=%s" class="cta--secondary">Delete</a>', 'yakadanda-google-hangout-events'), $_REQUEST['page'], 'delete', $item['id']),  
  34. 'view' => sprintf(__('<a href="%s" class="cta--secondary">View</a>', 'yakadanda-google-hangout-events'), $item['htmlLink']) 
  35. ); 
  36.  
  37. $title = '<a href="?page=' . $_REQUEST['page'] . '&action=extend&id=' . $item['id'] . '">' . $item['summary'] . '</a>'; 
  38. if ( $item['visibility'] ) $title = $title . ' - <span class="post-state">Private</span>'; 
  39. // Return the title contents 
  40. return sprintf('<strong>%1$s</strong>%2$s',  
  41. /** $1%s */ $title,  
  42. /** $2%s */ $this->row_actions($actions) 
  43. ); 
  44.  
  45. function column_cb($item) { 
  46. return sprintf( 
  47. '<input id="cb-select-%1$s" type="checkbox" name="%2$s[]" value="%1$s" />',  
  48. /** $1%s */ $item['id'],  
  49. /** $2%s */ $this->_args['plural'] 
  50. ); 
  51.  
  52. function get_columns() { 
  53. $columns = array( 
  54. 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text 
  55. 'title' => __('Title', 'yakadanda-google-hangout-events'),  
  56. 'author' => __('Author', 'yakadanda-google-hangout-events'),  
  57. 'time' => __('Time', 'yakadanda-google-hangout-events'),  
  58. 'location' => __('Location', 'yakadanda-google-hangout-events'),  
  59. 'date' => __('Date', 'yakadanda-google-hangout-events') 
  60. ); 
  61.  
  62. return $columns; 
  63.  
  64. function get_sortable_columns() { 
  65. $sortable_columns = array( 
  66. 'title' => array('summary', false), // true means it's already sorted 
  67. 'location' => array('location', false),  
  68. 'date' => array('created', false) 
  69. ); 
  70.  
  71. return $sortable_columns; 
  72.  
  73. function get_bulk_actions() { 
  74. $actions = array( 
  75. 'delete' => 'Delete' 
  76. ); 
  77.  
  78. return $actions; 
  79.  
  80. function process_bulk_action() { 
  81. // Detect when a bulk action is being triggered... 
  82. if ('delete' === $this->current_action()) { 
  83. if (isset($_GET['events']) && is_array($_GET['events'])) { 
  84. foreach ($_GET['events'] as $eventId) { 
  85. googleplushangoutevent_delete_event($eventId); 
  86.  
  87. function prepare_items() { 
  88. global $wpdb; 
  89.  
  90. $per_page = 20; 
  91.  
  92. $columns = $this->get_columns(); 
  93. $hidden = array(); 
  94. $sortable = $this->get_sortable_columns(); 
  95.  
  96. $this->_column_headers = array($columns, $hidden, $sortable); 
  97.  
  98. $this->process_bulk_action(); 
  99.  
  100. $data = googleplushangoutevent_response_admin(); 
  101.  
  102. function usort_reorder($a, $b) { 
  103. $orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : 'updated'; // If no sort, default to title 
  104. $order = (!empty($_REQUEST['order'])) ? $_REQUEST['order'] : 'asc'; // If no order, default to asc 
  105. $result = strcmp($a[$orderby], $b[$orderby]); // Determine sort order 
  106. return ($order === 'desc') ? $result : -$result; // Send final sort direction to usort 
  107.  
  108. usort($data, 'usort_reorder'); 
  109.  
  110. $current_page = $this->get_pagenum(); 
  111.  
  112. $total_items = count($data); 
  113.  
  114. $data = array_slice($data, (($current_page - 1) * $per_page), $per_page); 
  115.  
  116. $this->items = $data; 
  117.  
  118. $this->set_pagination_args(array( 
  119. 'total_items' => $total_items, // WE have to calculate the total number of items 
  120. 'per_page' => $per_page, // WE have to determine how many items to show on a page 
  121. 'total_pages' => ceil($total_items / $per_page) // WE have to calculate the total number of pages 
  122. )); 
  123.  
  124. function get_date($created, $modified) { 
  125. $created = strtotime($created); 
  126. $modified = strtotime($modified); 
  127.  
  128. $date = $created; 
  129. $status = 'Published'; 
  130. if ($created < $modified ) { 
  131. $date = $modified; 
  132. $status = 'Last Modified'; 
  133.  
  134. $output = '<abbr title="' . date('Y/m/d g:i:s A', $date) . '">' . date('Y/m/d', $date) . '</abbr><br>' . $status; 
  135.  
  136. return $output; 
  137.  
  138. function get_time($startdate, $finishdate, $timezone) { 
  139. $startdate = new DateTime( $startdate ); 
  140. $finishdate = new DateTime( $finishdate ); 
  141.  
  142. $dateTimeZone = new DateTimeZone( $timezone ); 
  143.  
  144. $startdate->setTimezone($dateTimeZone); 
  145. $startdate = $startdate->format('c'); 
  146.  
  147. $finishdate->setTimezone($dateTimeZone); 
  148. $finishdate = $finishdate->format('c'); 
  149.  
  150. $diff = round(abs(strtotime($finishdate)-strtotime($startdate))/86400); 
  151.  
  152. $begindate = str_split($startdate, 19); 
  153. $year_event = date('Y', strtotime($begindate[0])); 
  154. $year_current = date('Y'); 
  155. $years = $year_event - $year_current; 
  156.  
  157. $output = null; 
  158.  
  159. $timezone_abbreviations = googleplushangoutevent_timezone_abbreviations( $timezone ); 
  160.  
  161. $output = date('D, M d, g:i A', strtotime($begindate[0])) . ' ' . $timezone_abbreviations; 
  162. if ($years > 0) $output = date('D, M d Y, g:i A', strtotime($begindate[0])) . ' ' . $timezone_abbreviations; 
  163.  
  164. if ( $diff >= 1 ) { 
  165. $enddate = str_split($finishdate, 19); 
  166. $output = date('D, M d, g:i A', strtotime($begindate[0])) . ' ' . $timezone_abbreviations . ' - ' . date('D, M d, g:i A', strtotime($enddate[0])) . ' ' . $timezone_abbreviations; 
  167. if ($years > 0) $output = date('D, M d Y, g:i A', strtotime($begindate[0])) . ' ' . $timezone_abbreviations . ' - ' . date('D, M d Y, g:i A', strtotime($enddate[0])) . ' ' . $timezone_abbreviations; 
  168.  
  169. if ( !isset($timezone_abbreviations) ) { 
  170. $output = date('D, M d, ', strtotime($begindate[0])) . 'All day'; 
  171. if ($years > 0) $output = date('D, M d Y, ', strtotime($begindate[0])) . 'All day'; 
  172.  
  173. return $output; 
  174.