예제 #1
0
 public static function load_items_callback()
 {
     // 		global $wpdb; // this is how you get access to the database
     $items = array();
     $itemids = get_user_meta(get_current_user_id(), 'itembasket', true);
     if ($itemids == null) {
         $itemids = array();
     }
     foreach ($itemids as $item_id) {
         $post = get_post($item_id);
         if ($post == null) {
             continue;
         }
         $row = array('ID' => $item_id);
         if ($post->post_type == 'itemsc') {
             $item = new EAL_ItemSC();
         }
         if ($post->post_type == 'itemmc') {
             $item = new EAL_ItemMC();
         }
         $row['terms'] = array();
         foreach (wp_get_post_terms($item_id, 'topic') as $term) {
             $termhier = array($term->name);
             $parentId = $term->parent;
             while ($parentId > 0) {
                 $parentTerm = get_term($parentId, 'topic');
                 $termhier = array_merge(array($parentTerm->name), $termhier);
                 $parentId = $parentTerm->parent;
             }
             $row['terms'] = array_merge($row['terms'], array($termhier));
         }
         $item->loadById($item_id);
         $row['type'] = $item->type;
         $row['dim'] = '';
         $row['level'] = 0;
         foreach (array('FW', 'PW', 'KW') as $dim) {
             if ($item->level[$dim] > 0) {
                 $row['dim'] = $dim;
                 $row['level'] = $item->level[$dim];
             }
         }
         $row['points'] = $item->getPoints();
         array_push($items, $row);
     }
     $whatever = intval($_POST['whatever']);
     $whatever += 10;
     wp_send_json($items);
     // 		echo $whatever;
     // 		wp_die(); // this is required to terminate immediately and return a proper response
 }
예제 #2
0
 function prepare_items()
 {
     $this->process_bulk_action();
     $columns = $this->get_columns();
     $hidden = array();
     $sortable = $this->get_sortable_columns();
     $this->_column_headers = array($columns, $hidden, $sortable);
     // 		usort( $this->example_data, array( &$this, 'usort_reorder' ) );
     // 		$this->items = $this->example_data;
     $this->items = array();
     $itemids = get_user_meta(get_current_user_id(), 'itembasket', true);
     if ($itemids == null) {
         $itemids = array();
     }
     foreach ($itemids as $item_id) {
         $post = get_post($item_id);
         if ($post == null) {
             continue;
         }
         $row = array('ID' => $item_id);
         if ($post->post_type == 'itemsc') {
             $item = new EAL_ItemSC();
             $row['type'] = 'Single Choice';
         }
         if ($post->post_type == 'itemmc') {
             $item = new EAL_ItemMC();
             $row['type'] = 'Mutliple Choice';
         }
         $item->loadById($item_id);
         $row['title'] = $item->title;
         $row['FW'] = $item->level['FW'] > 0 ? EAL_Item::$level_label[$item->level['FW'] - 1] : '';
         $row['KW'] = $item->level['KW'] > 0 ? EAL_Item::$level_label[$item->level['KW'] - 1] : '';
         $row['PW'] = $item->level['PW'] > 0 ? EAL_Item::$level_label[$item->level['PW'] - 1] : '';
         $row['points'] = $item->getPoints();
         array_push($this->items, $row);
     }
 }