629 Commits

Author SHA1 Message Date
tjhunt
1ced9d7b73 MDL-10903 - Wrong capability checked in get_all_instances_in_course should be moodle/course:viewhiddenactivities, not moodle/course:viewhiddencourses. Merged from MOODLE_18_STABLE. 2007-09-19 17:06:31 +00:00
martinlanghoff
45ea1afb16 accesslib: make_context_subobj() now expects ctxlevel, and fix all callers
make_context_subobj() was not providing a contextlevel property, and
no callers fetched the field. This comes from its humble origins where
it was only ever called for course objects. These days it's used in
many other situations, so this patch DTRT and

 - fixes make_context_subobj() expect a cxtlevel and turn it into
   contextlevel

 - fixes all callers (accesslib, datalib) to provide it
2007-09-19 07:54:37 +00:00
martinlanghoff
b1cff118c7 datalib:get_courses_wmanagers() handle empty $CFG->coursemanager more gracefully
Having no roles set as coursemanager is a valid setting.
get_courses_wmanagers() should not produce invalid SQL on it...
actually, it should not even try to get the course managers.
2007-09-19 07:54:23 +00:00
martinlanghoff
bbfed0ec61 datalib: get_my_courses() honour $fields array
If the caller passes a fields array, then merge it as we say we will do.
2007-09-19 07:51:36 +00:00
martinlanghoff
b9e9491a89 accesslib: get_my_courses() fix when called when empty sort
get_my_courses() was failing if called with an empty sortorder on a
cached courselist. Fix.
2007-09-19 07:51:19 +00:00
martinlanghoff
e89f157b0a datalib: get_courses_wmanagers() exclude the sitecourse
Should never return the sitecourse - so we exclude it explicitly.
2007-09-19 07:49:10 +00:00
martinlanghoff
2e159efb1c Revert "datalib: Introducing sql_intarray_to_in()"
We don't need sql_intarray_to_in(), use implode() instead.

This reverts commit 3ef7fc54d9df780c837c64a8ace1fc565d6d7744.
2007-09-19 07:47:26 +00:00
martinlanghoff
44f1636ee2 datalib: get_categories() - remove PostgreSQL-ism 2007-09-19 07:28:43 +00:00
martinlanghoff
40fb8aa69a datalib: get_categories() returns context, supports !shallow
With this patch, get_categories() now adds a nice context
sub-object to the returned object, which means callers can
save DB traffic.

It now also supports "deep" retrievals, which means we can
rewrite the course categories display pages to avoid
costly recursion.
2007-09-19 07:27:20 +00:00
martinlanghoff
c5d13b689f datalib: fix_course_sortorder() - minor optimisation
Don't update fields unnecessarily. Cuts 3 DB queries per category
on course/index page (45 in a 15 category setup).

fix_course_sortorder() should be fixed to avoid recursion.
2007-09-19 07:27:08 +00:00
martinlanghoff
70f158789e datalib: Introducing get_courses_wmanagers() for print_courses() usage
For an efficient print_courses() we need to grab in a constant number
of queries...

 - course data
 - "course manager" role assignments
 - user records for the coursemanagers' fullname()

So here we do it in 2 DB queries. The 2nd one (grabbing RAs and user
records) can be expensive if we are dealing with a large number of
courses.

Which we shouldn't - When the number of courses is large the course
listing doesn't come this way anyway...
2007-09-19 07:26:42 +00:00
martinlanghoff
2ee469b3b8 datalib: add_to_log() fix a bug and better error handling
All the $db->Execute calls now do proper err handling, and send their
message to debugging().
2007-09-19 07:22:37 +00:00
martinlanghoff
2965f8fdb8 datalib: get_admin() - cache in a static var
get_admin is called a zillion times during cron, and is a tiny
bit of data we can safely keep around... so...

(shaves 2 queries per email we send!)
2007-09-19 07:22:01 +00:00
martinlanghoff
b00cb46b27 datalib: get_my_courses() now returns invisible courses if visible to $USER
So admins can see the appropriate user listing in the profile page.

In fact, probably _all_ the visibility checks should be done by callers.
Hmmm...
2007-09-19 07:21:35 +00:00
martinlanghoff
3511647c44 datalib:course_parent_visible() rework, remove category_parent_visible()
Reworked course_parent_visible() to always return in a constant
number of db queries (2 worst case) regardless of nesting depth.

The rewritten version has a small cache, but if you are going to
walk many courses, it's still 1~2 DB queries per category seen,
so the right thing to do is to check it in the caller, as seen
in get_my_courses().
2007-09-19 07:19:05 +00:00
martinlanghoff
82c62d1b17 datalib: get_my_courses() - add course visibility checks
Reworked gmc to perform the course visibility checks. These are
very cheap if $CFG->allowvisiblecoursesinhiddencategories is true.

However, where we have to enforce category visibility, it adds a bit
of work. In simple terms, it adds a DB query to read all the categories,
and extra checks to make sure we are doing the right thing WRT

 - course visibility   vs the permission to see hidden courses
 - category visibility vs the permission to see hidden categories

and still do it quickly.
2007-09-19 07:18:54 +00:00
martinlanghoff
8fe9c4de51 datalib: get_courses_search() remove dead code 2007-09-19 07:09:01 +00:00
martinlanghoff
2c64f65cd3 datalib: get_courses_search() learns to be smart about contexts...
Join against contexts, save bazillion context lookups...
2007-09-19 07:08:37 +00:00
martinlanghoff
679b617967 categories: Categories page and get_courses_page() - smarter about context
This patch saves 1600 context lookups on a 1600 course category. rcache
does help a bit with small categories, but on large setups, this is
not sustainable.

And it's not needed either. We have the data right at our fingertips.
Just get it when it's cheap...
2007-09-19 07:08:24 +00:00
martinlanghoff
c1b7a5e537 accesslib: introducing make_context_subobj() - and refactor callers
We had many copies of the subcontext building bit. Time to
abstract it, and fix callers...
2007-09-19 07:08:12 +00:00
martinlanghoff
fe3141e00b get_my_courses() - bugfix in sitewide-login-as support.
Oops. The supportfor login-as was buggy now with sitewide
loginas. Now works in both.
2007-09-19 07:07:34 +00:00
martinlanghoff
ae1555ae2e get_my_courses(): Support course-level login as
A walkthrough of course-login-as functionality shows that is
Just Works, except that get_my_courses() was showing all the
courses. So we fix it.

And cleanup load_all_capabilities() - things just work
transparently.
2007-09-19 07:07:21 +00:00
martinlanghoff
352f6f74fc get_my_courses() and get_user_courses_bycap() field handling and caching
- Field handling moves back to get_my_courses() and now we have
  almost all the fields that the old get_my_courses() did
  (except for summary, which is *huge*) so get_my_courses() asks
  for a lot of fields, but the get_user_courses_bycap() defaults
  are _much_ leaner now.

  I think this makes sense ;-)

- get_my_courses() now caches the course ids for the currently logged in
  user in $USER->mycourses -- as a _string_. This is magnitudes more efficient
  than having it as an array.

The cache makes a difference, but it's not very visible on
normal pageloads (with my courses block, for example).

However, over 100 iterations, for a user with 50 enrolments in a site
with 6K courses, we go from 4.3s to 0.6s. And the DB queries are *cheap*.

            $tt = microtime(true);
            for($n=0;$n<100;$n++) {
                get_my_courses($USER->id, 'sortorder ASC');
            }
            error_log("took " .  (microtime(true) - $tt));
2007-09-19 07:04:59 +00:00
martinlanghoff
573674bf47 accesslib: get_user_courses_bycap() is less of a piggy now...
get_user_courses_bycap() replaces get_courses_bycap_fromsess().

Using a combination of in-DB enrolments and in-session capability
checks, we narrow down the courses we fetch from the DB for checking.

This patch adds a small DB query, and has has a moderate impact on
the timings observable on my laptop (~300ms?), but reduces
*significantly* the bandwidth used, which in cluster environments
with frontends separate from backends has a serious impact.
2007-09-19 07:04:23 +00:00
martinlanghoff
aeb3916b7a datalib: get_my_courses() - some fixes to the data we return
strangely, get_my_courses() is expected to return the
array keyed on id, which messes up the sorting

So let's do it ;-)
2007-09-19 07:04:10 +00:00
martinlanghoff
e1d5e5c181 accesslib: get_my_courses() rework, new get_courses_bycap_fromsess()
get_my_courses() goes from a bazillion queries (500 in some sample
cases) to 1 for the logged-in user, and 4 for a non-logged-in user.

One of those queries brings a *lot* of data across (all rows from
mdl_course) so there is room for serious optimisation.

  However, this clocks at ~300 ms on my laptop, costly, but not
  the end of the world. If your PHP-DB link has bandwidth probs
  it might be a problem.

A few important changes to get_my_courses()

 - (Compat ALERT!) the default fields are less than before --
   (will be followed by patches that fix the callers!) our defaults
   had grown to quite a bit because of the crazy caching scheme it had

 - the $fields parameter is to name _additional_ fields you need, and
   ideally wants them passed as an array. Will cope with old-style
   strings too.

 - the returned courses have an extra property "context" that is
   a fully valid context object, so if the caller needs to perform
   further accesslib checks, we save a query per course down the road

The work is done in the newfangled get_courses_bycap_fromsess()
which is brute-force but fast. I'm sure we can optimise the common
cases a lot in it if we try. It'd be worthwhile to

  - reduce the rows we grab - that's really boneheaded

  - if we copy and tweak the logic of has_cap_fromsess() in it
    it can be made even faster
2007-09-19 07:03:49 +00:00
martinlanghoff
41883f79ca datalib: Introducing sql_intarray_to_in()
Trivial function to turn an array of ints into a string
usable in an IN sql clause.
2007-09-19 07:01:53 +00:00
martinlanghoff
a9fcd13a77 datalib:add_to_log() - avoid schema lookups, pace updates to user and user_lastaccess
* All updates to user.lastaccess and user_lastaccess.timeaccess are paced to
60s of the last update on the same record -- this should reduce the heat
on those tables.

* Updates/inserts to user_lastaccess are down with raw SQL to avoid costly
schema lookups on every request.
2007-09-19 07:01:04 +00:00
martinlanghoff
d863419245 course/index: move orphan fixups to an optimised fix_coursecategory_orphans()
Move the fixups for orphan courses to the newly minted
fix_coursecategory_orphans() -- and optimise it to take only 1 dbquery for
the common case.

If we do find lots of orphans, we issue 2 updates per orphan.

This cuts down dbqueries drastically - we used to have 2x the number of
courses in the site.
2007-09-12 02:56:36 +00:00
martinlanghoff
f8ea60777c fix_course_sortorder(): fix breakage with large categories, saner error
Two improvements for fix_course_sortorder()

 - If the category has more courses than the shift range
   use a larger shift range to avoid overlapping with itself

 - If things do go wrong during the per-course sortorder updates,
   rollback and try and call ourselves with a 'safe' flag.

Still - far from perfect. Probably the global sortorder approach
is broken. The sanest way is to rework things to always join against
course_categories and order by the combined sortorders.
2007-09-12 02:56:16 +00:00
skodak
2d675a2331 MDL-11023 silence warnings in PHP 4.x - the last param was added in PHP 5.0.2; merged from MODOLE_18_STABLE 2007-08-29 20:20:10 +00:00
mattc-catalyst
d8c9d8a150 MDL-10888: - groupings - mod/scorm - updated to support groupings 2007-08-28 02:54:37 +00:00
mattc-catalyst
e683967738 MDL-10888: groupings - added function to get all grouping members, cleaned up some notices 2007-08-26 23:47:24 +00:00
mattc-catalyst
8a67b03fce MDL-10888: groupings - make get_all_instances_in_course respect groupmembersonly 2007-08-22 04:20:42 +00:00
thepurpleblob
39dc779aa9 MDL-10929:
User search will now additionally return users based on an exact match
to their username.
2007-08-21 10:36:46 +00:00
Martin Langhoff
13534ef716 cvsimport fixups 2007-08-29 13:10:11 +12:00
skodak
2c386f82e5 MDL-10383 - deprecated get_groups(), user_group() and ismember() 2007-08-15 20:21:01 +00:00
skodak
1d68419596 MDL-10383 - deprecated groups_members_from_sql and friends - we do not need them anymore because we reverted to 1.7 style groups in 1.9 2007-08-15 19:28:11 +00:00
stronk7
92b564f494 Change xmldb debugging to use the central debugging() function. 2007-08-12 15:58:08 +00:00
stronk7
42fa499221 Prevent one warning
Merged from MOODLE_18_STABLE
2007-08-04 18:48:35 +00:00
stronk7
5930cded47 Added space to perform correct N' queries under MSSQL. MDL-10423
(plus general whitespace clean)

Merged from MOODLE_18_STABLE
2007-08-02 23:39:28 +00:00
toyomoyo
bdf3bbd198 if limit is specified on first call, ignore it, retrieve all, so that we can cache all entries, but only return the required number of entries at the end 2007-07-23 08:56:26 +00:00
toyomoyo
182c21f139 making get_my_courses() respect $limit 2007-07-23 08:38:07 +00:00
stronk7
ae7dc0d1e0 New cross-db version of the big union query used by get_my_courses() function.
I've tested both the "IN" subquery and the "FROM" subquery and, under sites
with more courses, the "FROM" one seems to perform slightly better. MDL-9381

Merged from MOODLE_18_STABLE
2007-07-22 00:56:42 +00:00
toyomoyo
61f774e8f6 merged fix for MDL-10469, users with doanything has no courses showing 2007-07-18 07:02:54 +00:00
mjollnir_
808fae8f05 fixing a small syntax oddity that breaks get_my_courses in postgres. quoting " means escape table, not string 2007-07-14 19:36:59 +00:00
toyomoyo
0674ff6ca8 sql_concact() can handle more than 2 params, thanks Eloy 2007-07-04 02:03:47 +00:00
toyomoyo
0cdd512c17 taking out some redundant sql 2007-06-29 08:31:01 +00:00
toyomoyo
12e27a048d MDL-9283, fixing a broken SQL, thanks Arno 2007-06-29 08:23:31 +00:00
toyomoyo
6a61f741e6 testing patch for MDL-9238 Arnaud's patch 2007-06-27 09:07:47 +00:00