function prepare_items($per_page) { global $wpdb; /** * REQUIRED. Now we need to define our column headers. This includes a complete * array of columns to be displayed (slugs & titles), a list of columns * to keep hidden, and a list of columns that are sortable. Each of these * can be defined in another method (as we've done here) before being * used to build the value for our _column_headers property. */ $columns = $this->get_columns(); $hidden = array(); $sortable = $this->get_sortable_columns(); /** * REQUIRED. Finally, we build an array to be used by the class for column * headers. The $this->_column_headers property takes an array which contains * 3 other arrays. One for all columns, one for hidden columns, and one * for sortable columns. */ $this->_column_headers = array($columns, $hidden, $sortable); /** * Optional. You can handle your bulk actions however you see fit. In this * case, we'll handle them within our package just to keep things clean. */ $this->process_bulk_action(); /** * Get all the shares and convert in array for this class to process */ // Get the context $consumer = new LTI_Tool_Consumer($_SESSION[LTI_SESSION_PREFIX . 'key'], array($wpdb->base_prefix)); $resource = new LTI_Resource_Link($consumer, $_SESSION[LTI_SESSION_PREFIX . 'resourceid']); $lti_shares = $resource->getShares(); for ($i = 0; $i < count($lti_shares); $i++) { $data[$i]['ID'] = $i; $data[$i]['name'] = $lti_shares[$i]->title; $data[$i]['key'] = $lti_shares[$i]->consumer_key; $data[$i]['approved'] = $lti_shares[$i]->approved ? 'Yes' : 'No'; $data[$i]['resource_link_id'] = $lti_shares[$i]->resource_link_id; } /** * This checks for sorting input and sorts the data in our array accordingly. * * In a real-world situation involving a database, you would probably want * to handle sorting by passing the 'orderby' and 'order' values directly * to a custom query. The returned data will be pre-sorted, and this array * sorting technique would be unnecessary. */ function usort_reorder($a, $b) { $orderby = !empty($_REQUEST['orderby']) ? $_REQUEST['orderby'] : 'name'; //If no sort, default to title $order = !empty($_REQUEST['order']) ? $_REQUEST['order'] : 'asc'; //If no order, default to asc $result = strcmp($a[$orderby], $b[$orderby]); //Determine sort order return $order === 'asc' ? $result : -$result; //Send final sort direction to usort } // Don't usort if there is no data if (isset($data)) { usort($data, 'usort_reorder'); } /** * REQUIRED for pagination. Let's figure out what page the user is currently * looking at. We'll need this later, so you should always include it in * your own package classes. */ $current_page = $this->get_pagenum(); /** * REQUIRED for pagination. Let's check how many items are in our data array. * In real-world use, this would be the total number of items in your database, * without filtering. We'll need this later, so you should always include it * in your own package classes. */ $total_items = 0; if (isset($data)) { $total_items = count($data); } /** * The WP_List_Table class does not handle pagination for us, so we need * to ensure that the data is trimmed to only the current page. There needs * to be data here... */ if ($total_items > 0) { $data = array_slice($data, ($current_page - 1) * $per_page, $per_page); } /** * REQUIRED. Now we can add our *sorted* data to the items property, where * it can be used by the rest of the class. */ if (isset($data)) { $this->items = $data; } /** * REQUIRED. We also have to register our pagination options & calculations. */ $this->set_pagination_args(array('total_items' => $total_items, 'per_page' => $per_page, 'total_pages' => ceil($total_items / $per_page))); }
function lti_get_share_enabled_state($key) { global $wpdb; $consumer = new LTI_Tool_Consumer($_SESSION[LTI_SESSION_PREFIX . 'key'], array($wpdb->base_prefix)); $resource = new LTI_Resource_Link($consumer, $_SESSION[LTI_SESSION_PREFIX . 'resourceid']); $shares = $resource->getShares(); foreach ($shares as $share) { if ($share->consumer_key == $key) { $reply = is_null($share->approved) ? FALSE : TRUE; return $reply; } } return FALSE; }