當前位置: 首頁>>代碼示例>>PHP>>正文


PHP coursecat::get_parents方法代碼示例

本文整理匯總了PHP中coursecat::get_parents方法的典型用法代碼示例。如果您正苦於以下問題:PHP coursecat::get_parents方法的具體用法?PHP coursecat::get_parents怎麽用?PHP coursecat::get_parents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在coursecat的用法示例。


在下文中一共展示了coursecat::get_parents方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: change_parent_raw

 /**
  * Moves the category under another parent category. All associated contexts are moved as well
  *
  * This is protected function, use change_parent() or update() from outside of this class
  *
  * @see coursecat::change_parent()
  * @see coursecat::update()
  *
  * @param coursecat $newparentcat
  * @throws moodle_exception
  */
 protected function change_parent_raw(coursecat $newparentcat)
 {
     global $DB;
     $context = $this->get_context();
     $hidecat = false;
     if (empty($newparentcat->id)) {
         $DB->set_field('course_categories', 'parent', 0, array('id' => $this->id));
         $newparent = context_system::instance();
     } else {
         if ($newparentcat->id == $this->id || in_array($this->id, $newparentcat->get_parents())) {
             // Can not move to itself or it's own child.
             throw new moodle_exception('cannotmovecategory');
         }
         $DB->set_field('course_categories', 'parent', $newparentcat->id, array('id' => $this->id));
         $newparent = context_coursecat::instance($newparentcat->id);
         if (!$newparentcat->visible and $this->visible) {
             // Better hide category when moving into hidden category, teachers may unhide afterwards and the hidden children
             // will be restored properly.
             $hidecat = true;
         }
     }
     $this->parent = $newparentcat->id;
     $context->update_moved($newparent);
     // Now make it last in new category.
     $DB->set_field('course_categories', 'sortorder', MAX_COURSES_IN_CATEGORY * MAX_COURSE_CATEGORIES, array('id' => $this->id));
     if ($hidecat) {
         fix_course_sortorder();
         $this->restore();
         // Hide object but store 1 in visibleold, because when parent category visibility changes this category must
         // become visible again.
         $this->hide_raw(1);
     }
 }
開發者ID:janaece,項目名稱:globalclassroom4_clean,代碼行數:44,代碼來源:coursecatlib.php

示例2: category_listing

 /**
  * Presents a course category listing.
  *
  * @param coursecat $category The currently selected category. Also the category to highlight in the listing.
  * @return string
  */
 public function category_listing(coursecat $category = null)
 {
     if ($category === null) {
         $selectedparents = array();
         $selectedcategory = null;
     } else {
         $selectedparents = $category->get_parents();
         $selectedparents[] = $category->id;
         $selectedcategory = $category->id;
     }
     $catatlevel = \core_course\management\helper::get_expanded_categories('');
     $catatlevel[] = array_shift($selectedparents);
     $catatlevel = array_unique($catatlevel);
     $listing = coursecat::get(0)->get_children();
     $attributes = array('class' => 'ml', 'role' => 'tree', 'aria-labelledby' => 'category-listing-title');
     $html = html_writer::start_div('category-listing');
     $html .= html_writer::tag('h3', get_string('categories'), array('id' => 'category-listing-title'));
     $html .= $this->category_listing_actions($category);
     $html .= html_writer::start_tag('ul', $attributes);
     foreach ($listing as $listitem) {
         // Render each category in the listing.
         $subcategories = array();
         if (in_array($listitem->id, $catatlevel)) {
             $subcategories = $listitem->get_children();
         }
         $html .= $this->category_listitem($listitem, $subcategories, $listitem->get_children_count(), $selectedcategory, $selectedparents);
     }
     $html .= html_writer::end_tag('ul');
     $html .= $this->category_bulk_actions($category);
     $html .= html_writer::end_div();
     return $html;
 }
開發者ID:eamador,項目名稱:moodle-course-custom-fields,代碼行數:38,代碼來源:management_renderer.php

示例3: record_expanded_category

 /**
  * Records when a category is expanded or collapsed so that when the user
  *
  * @param \coursecat $coursecat The category we're working with.
  * @param bool $expanded True if the category is expanded now.
  */
 public static function record_expanded_category(\coursecat $coursecat, $expanded = true)
 {
     // If this ever changes we are going to reset it and reload the categories as required.
     self::$expandedcategories = null;
     $categoryid = $coursecat->id;
     $path = $coursecat->get_parents();
     /* @var \cache_session $cache */
     $cache = \cache::make('core', 'userselections');
     $categories = $cache->get('categorymanagementexpanded');
     if (!is_array($categories)) {
         if (!$expanded) {
             // No categories recorded, nothing to remove.
             return;
         }
         $categories = array();
     }
     if ($expanded) {
         $ref =& $categories;
         foreach ($coursecat->get_parents() as $path) {
             if (!isset($ref[$path]) || !is_array($ref[$path])) {
                 $ref[$path] = array();
             }
             $ref =& $ref[$path];
         }
         if (!isset($ref[$categoryid])) {
             $ref[$categoryid] = true;
         }
     } else {
         $found = true;
         $ref =& $categories;
         foreach ($coursecat->get_parents() as $path) {
             if (!isset($ref[$path])) {
                 $found = false;
                 break;
             }
             $ref =& $ref[$path];
         }
         if ($found) {
             $ref[$categoryid] = null;
             unset($ref[$categoryid]);
         }
     }
     $cache->set('categorymanagementexpanded', $categories);
 }
開發者ID:EsdrasCaleb,項目名稱:moodle,代碼行數:50,代碼來源:helper.php


注:本文中的coursecat::get_parents方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。