Hi guys, someone can help me?

The module is excellent but it can be a little confusing when U go on Resources Tab and u have to add resources.

If you have more than 1 teacher for a classroom, every teacher can see the content created by other teachers and offen they do mistakes adding the wrong resources to wrong topic.

Example:

Classroom 1

topic 1 PHP lessons
topic 2 Javascript lessons

teacher 1 is the teacher of PHP lessons

teacher 2 is the teacher of Javascript lessons

when you go to the Resources tab you can see all the resources created by teacher 1 and teacher 2 not assigned. Teacher 1 do a mistake and add a Javascript resource to the Topic 1 PHP lessons.

In few word what I'm asking if it's possible do a sql query who loads in the Resource tabs only the resources created by the logged in user, in this way is impossible to do mistakes :)

Hope someone can help me :)

Comments

GolDRoger’s picture

I'm not a coder but i thinks is only a variable who add the user id in this function

/**
* Get resources associated to a given course.
*
* @param $course
* Course to query about her resources.
* @param $topic
* Topic which the resource belongs to. It could be: a topic, null (all resources),
* or false (only resources without associated topic).
* @return
* An array containing resource objects associated with $course. Returns an
* empty array if there's no resources.
*/
function classroom_get_resources_for($course, $topic = NULL) {
$qry = "SELECT resource_nid FROM {classroom_course_resource} WHERE course_nid = %d";
$conds = array($course->nid);
if ($topic) {
$qry .= " AND topic_tid = %d";
$conds[] = $topic->tid;
} elseif ($topic === FALSE) {
$qry .= " AND topic_tid IS NULL";
}
$result = db_query($qry, $conds);
$resources = array();
while ($row = db_fetch_array($result)) {
// OPTIMIZE
$resources[] = node_load(array('nid' => $row['resource_nid']));
}
return $resources;
}

GolDRoger’s picture

They suggested me this but i'm not able to make it working with the upper function
and the query is wrong because does not exist a content type classroom_course_resource

  global $user;
  $res = db_query('SELECT nid FROM {node} WHERE type = "classroom_course_resource" AND uid = %d',  $user-uid);
  while($row = db_fetch_array($res)) {
    // do something with $row['nid']
  }

GolDRoger’s picture

this is what i will do with sql

SELECT DISTINCT classroom_course_resource.resource_nid, node.uid from classroom_course_resource, node where uid=1 AND course_nid=2;

but now i have to make dynamic the node.uid for autounderstanding wich user is logged in

GolDRoger’s picture

I done a BIG MISTAKE, the function was wrong, this function populate the list of resources assigned to courses when u press Resources.

What i was trying to modify was the list of nodes when u press the button Add Resource, In this form I had the nedd of showing ONLY the nodes created by the current logged in user to prevent mistakes, for example teacher 1 use the content of teacher 2 and u have for example a javascript lesson inside one of php.

Now the game is done and the function is located at line 465 of classroom.pages.inc

I have added global $user and $uid = $user->uid;

and at the end of the sql command uid=$uid before $order_sql

simple overwrite this function:


/**
* Form to add resources to a course.
*
* @param $course_nid
* Course ID.
*/
function classroom_course_add_resources_form($form, $course_nid) {

$headers = array(
'name' => array('data' => t('Title'), 'field' => 'title'),
);
$types = array();
foreach (_classroom_get_types_for('resource') as $name => $type) {
$types[] = $name;
}
$types_sql = "'" . implode("','", $types) . "'";
$order_sql = tablesort_sql($headers);

global $user;
$uid = $user->uid;
$qry = "SELECT * FROM {node} AS n WHERE type IN ($types_sql) AND NOT EXISTS (SELECT * FROM {classroom_course_resource} WHERE resource_nid = n.nid AND course_nid = %d) AND uid=$uid $order_sql";
$pager_limit = variable_get('classroom_pager_limit', CLASSROOM_PAGER_LIMIT_DEFAULT);
$result = pager_query($qry, $pager_limit, 0, NULL, $course_nid, $uid);

$course = node_load(array('nid' => $course_nid));

$topics_map = classroom_get_topics_for_select($course);
$topic_form = array();
if ($topics_map) {
$topic_form['topic_tid'] = array(
'#type' => 'select',
'#title' => t('Topic'),
'#description' => t('Related topic.'),
'#options' => $topics_map,
);
}

$common_form = _classroom_course_resources_form($course_nid, $result, t("Add selected"),
$headers);
return array_merge($topic_form, $common_form);
}

GolDRoger’s picture

Status: Active » Closed (fixed)
gaheinrichs’s picture

Thank you for that correction! It really helped me a lot!

Hey do you know how to do the same thing, but in the quiz module. When you want to add questions to the quiz it shows all the questions done by all the users. It might be better to show just the ones that the logged in user have done.

Thanks in advance