예제 #1
0
 public static function load_items_callback()
 {
     // 		global $wpdb; // this is how you get access to the database
     $items = PAG_Basket::loadAllItemsFromBasket();
     // 		echo "<script> console.log('dimy0', 'test'); </script>";
     // 		print ("<script> console.log('dimy0', '" . $_POST['dimy0'] . "'); </script>");
     $_SESSION["dim_names"] = array(array($_POST['dimx0'], $_POST['dimx1'], $_POST['dimx2']), array($_POST['dimy0'], $_POST['dimy1'], $_POST['dimy2']));
     // FOR DEBUG
     $dim_names = array(array($_POST['dimx0'], $_POST['dimx1'], $_POST['dimx2']), array($_POST['dimy0'], $_POST['dimy1'], $_POST['dimy2']));
     // 		$dim_names = array(array ('dim', null, null), array('type', null, null));
     // 		$dim_values = array(array(), array());
     // 		foreach ([0,1] as $x) {
     // 			foreach ([0,1,2] as $y) {
     // 				$dim_values[$x][$y] = PAG_Explorer::getDimXValues($dim_names[$x][$y]);
     // 			}
     // 		}
     $noOfDimY = 3;
     if ($_POST['dimy2'] == "none" || $_POST['dimy2'] == null) {
         $noOfDimY = 2;
     }
     if ($_POST['dimy1'] == "none" || $_POST['dimy1'] == null) {
         $noOfDimY = 1;
     }
     if ($_POST['dimy0'] == "none" || $_POST['dimy0'] == null) {
         $noOfDimY = 0;
     }
     // group items by all dimensions (3+3)
     $res = array();
     $createHeader = true;
     $lines = array();
     $lines_href = array();
     $row_span = array(array(), array());
     foreach (PAG_Explorer::groupBy($dim_names[1][0], $items, null, false) as $k1 => $items1) {
         $level1_first = true;
         $level1_span = 0;
         foreach (PAG_Explorer::groupBy($dim_names[1][1], $items1, $k1, false) as $k2 => $items2) {
             $level2_first = true;
             $level2_span = 0;
             foreach (PAG_Explorer::groupBy($dim_names[1][2], $items2, $k2, false) as $k3 => $items3) {
                 if (createHeader) {
                     $header_values = array([], [], []);
                     $header_sizes = array([], [], []);
                 }
                 $level1_span++;
                 $level2_span++;
                 $line = array($level1_first ? PAG_Explorer::getDimensionLabel($dim_names[1][0], $k1) : "SPAN", $level2_first ? PAG_Explorer::getDimensionLabel($dim_names[1][1], $k2) : "SPAN", PAG_Explorer::getDimensionLabel($dim_names[1][2], $k3));
                 $line_href = array('', '', '');
                 $level1_first = false;
                 $level2_first = false;
                 foreach (PAG_Explorer::groupBy($dim_names[0][0], $items3, null, true) as $k4 => $items4) {
                     if (createHeader) {
                         array_push($header_values[0], PAG_Explorer::getDimensionLabel($dim_names[0][0], $k4));
                         //  (($dim_names[0][0]=="none") || ($dim_names[0][0]==null)) ? "" : $k4);
                         $count_k4 = 0;
                     }
                     foreach (PAG_Explorer::groupBy($dim_names[0][1], $items4, $k4, true) as $k5 => $items5) {
                         if (createHeader) {
                             array_push($header_values[1], PAG_Explorer::getDimensionLabel($dim_names[0][1], $k5));
                             //  (($dim_names[0][1]=="none") || ($dim_names[0][1]==null)) ? "" : $k5);
                             $count_k5 = 0;
                         }
                         foreach (PAG_Explorer::groupBy($dim_names[0][2], $items5, $k5, true) as $k6 => $items6) {
                             $res[$k1][$k2][$k3][$k4][$k5][$k6] = $items6;
                             $href = '';
                             foreach ($items6 as $i) {
                                 $href .= $href == "" ? $i->id : "," . $i->id;
                             }
                             array_push($line, count($items6));
                             array_push($line_href, $href);
                             if (createHeader) {
                                 array_push($header_values[2], PAG_Explorer::getDimensionLabel($dim_names[0][2], $k6));
                                 //  (($dim_names[0][2]=="none") || ($dim_names[0][2]==null)) ? "" : $k6);
                                 array_push($header_sizes[2], 1);
                                 $count_k4++;
                                 $count_k5++;
                             }
                         }
                         if (createHeader) {
                             array_push($header_sizes[1], $count_k5);
                         }
                     }
                     if (createHeader) {
                         array_push($header_sizes[0], $count_k4);
                     }
                 }
                 $createHeader = false;
                 array_push($lines, $line);
                 array_push($lines_href, $line_href);
             }
             array_push($row_span[1], $level2_span);
         }
         array_push($row_span[0], $level1_span);
     }
     // no nested arrays for javascript --> expand to header1, header2 etc.
     wp_send_json(array('header_values_0' => $header_values[0], 'header_values_1' => $header_values[1], 'header_values_2' => $header_values[2], 'header_sizes_0' => $header_sizes[0], 'header_sizes_1' => $header_sizes[1], 'header_sizes_2' => $header_sizes[2], 'row_span_0' => $row_span[0], 'row_span_1' => $row_span[1], 'noOfDimY' => $noOfDimY, 'lines' => $lines, 'lines_href' => $lines_href));
 }
예제 #2
0
 public static function createPageView()
 {
     $itemids = array();
     /* try to get learning outcomes */
     $post_label = "Learning Outcome";
     if ($_REQUEST['learnoutid'] != null) {
         $itemids = [$_REQUEST['learnoutid']];
     }
     if ($_REQUEST['learnoutids'] != null) {
         if (is_array($_REQUEST['learnoutids'])) {
             $itemids = $_REQUEST['learnoutids'];
         }
         if (is_string($_REQUEST['learnoutids'])) {
             $itemids = explode(",", $_REQUEST["learnoutids"]);
         }
     }
     if (count($itemids) == 0) {
         // no learning outcomes found --> get reviews
         $post_label = "Review";
         if ($_REQUEST['reviewid'] != null) {
             $itemids = [$_REQUEST['reviewid']];
         }
         if ($_REQUEST['reviewids'] != null) {
             if (is_array($_REQUEST['reviewids'])) {
                 $itemids = $_REQUEST['reviewids'];
             }
             if (is_string($_REQUEST['reviewids'])) {
                 $itemids = explode(",", $_REQUEST["reviewids"]);
             }
         }
     }
     if (count($itemids) == 0) {
         // nothing found --> get items
         $post_label = "Item";
         if ($_REQUEST['itemid'] != null) {
             $itemids = [$_REQUEST['itemid']];
         }
         if ($_REQUEST['itemids'] != null) {
             if (is_array($_REQUEST['itemids'])) {
                 $itemids = $_REQUEST['itemids'];
             }
             if (is_string($_REQUEST['itemids'])) {
                 $itemids = explode(",", $_REQUEST["itemids"]);
             }
         }
         // fallback: get items from basket
         if (count($itemids) == 0) {
             $itemids = RoleTaxonomy::getCurrentBasket();
         }
         // get_user_meta(get_current_user_id(), 'itembasket', true);
     }
     $html_list = "";
     $html_select = "<form><select onChange='for (x=0; x<this.form.nextSibling.childNodes.length; x++) {  this.form.nextSibling.childNodes[x].style.display = ((this.value<0) || (this.value==x)) ? \"block\" :  \"none\"; }'>";
     $html_select .= sprintf('<option value="-1" selected>[All %1$d %2$ss]</option>', count($itemids), $post_label);
     $count = 0;
     $items = array();
     foreach ($itemids as $item_id) {
         $post = get_post($item_id);
         if ($post == null) {
             continue;
         }
         $item = null;
         if ($post->post_type == 'itemsc') {
             $item = new EAL_ItemSC();
         }
         if ($post->post_type == 'itemmc') {
             $item = new EAL_ItemMC();
         }
         if ($post->post_type == 'learnout') {
             $item = new EAL_LearnOut();
         }
         if ($post->post_type == 'review') {
             $item = new EAL_Review();
         }
         if ($item != null) {
             $item->loadById($item_id);
             $html_select .= sprintf("<option value='%d'>%s</option>", $count, $post->post_type == 'review' ? $item->getItem()->title : $item->title);
             $html_list .= sprintf("<div style='margin-top:2em;'><hr/>%s<br style='clear:both;'/></div>", substr($post->post_type, 0, 4) == "item" ? CPT_Item::getHTML_Item($item, FALSE) : ($post->post_type == 'learnout' ? CPT_LearnOut::getHTML_LearnOut($item) : CPT_Review::getHTML_Review($item)));
             $count++;
             array_push($items, $item);
         }
     }
     $html_select .= "</select>&nbsp;&nbsp;&nbsp;<input type='checkbox' checked \r\n\t\t\tonChange='for (x=0; x<this.form.nextSibling.childNodes.length; x++) { this.form.nextSibling.childNodes[x].querySelector(\"#postbox-container-1\").style.display = (this.checked==true) ? \"block\" :  \"none\"; }'/> Show Metadata</form>";
     if ($post_label == "Item") {
         $html_info = sprintf("<form  style='margin-top:5em' enctype='multipart/form-data' action='admin.php?page=view&download=1&itemids=%s' method='post'><table class='form-table'><tbody'>", implode(",", $itemids));
         $html_info .= sprintf("<tr><th style='padding-top:0px; padding-bottom:0px;'><label>%s</label></th>", "Number of Items");
         $html_info .= sprintf("<td style='padding-top:0px; padding-bottom:0px;'>");
         $html_info .= sprintf("<input style='width:5em' type='number' value='%d' readonly/>", count($items));
         $html_info .= sprintf("</td></tr>");
         // Min / Max for all categories
         $categories = array("type", "dim", "level", "topic1");
         foreach ($categories as $category) {
             $html_info .= sprintf("<tr><th style='padding-bottom:0.5em;'><label>%s</label></th></tr>", EAL_Item::$category_label[$category]);
             foreach (PAG_Explorer::groupBy($category, $items, NULL, true) as $catval => $catitems) {
                 $html_info .= sprintf("<tr><td style='padding-top:0px; padding-bottom:0px;'><label>%s</label></td>", $category == "topic1" ? $catval : EAL_Item::$category_value_label[$category][$catval]);
                 $html_info .= sprintf("<td style='padding-top:0px; padding-bottom:0px;'>");
                 $html_info .= sprintf("<input style='width:5em' type='number' value='%d' readonly/>", count($catitems));
                 $html_info .= sprintf("</td></tr>");
             }
         }
         $html_info .= sprintf("<tr><th><button type='submit' name='action' value='download'>Download</button></th><tr>");
         $html_info .= sprintf("</tbody></table></form></div>");
     }
     printf('<div class="wrap"><h1>%1$s Viewer</h1>', $post_label);
     if ($_REQUEST['download'] == '1') {
         $ilias = new EXP_Ilias();
         $link = $ilias->generateExport($itemids);
         printf("<h2><a href='%s'>Download</a></h2>", $link);
     }
     if (count($itemids) > 1 || count($itemids) == 1) {
         print $html_select;
         print "<div style='margin-top:2em'>{$html_list}{$html_info}</div>";
     } else {
         print "<div style='margin-top:2em'>{$html_list}</div>";
     }
     print "</div>";
 }
예제 #3
0
 public static function createPage()
 {
     $items = PAG_Basket::loadAllItemsFromBasket();
     $html = sprintf("<form  enctype='multipart/form-data' action='admin.php?page=generator' method='post'><table class='form-table'><tbody'>");
     $html .= sprintf("<tr><th style='padding-top:0px; padding-bottom:0px;'><label>%s</label></th>", "Number of Items");
     $html .= PAG_Generator::minMaxField("number", count($items));
     $html .= sprintf("</tr>");
     $html .= sprintf("<tr><td style='vertical-align:top; padding-top:0px; padding-bottom:0px;'><label>%s</label></td>", "Overlap");
     $html .= PAG_Generator::minMaxField("overlap", count($items));
     $html .= sprintf("</tr>");
     $html .= sprintf("<tr><td style='vertical-align:top; padding-top:0px; padding-bottom:0px;'><button type='button' onclick='\r\n\t\t\t\t\r\n\t\t\t\tif (this.innerText == \"Select ...\") {\r\n\t\t\t\t\tthis.innerText = \"Close\";\r\n\t\t\t\t\tthis.parentNode.nextSibling.firstChild.style.display=\"block\";\r\n\t\t\t\t} else {\r\n\t\t\t\t\tthis.innerText = \"Select ...\";\r\n\t\t\t\t\tthis.parentNode.nextSibling.firstChild.style.display=\"none\";\r\n\t\t\t\t}\r\n\t\t\t\t\r\n\t\t\t\t'>Select ...</button></td>");
     $html .= "<td><div style='display:none'>";
     foreach ($items as $i) {
         $html .= sprintf("<input type='checkbox' name='overlap_items[]' value='%d'><label style='vertical-align:top'>%s</label><br/>", $i->id, $i->title);
     }
     $html .= sprintf("</div></td></tr>");
     // Min / Max for all categories
     $categories = array("type", "dim", "level", "topic1");
     foreach ($categories as $category) {
         $html .= sprintf("<tr><th style='padding-bottom:0.5em;'><label>%s</label></th></tr>", EAL_Item::$category_label[$category]);
         foreach (PAG_Explorer::groupBy($category, $items, NULL, true) as $catval => $catitems) {
             $html .= sprintf("<tr><td style='padding-top:0px; padding-bottom:0px;'><label>%s</label></td>", $category == "topic1" ? $catval : EAL_Item::$category_value_label[$category][$catval]);
             $html .= PAG_Generator::minMaxField($category . "_" . $catval, count($catitems));
             $html .= sprintf("</tr>");
         }
     }
     $html .= sprintf("<tr><th><button type='submit' name='action' value='generate'>Generate</button></th><tr>");
     $html .= sprintf("</tbody></table></form></div>");
     // (re-)generate pools
     if ($_REQUEST['action'] == 'generate') {
         $pool = new PAG_Generator($items, array($_SESSION['min_number'], $_SESSION['min_type_itemsc'], $_SESSION['min_type_itemmc'], $_SESSION['min_dim_FW'], $_SESSION['min_dim_KW'], $_SESSION['min_dim_PW'], $_SESSION['min_level_1'], $_SESSION['min_level_2'], $_SESSION['min_level_3'], $_SESSION['min_level_4'], $_SESSION['min_level_5'], $_SESSION['min_level_6']), array($_SESSION['max_number'], $_SESSION['max_type_itemsc'], $_SESSION['max_type_itemmc'], $_SESSION['max_dim_FW'], $_SESSION['max_dim_KW'], $_SESSION['max_dim_PW'], $_SESSION['max_level_1'], $_SESSION['max_level_2'], $_SESSION['max_level_3'], $_SESSION['max_level_4'], $_SESSION['max_level_5'], $_SESSION['max_level_6']), array($_SESSION['min_overlap'], $_SESSION['max_overlap']));
         $_SESSION['generated_pools'] = $pool->generatedPools;
     }
     print "<div class='wrap'>";
     print "<h1>Task Pool Generator</h1><br/>";
     print $html;
     // show pools (from last generation; stored in Session variable)
     if (isset($_SESSION['generated_pools'])) {
         // 			print_r ($_SESSION['generated_pools']);
         print "<br/><h2>Generated Task Pools</h2>";
         printf("<table cellpadding='10px' class='widefat fixed' style='table-layout:fixed; width:%dem; background-color:rgba(0, 0, 0, 0);'>", 6 + 2 * count($items));
         print "<col width='6em;' />";
         foreach ($items as $item) {
             print "<col width='2em;' />";
         }
         foreach ($_SESSION['generated_pools'] as $pool) {
             print "<tr valign='middle'>";
             $s = "View";
             $href = "admin.php?page=view&itemids=" . join(",", $pool);
             printf("<td style='overflow: hidden; padding:0px; padding-bottom:0.5em; padding-top:0.5em; padding-left:1em' ><a href='%s' class='button'>View</a></td>", $href);
             // http://localhost/wordpress/wp-admin/admin.php?page=view&itemids=458,307,307,106
             foreach ($items as $item) {
                 $symbol = "";
                 $link = "";
                 if (in_array($item->id, $pool)) {
                     $link = sprintf("onClick='document.location.href=\"admin.php?page=view&itemid=%s\";'", $item->id);
                     if ($item->type == "itemsc") {
                         $symbol = "<span class='dashicons dashicons-marker'></span>";
                     }
                     if ($item->type == "itemmc") {
                         $symbol = "<span class='dashicons dashicons-forms'></span>";
                     }
                 }
                 printf("<td %s valign='bottom' style='overflow: hidden; padding:0px; padding-top:0.83em;' >%s</td>", $link, $symbol);
             }
             print "</tr>";
         }
         print "</table>";
     }
 }