How to create category from api

How to create category from api

- rajeeva d の投稿
返信数: 2

I am trying to create a category from api.But i am unable to do it.


I have tried adding category from code level and added to "course_categories" table.Record is inserted but the category is not showing up in the website.


Can anyone suggest

rajeeva d への返信

Re: How to create category from api

- Marina Glancy の投稿
画像 Core developers 画像 Moodle HQ 画像 Moodle Workplace team 画像 Peer reviewers 画像 Plugin developers 画像 Testers

I think you mean course categories,

in this case there are number of functions in the class coursecat, you would need create() function: https://github.com/moodle/moodle/blob/MOODLE_29_STABLE/lib/coursecatlib.php#L344

Course categories is not an API, so there is no dev docs page about it. From time to time we discuss the phpdocs generation from moodle core but because of very different code style in different parts of moodle the generated phpdocs are almost impossible to navigate through. 


P.S. you can see the examples of calling coursecat::create() in the unittest: https://github.com/moodle/moodle/blob/MOODLE_29_STABLE/lib/tests/coursecatlib_test.php

Just don't create courses in the real system using data generator please! I actually would not recommend creating courses from the code, better use the tool upload courses.