[Closed] Courses by category - Cursos Por Categoria

10 years 2 months ago 10 years 1 month ago by Yuri Reis.
Yuri Reis
Posts: 23
More
Topic Author
[Closed] Courses by category - Cursos Por Categoria #1
Hi guys,
i'm here again!
So, i have used Joomdle day by day, and i'm very happy with this framework.
I would like know if is possible get all courses that one logged user and show the courses by categories.
I know that joomdle have one kind of menu "courses by category", but i would like something like the module "mod_joomdle_my_courses". View a user's courses, divided into categories and when clicked it redirects to room moodle.

This is possible?

thanks one more time

Yuri Reis Barbosa - Brazil/Vitória

Please Log in or Create an account to join the conversation.

10 years 2 months ago
Yuri Reis
Posts: 23
More
Topic Author
[Closed] Courses by category - Cursos Por Categoria #2
Hi guys , i tried find one solution using the meny type "couserbycategory".
but i cant find one solution.
I could point out the direct course to the student's room but can not take the courses for the student logado.
Para receive data from students, I used the following method:

$user = & JFactory::getUser();
$username = $user->get('username');

$session =& JFactory::getSession();
$token = md5 ($session->getId());

$cursos = JoomdleHelperContent::call_method ("my_courses", $username);

but can not get categories.
I know I would have to use the function:

$cursos = JoomdleHelperContent::getCourseCategory ($cat);
$cat_id = $cat;

passing the id of the course. But how to get the id of the courses the student logged in?

Please Log in or Create an account to join the conversation.

10 years 2 months ago
Chris
Posts: 2118
More
[Closed] Courses by category - Cursos Por Categoria #3
Hi there,

Antonio is on holidays until the end of the month. I can try to have a play but it will not be for another 1-2 weeks, by which time he is back anyway :) If I get a chance earlier I will let you know.

Chris

Please Log in or Create an account to join the conversation.

10 years 2 months ago
Yuri Reis
Posts: 23
More
Topic Author
[Closed] Courses by category - Cursos Por Categoria #4
Hi Chris

I will continue try find one solution, and i wait for your help or Antonio help or other people of forum
Thanks one more time!

Please Log in or Create an account to join the conversation.

10 years 1 month ago
Antonio Durán
Posts: 7311
More
[Closed] Courses by category - Cursos Por Categoria #5
Hi.

You will need to add some code in my_courses web service, to include category id in result. Something like
$record = $course->category;

Then you could use that to call the other web service.

Please Log in or Create an account to join the conversation.

10 years 1 month ago
Yuri Reis
Posts: 23
More
Topic Author
[Closed] Courses by category - Cursos Por Categoria #6
Hello Antonio,
I customize the view "coursebycategory" and I did it here and it worked.

...//components/com_joomdle/views/coursesbycategory/tmpl/default.php


<?php defined('_JEXEC') or die('Restricted access'); ?>

<?php
$index_url = JURI::base()."index.php";
$itemid = JoomdleHelperContent::getMenuItem();

?>

<?php
// Include the whosonline functions only once
//require_once (dirname(__FILE__).DS.'helper.php');

$comp_params = &JComponentHelper::getParams( 'com_joomdle' );

$moodle_xmlrpc_server_url = $comp_params->get( 'MOODLE_URL' ).'/mnet/xmlrpc/server.php';
$moodle_auth_land_url = $comp_params->get( 'MOODLE_URL' ).'/auth/joomdle/land.php';
$linkstarget = $comp_params->get( 'linkstarget' );

$user = & JFactory::getUser();
$username = $user->get('username');

$session =& JFactory::getSession();
$token = md5 ($session->getId());

$cursos = JoomdleHelperContent::call_method ("my_courses", $username);
$target = " target='_blank'";
?>

<table width="100%" cellpadding="4" cellspacing="0" border="0" align="center" class="contentpane<?php echo $this->params->get( 'pageclass_sfx' ); ?>">

<tr>
<td width="60%" colspan="2">
<!-- exibir meus cursos-->
<?php

$moodle_auth_land_url = $comp_params->get( 'MOODLE_URL' ).'/auth/joomdle/land.php';

echo '<ul class="menu">';

if (is_array($cursos)) {

foreach ($cursos as $id => $curso) {
$id = $curso;

$minhacategoria = JoomdleHelperContent::getCourseCategory ($curso);
$count = count($minhacategoria);
$tamvet = sizeof($minhacategoria) -1;
for($i = 0; $i<$count;$i++){
if($i != $count-1){
echo "" . $minhacategoria[$tamvet-$i] . " ->";
}else {
echo "" . $minhacategoria[$tamvet-$i] . ":";
}


}
//echo $minhacategoria;
echo "<li><a $target href=\"".$moodle_auth_land_url."?username=$username&token=$token&mtype=course&id=$id&use_wrapper=$open_in_wrapper&Itemid=$itemid\">".$curso."</a></li>";
//echo $curso;

}
}

echo "</ul>";


?>

</td>
</tr>


</table>


and /moodle/auth/joomdle/auth.php

function courses_by_category ($category, $available = 0) {
global $CFG;
//$category_id = addslashes ($category);
(int)$category;
$countarray = 0;
$my_cate = array();
$num = $category;
$contador = 0;

$i=0;
while ($num != 0){
$query = "SELECT name,parent
FROM
{$CFG->prefix}course_categories
WHERE
id = '$num'
";
$result = mysql_query($query);
$registros = mysql_fetch_row($result);
$my_cate[$i] = $registros[0];
$num = (int)$registros[1];
$i++;

}

return $my_cate;
}




I need now is the following. Group courses in the same category and display. For example, the logical course and course Profinacci Calculator are part of the mathematics category, hence would like to display :
mathematics
. logic
. Profinacci Calculator

thanks one more time

Please Log in or Create an account to join the conversation.

10 years 1 month ago
Antonio Durán
Posts: 7311
More
[Closed] Courses by category - Cursos Por Categoria #7
Sorry, but I don't really understand what you are doing in that code.

But if you already have the info, I guess you just need to loop trhough it to show it how you want...

Anyway, for me it seems more logical to create a mycourses modified view, copying funcionality there from the coursesbycategory view, so that courses are shown they way you want.

Please Log in or Create an account to join the conversation.

10 years 1 month ago
Yuri Reis
Posts: 23
More
Topic Author
[Closed] Courses by category - Cursos Por Categoria #8
B) Finally I Got what i wanted. Get the courses divided by category, showing only those courses students logged in and show all category trees.
Well, looks like the code (joomlasite/components/com_joomdle/views/coursesbycategory/tmpl/default.php) and one picture for you undertand what i wanted.



default.php code modify

<?php defined('_JEXEC') or die('Restricted access'); ?>

<?php
$index_url = JURI::base()."index.php";
$itemid = JoomdleHelperContent::getMenuItem();

?>

<?php


$comp_params = &JComponentHelper::getParams( 'com_joomdle' );

$moodle_xmlrpc_server_url = $comp_params->get( 'MOODLE_URL' ).'/mnet/xmlrpc/server.php';
$moodle_auth_land_url = $comp_params->get( 'MOODLE_URL' ).'/auth/joomdle/land.php';
$linkstarget = $comp_params->get( 'linkstarget' );
//get the user
$user = & JFactory::getUser();
$username = $user->get('username');

$session = & JFactory::getSession();
$token = md5 ($session->getId());

//get all the courses the student logged
$cursos = JoomdleHelperContent::call_method ("my_courses", $username);

$target = " target='_blank'";
?>
<div class="componentheading"> Cursos por Categoria</div><br />
<table width="100%" cellpadding="4" cellspacing="0" border="0" align="center" class="contentpane<?php echo $this->params->get( 'pageclass_sfx' ); ?>">


<tr class ="sectiontableentry3">
<?php
$moodle_auth_land_url = $comp_params->get( 'MOODLE_URL' ).'/auth/joomdle/land.php';

echo '<td width="90%" height="20" >';

//verify if $cursos is array
if (is_array($cursos)) {

// create the variable - $cateogira_atual (in english @current_category)
$categoria_atual = "";


foreach ($cursos as $id => $curso)
{
//get the id of student logged
$id = $curso;
//Get an array with all the category tree of Moodle (ps: I Changed the function "getCourseCategory" in ..//moodle/auth/joomdle/auth.php - code above)
$minhacategoria = JoomdleHelperContent::getCourseCategory ($curso);
//reverse array
$arraymycategory = array_reverse($minhacategoria);


//concatenates each field in the array with "->" and the last position puts it ":"
$arraymycategory = implode(" -> ", $arraymycategory).":";

//compare if the courses belong to the same category, the courses are grouped by category and displays the courses divided in their categories
if(strcasecmp($arraymycategory, $categoria_atual) != 0)
{
if(!empty($categoria_atual))
echo $texto . "</ul>";
$categoria_atual = $arraymycategory;
$texto = "<ul>" . $categoria_atual;

}
//get the course and concatenate with the category
$texto .= "<li><a $target href=\"".$moodle_auth_land_url."?username=$username&token=$token&mtype=course&id=$id&use_wrapper=$open_in_wrapper&Itemid=$itemid\">".$curso."</a></li>";

}
echo $texto . "</ul>";

}
echo '</td>';

?>
</tr>


</table>



and auth.php /moodle/auth/joomdle/auth.php


function courses_by_category ($category, $available = 0) {
global $CFG;

(int)$category;
$countarray = 0;
$my_cate = array();
$num = $category;
$contador = 0;

$i=0;
while ($num != 0){
$query = "SELECT name,parent
FROM
{$CFG->prefix}course_categories
WHERE
id = '$num'
";
$result = mysql_query($query);
$registros = mysql_fetch_row($result);
$my_cate[$i] = $registros[0];
$num = (int)$registros[1];
$i++;

}

return $my_cate;
}


I'm leaving what i did for future reference

Attachments:

Please Log in or Create an account to join the conversation.

10 years 1 month ago
Antonio Durán
Posts: 7311
More
[Closed] Courses by category - Cursos Por Categoria #9
Great!

Thanks for sharing :)

Please Log in or Create an account to join the conversation.

9 years 10 months ago 9 years 10 months ago by Damien Caldwell.
Damien Caldwell
Posts: 4
More
[Closed] Courses by category - Cursos Por Categoria #10
Hi

This is exactly what I need. I tried, but it didn't work anymore advice? Have you the files?

Grateful for any help with this, Damien

Please Log in or Create an account to join the conversation.