public static function getListOfLearningOutcomes($learnout_id, $namePrefix = "") { global $wpdb; $sqlres = $wpdb->get_results("\r\n\t\t\t\tSELECT L.id, L.title\r\n\t\t\t\tFROM {$wpdb->prefix}eal_learnout L\r\n\t\t\t\tJOIN {$wpdb->prefix}posts P\r\n\t\t\t\tON (L.id = P.id)\r\n\t\t\t\tWHERE P.post_status = 'publish'\r\n\t\t\t\tAND L.domain = '" . RoleTaxonomy::getCurrentRoleDomain()["name"] . "'\r\n\t\t\t\tORDER BY L.title\r\n\t\t\t\t"); $html .= "<select align='right' name='{$namePrefix}learnout_id'>"; $html .= "<option value='0'" . ($learnout_id == 0 ? " selected" : "") . ">None</option>"; foreach ($sqlres as $pos => $sqlrow) { $html .= "<option value='{$sqlrow->id}'" . ($learnout_id == $sqlrow->id ? " selected" : "") . ">{$sqlrow->title}</option>"; } $html .= "</select>"; return $html; }
private static function getValuesByKey($name, $item, $parent) { if ($name == null || $name == "none") { return [0]; } if ($name == "type") { return [$item->type]; } if ($name == "difficulty") { if (!isset($item->difficulty)) { return []; } return [$item->difficulty]; } if ($name == "dim" || $name == "level") { $res = array(); foreach (array('FW', 'PW', 'KW') as $dim) { if ($item->level[$dim] > 0) { if ($name == "dim") { array_push($res, $dim); } // return [$dim]; if ($name == "level") { array_push($res, $item->level[$dim]); } // return [$item->level[$dim]]; } } return $res; } if ($name == "topic1" || $name == "topic2") { $res = array(); foreach (wp_get_post_terms($item->id, RoleTaxonomy::getCurrentRoleDomain()["name"]) as $term) { $termhier = array($term->name); $parentId = $term->parent; while ($parentId > 0) { $parentTerm = get_term($parentId, RoleTaxonomy::getCurrentRoleDomain()["name"]); $termhier = array_merge(array($parentTerm->name), $termhier); $parentId = $parentTerm->parent; } if ($name == "topic1" && !in_array($termhier[0], $res)) { array_push($res, $termhier[0]); } // for topic2: check if available AND if parent=topic1 is the same if ($name == "topic2" && count($termhier) > 1 && $termhier[0] == $parent && !in_array($termhier[1], $res)) { array_push($res, $termhier[1]); } } return $res; } return []; }
public static function loadAllItemsFromBasket() { // load all items from basket $items = array(); $itemids = RoleTaxonomy::getCurrentBasket(); // get_user_meta(get_current_user_id(), 'itembasket', true); if ($itemids == null) { $itemids = array(); } $itemids_new = 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 ($item == null) { continue; } $item->loadById($item_id); if (RoleTaxonomy::getCurrentRoleDomain()["name"] != "" && $item->domain != RoleTaxonomy::getCurrentRoleDomain()["name"]) { continue; } array_push($items, $item); array_push($itemids_new, $item_id); } RoleTaxonomy::setCurrentBasket($itemids_new); // update_user_meta (get_current_user_id(), 'itembasket', $itemids_new); return $items; }
public function WPCB_restrict_manage_posts() { global $typenow, $wp_query; // an array of all the taxonomyies you want to display. Use the taxonomy name or slug $taxonomies = array(RoleTaxonomy::getCurrentRoleDomain()["name"]); // must set this to the post type you want the filter(s) displayed on if ($typenow == $this->type) { if ($this->type == "item" || $this->type == "itembasket") { $selected = isset($_REQUEST["item_type"]) ? $_REQUEST["item_type"] : "0"; printf('<select class="postform" name="item_type">'); printf('<option value="0" %1$s>All Item Types</option>', $selected == "0" ? "selected" : ""); printf('<option value="itemsc" %1$s>Single Choice</option>', $selected == "itemsc" ? "selected" : ""); printf('<option value="itemmc" %1$s>Multiple Choice</option>', $selected == "itemmc" ? "selected" : ""); printf('</select>'); $selected = isset($_REQUEST["post_status"]) ? $_REQUEST["post_status"] : "0"; printf('<select class="postform" name="post_status">'); printf('<option value="0" %1$s>All Item Statuses</option>', $selected == "0" ? "selected" : ""); printf('<option value="draft" %1$s>Draft</option>', $selected == "draft" ? "selected" : ""); printf('<option value="pending" %1$s>Pending</option>', $selected == "pending" ? "selected" : ""); printf('<option value="publish" %1$s>Published</option>', $selected == "publish" ? "selected" : ""); printf('</select>'); } wp_dropdown_categories(array('show_option_all' => __("Show All Topics"), 'taxonomy' => RoleTaxonomy::getCurrentRoleDomain()["name"], 'name' => 'taxonomy', 'orderby' => 'name', 'selected' => isset($wp_query->query['taxonomy']) ? $wp_query->query['taxonomy'] : '', 'hierarchical' => true, 'depth' => 0, 'value_field' => 'term_id', 'show_count' => true, 'hide_empty' => false)); foreach (EAL_Item::$level_type as $lt) { $selected = isset($_REQUEST["level_{$lt}"]) && $_REQUEST["level_{$lt}"] != '0' ? $_REQUEST["level_{$lt}"] : 0; echo "<select class='postform' name='level_{$lt}'>"; echo "<option value='0'>All {$lt}</option>"; foreach (array(1, 2, 3, 4, 5, 6) as $v) { echo "<option value='{$v}' " . ($v == $selected ? 'selected' : '') . ">" . EAL_Item::$level_label[$v - 1] . "</option>"; } echo "</select>"; } if (substr($this->type, 0, 4) == 'item') { $flag == 0; if (isset($_REQUEST["flag"])) { $flag = $_REQUEST["flag"]; } printf("<select class='postform' name='flag'>"); printf("<option value='0' %s>All Flags</option>", $flag == 0 ? "selected" : ""); printf("<option value='1' %s>Marked</option>", $flag == 1 ? "selected" : ""); printf("<option value='2' %s>Unmarked</option>", $flag == 2 ? "selected" : ""); printf("</select>"); } } }
function my_new_toolbar_item($wp_admin_bar) { $args = array('id' => 'eal_logo', 'title' => '<div style="width:10em"><a href="' . site_url() . '/wp-admin/"><img style="display:block; margin-top:1em; margin-left:-1em; width:11em" src="' . plugin_dir_url(__FILE__) . 'Logo_EAs.LiT.png"></a></div>'); $wp_admin_bar->add_node($args); // $wp_admin_bar->remove_menu ('user-actions'); $wp_admin_bar->remove_menu('updates'); $wp_admin_bar->remove_menu('comments'); $wp_admin_bar->remove_menu('new-content'); $wp_admin_bar->remove_menu('wp-logo'); $wp_admin_bar->remove_menu('site-name'); // $title = "<div>"; // $title .= sprintf ("<div class='dashicons-before %s' style='display:inline'> ", (RoleTaxonomy::getCurrentRoleType()=="author") ? "dashicons-admin-users" : "dashicons-groups"); $title .= sprintf("%s %s", site_url(), RoleTaxonomy::getCurrentRoleDomain()["label"]); // $title .= sprintf ("<a class='ab-item' href='%s/wp-admin/profile.php'>%s</a></div>", site_url(), RoleTaxonomy::getCurrentRoleDomain()["label"]); // $wp_admin_bar->add_menu (array ("id" => "eal_currentRole", "title" => $title, "meta" => array ("class" => sprintf ("dashicons-before %s", (RoleTaxonomy::getCurrentRoleType()=="author") ? "dashicons-admin-users" : "dashicons-groups")))); $wp_admin_bar->add_menu(array("id" => "eal_currentRole", "href" => sprintf('%s/wp-admin/profile.php', site_url()), "title" => sprintf("<div class='wp-menu-image dashicons-before %s'> %s</div>", RoleTaxonomy::getCurrentRoleType() == "author" ? "dashicons-admin-users" : "dashicons-groups", RoleTaxonomy::getCurrentRoleDomain()["label"]))); }
public function WPCB_posts_where($where, $checktype = TRUE) { global $wp_query, $wpdb; if ($wp_query->query["post_type"] == $this->type || !$checktype) { // if all items are considered --> consider all type starting with "item" if ($this->type == "item") { $where = str_replace("{$wpdb->posts}.post_type = 'item'", "{$wpdb->posts}.post_type LIKE 'item%'", $where); } // if current role type = author --> show all items except drafts from others if (RoleTaxonomy::getCurrentRoleType() == "author") { $where .= "AND ({$wpdb->posts}.post_status != 'draft' OR {$wpdb->posts}.post_author = " . get_current_user_id() . ")"; } if (isset($_REQUEST["item_type"]) && $_REQUEST['item_type'] != "0") { $where .= " AND I.type = '{$_REQUEST['item_type']}'"; } if (isset($_REQUEST["post_status"]) && $_REQUEST['post_status'] != "0") { $where .= " AND {$wpdb->posts}.post_status = '" . $_REQUEST['post_status'] . "'"; } if (isset($_REQUEST["learnout_id"])) { $where .= " AND L.id = {$_REQUEST['learnout_id']}"; } if (isset($_REQUEST['item_author'])) { $where .= " AND {$wpdb->posts}.post_author \t\t\t= " . $_REQUEST['item_author']; } if (isset($_REQUEST['item_points'])) { $where .= " AND I.points \t= " . $_REQUEST['item_points']; } if (isset($_REQUEST['level_FW']) && $_REQUEST['level_FW'] > 0) { $where .= " AND I.level_FW \t= " . $_REQUEST['level_FW']; } if (isset($_REQUEST['level_PW']) && $_REQUEST['level_PW'] > 0) { $where .= " AND I.level_PW \t= " . $_REQUEST['level_PW']; } if (isset($_REQUEST['level_KW']) && $_REQUEST['level_KW'] > 0) { $where .= " AND I.level_KW\t= " . $_REQUEST['level_KW']; } if (isset($_REQUEST['learnout_id'])) { $where .= " AND I.learnout_id = " . $_REQUEST['learnout_id']; } if (isset($_REQUEST['flag'])) { if ($_REQUEST['flag'] == 1) { $where .= " AND I.flag = 1"; } if ($_REQUEST['flag'] == 2) { $where .= " AND (I.flag != 1 OR I.flag IS NULL)"; } } if (isset($_REQUEST['taxonomy']) && $_REQUEST['taxonomy'] > 0) { $children = get_term_children($_REQUEST['taxonomy'], RoleTaxonomy::getCurrentRoleDomain()["name"]); array_push($children, $_REQUEST['taxonomy']); $where .= sprintf(' AND %1$s.ID IN (SELECT TR.object_id FROM %2$s TT JOIN %3$s TR ON (TT.term_taxonomy_id = TR.term_taxonomy_id) WHERE TT.term_id IN ( %4$s ))', $wpdb->posts, $wpdb->term_taxonomy, $wpdb->term_relationships, implode(', ', $children)); } if ($this->type == "itembasket") { $where = str_replace("{$wpdb->posts}.post_type = 'itembasket'", "{$wpdb->posts}.post_type LIKE 'item%'", $where); $basket = RoleTaxonomy::getCurrentBasket(); // get_user_meta(get_current_user_id(), 'itembasket', true); if (is_array($basket) && count($basket) > 0) { $where .= " AND I.ID IN (" . implode(",", $basket) . ") "; } else { $where .= " AND (1=2) "; } } } return $where; }
public function load() { global $post; if (get_post_status($post->ID) == 'auto-draft') { /* Create new item */ $this->id = $post->ID; $this->title = ''; $this->description = ''; $this->question = ''; $this->level["FW"] = 0; $this->level["KW"] = 0; $this->level["PW"] = 0; $this->learnout_id = isset($_POST['learnout_id']) ? $_POST['learnout_id'] : (isset($_GET['learnout_id']) ? $_GET['learnout_id'] : null); $this->learnout = null; $this->difficulty = null; $this->domain = RoleTaxonomy::getCurrentRoleDomain()["name"]; $this->note = ""; $this->flag = 0; } else { $this->loadById($post->ID); } }
public static function createPage() { if ($_POST['action'] == 'Upload') { // checks for errors and that file is uploaded if ($_FILES['uploadedfile']['error'] == UPLOAD_ERR_OK && is_uploaded_file($_FILES['uploadedfile']['tmp_name'])) { $level = -1; $lastParent = array(-1 => $_POST['topicroot']); foreach (file($_FILES['uploadedfile']['tmp_name'], FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) { $identSize = strlen($line) - strlen(ltrim($line)); if ($identSize > $level) { $level++; } if ($identSize < $level) { $level = max(0, $identSize); } $x = wp_insert_term(utf8_encode(trim($line)), RoleTaxonomy::getCurrentRoleDomain()["name"], array('parent' => $lastParent[$level - 1])); $lastParent[$level] = $x instanceof WP_Error ? $x->error_data['term_exists'] : $x['term_id']; } } } ?> <div class="wrap"> <h1>Import Taxonomy Terms</h1> <h2>Upload Terms</h2> <form enctype="multipart/form-data" action="admin.php?page=import-taxonomy" method="post"> <table class="form-table"> <tbody> <tr class="user-first-name-wrap"> <th><label>File</label></th> <td><input class="menu-name regular-text menu-item-textbox input-with-default-title" name="uploadedfile" type="file" size="30" accept="text/*"></td> </tr> <tr class="user-first-name-wrap"> <th><label>Parent</label></th> <td> <?php wp_dropdown_categories(array('show_option_none' => __("None"), 'option_none_value' => 0, 'taxonomy' => RoleTaxonomy::getCurrentRoleDomain()["name"], 'name' => 'topicroot', 'value_field' => 'id', 'orderby' => 'name', 'selected' => '', 'hierarchical' => true, 'depth' => 0, 'show_count' => false, 'hide_empty' => false)); ?> </td> </tr> <tr> <th> <input type="submit" name="action" class="button button-primary" value="Upload"> </th> <td></td> </tr> </tbody> </table> </form> <h2>Download Topic Terms</h2> <form action="options.php" method="post" name="options"> <table class="form-table"> <tbody> <tr class="user-first-name-wrap"> <th><label>Parent</label></th> <td> <?php wp_dropdown_categories(array('show_option_none' => __("None"), 'option_none_value' => 0, 'taxonomy' => 'topic', 'name' => 'topicroot', 'value_field' => 'id', 'orderby' => 'name', 'selected' => '', 'hierarchical' => true, 'depth' => 0, 'show_count' => false, 'hide_empty' => false)); ?> </td> </tr> <tr> <th><input type="submit" name="action" class="button button-primary" value="Download"></th> <td></td> </tr> </tbody> </table> </form> </div> <?php }
public function WPCB_posts_where($where, $checktype = TRUE) { global $wp_query, $wpdb; if ($wp_query->query["post_type"] == $this->type || !$checktype) { if (isset($_REQUEST['learnout_author'])) { $where .= " AND {$wpdb->posts}.post_author \t= " . $_REQUEST['learnout_author']; } if (isset($_REQUEST['level_FW']) && $_REQUEST['level_FW'] > 0) { $where .= " AND L.level_FW \t= " . $_REQUEST['level_FW']; } if (isset($_REQUEST['level_PW']) && $_REQUEST['level_PW'] > 0) { $where .= " AND L.level_PW \t= " . $_REQUEST['level_PW']; } if (isset($_REQUEST['level_KW']) && $_REQUEST['level_KW'] > 0) { $where .= " AND L.level_KW\t= " . $_REQUEST['level_KW']; } if (isset($_REQUEST['taxonomy']) && $_REQUEST['taxonomy'] > 0) { $children = get_term_children($_REQUEST['taxonomy'], RoleTaxonomy::getCurrentRoleDomain()["name"]); array_push($children, $_REQUEST['taxonomy']); $where .= sprintf(' AND %1$s.ID IN (SELECT TR.object_id FROM %2$s TT JOIN %3$s TR ON (TT.term_taxonomy_id = TR.term_taxonomy_id) WHERE TT.term_id IN ( %4$s ))', $wpdb->posts, $wpdb->term_taxonomy, $wpdb->term_relationships, implode(', ', $children)); } } return $where; }
/** * * @param DOMDocument $doc * @param $itemids: array (qref -> item_id) ... if item_id is available * @return array (qref -> item) return the item object for each qref (if the item is already in the database, it has been loaded and updated with the values) */ public function parseQTI(DOMDocument $doc, $itemids) { $items = array(); $root = $doc->documentElement; $xpath = new DOMXPath($doc); foreach ($xpath->evaluate("//item", $doc->documentElement) as $itemXML) { // determine (==item_id) if available and item type $item_id = $itemids[$itemXML->getAttribute("ident")]; $item_type = ""; foreach ($xpath->evaluate(".//qtimetadatafield[./fieldlabel='QUESTIONTYPE']/fieldentry", $itemXML) as $md) { if ($md->nodeValue == "SINGLE CHOICE QUESTION") { $item_type = "itemsc"; } if ($md->nodeValue == "MULTIPLE CHOICE QUESTION") { $item_type = "itemmc"; } } // TODO: Handling if item type not found if ($item_type == "") { unset($itemids[$itemXML->getAttribute("ident")]); continue; } // initialize item if ($item_type == "itemsc") { $item = new EAL_ItemSC(); } if ($item_type == "itemmc") { $item = new EAL_ItemMC(); } if ($item_id != "") { $item->loadById($item_id); } // get title and description + question $item->domain = RoleTaxonomy::getCurrentRoleDomain()["name"]; $item->title = $itemXML->getAttribute("title"); $descques = $xpath->evaluate("./presentation/flow/material/mattext/text()", $itemXML)[0]->wholeText; $descques = preg_replace_callback('|(<img[^>]+)src=["\']([^"]*)["\']|', function ($match) { /* if img is stored inline (src="data:image/png;base64,iVBOR....") --> do nothing */ if (strtolower(substr($match[2], 0, 5)) == 'data:') { return $match[1] . "src='" . $match[2] . "'"; } /* locate file */ $entries = scandir("{$this->dir}/{$this->name}/objects/{$match[2]}/"); $entry = $entries[count($entries) - 1]; /* generate unique filename for img */ $count = 0; $path = wp_upload_dir()["path"]; $filename = $match[2]; while (file_exists($path . "/" . $filename . "_" . $count)) { $count++; } $from = "{$this->dir}/{$this->name}/objects/{$entry}"; $to = $path . "/" . $filename . "_" . $count; copy("{$this->dir}/{$this->name}/objects/{$match[2]}/{$entry}", $path . "/" . $filename . "_" . $count); return $match[1] . "src='" . wp_upload_dir()["url"] . "/" . $filename . "_" . $count . "'"; }, $descques); // Description and Question are separated by horizontal line $split = explode("<hr />", $descques, 2); if (count($split) == 1) { $item->description = ""; $item->question = $split[0]; } else { $item->description = $split[0]; $item->question = $split[1]; } // collect answer ids $answers = array(); foreach ($xpath->evaluate("./presentation/flow//response_label", $itemXML) as $resp) { $answers[$resp->getAttribute("ident")] = array("text" => $xpath->evaluate("./material/mattext/text()", $resp)[0]->wholeText, "positive" => 0, "negative" => 0); } // collect points for each answer foreach ($xpath->evaluate("./resprocessing/respcondition", $itemXML) as $resp) { $answerId = $resp->getElementsByTagName("conditionvar")[0]->firstChild->nodeValue; $answerPositive = $xpath->evaluate("./setvar[../conditionvar/varequal]/text()", $resp); $answerNegative = $xpath->evaluate("./setvar[../conditionvar/not/varequal]/text()", $resp); if ($answerPositive->length > 0) { $answers[$answerId]["positive"] = $answerPositive[0]->wholeText; } if ($answerNegative->length > 0) { $answers[$answerId]["negative"] = $answerNegative[0]->wholeText; } } // set answer data for items $item->answers = array(); foreach ($answers as $k => $v) { if ($item->type == "itemsc") { array_push($item->answers, array("answer" => $v["text"], "points" => $v["positive"])); } if ($item->type == "itemmc") { array_push($item->answers, array("answer" => $v["text"], "positive" => $v["positive"], "negative" => $v["negative"])); } } // update Item id (for newly created items) $items[$itemXML->getAttribute("ident")] = $item; } return $items; }
public function WPCB_posts_join($join, $checktype = TRUE) { global $wp_query, $wpdb; if ($wp_query->query["post_type"] == $this->type || !$checktype) { $domain = RoleTaxonomy::getCurrentRoleDomain(); $join .= " JOIN {$wpdb->prefix}eal_{$this->type} AS R ON (R.id = {$wpdb->posts}.ID) "; $join .= " JOIN {$wpdb->prefix}eal_item AS I ON (I.id = R.item_id " . ($domain["name"] != "" ? "AND I.domain = '" . $domain["name"] . "')" : ")"); $join .= " JOIN {$wpdb->posts} AS postitem ON (I.id = postitem.id) "; $join .= " JOIN {$wpdb->users} UI ON (UI.id = postitem.post_author) "; $join .= " JOIN {$wpdb->users} UR ON (UR.id = {$wpdb->posts}.post_author) "; } return $join; }
public static function setCurrentBasket($itemids) { update_user_meta(get_current_user_id(), 'itembasket_' . RoleTaxonomy::getCurrentRoleDomain()["name"], $itemids); }