Skip to content

Commit

Permalink
Weird merge issue
Browse files Browse the repository at this point in the history
  • Loading branch information
torinfo committed Jul 4, 2022
1 parent 9eda1eb commit f9e0ae3
Showing 1 changed file with 0 additions and 252 deletions.
252 changes: 0 additions & 252 deletions website_code/php/display_library.php
Expand Up @@ -872,258 +872,6 @@ function get_workspace_templates($folder_id, $tree_id, $sort_type, $copy_only=fa
return $query_response;
}

/**
* Builds an array with the whole structure of the folder suitable for jsTree
* Called by an AJAX function, that returns the array as a alternative JSON file for jstree
* @param $folder_id
* @param $sort_type
*/
function get_workspace_contents($folder_id, $tree_id, $sort_type, $copy_only=false, $type="") {

global $xerte_toolkits_site;

$items = array();
$folders = get_workspace_folders($folder_id, $tree_id, $sort_type, $copy_only, $type);
$templates = get_workspace_templates($folder_id, $tree_id, $sort_type, $copy_only, $type);
foreach($folders as $folder)
{
$item = new stdClass();
$item->id = $folder['tree_id'];
$item->xot_id = $folder['folder_id'];
$item->parent = $folder['tree_parent_id'];
$item->text = $folder['folder_name'];
$item->type = "folder";
$item->xot_type = "folder";
$item->published = false;
$item->shared = false;

$items[] = $item;

$foldertemplates = array_filter($templates, function($template) use ($item) {
return $template['folder'] == $item->xot_id;
});
foreach($foldertemplates as $template)
{
// Check whether shared LO is in recyclebin
if ($template['role'] != 'creator' && $template['creator_folder_name'] == "recyclebin") {
continue;
}

$titem = new stdClass();
$titem->id = $folder['tree_id'] . "_" . $template['template_id'];
$titem->xot_id = $template['template_id'];
$titem->parent = $folder['tree_id'];
$titem->text = $template['project_name'];
if ($type == "")
$titem->type = strtolower($template['parent_template']);
else
$titem->type = strtolower($template['parent_template'] . "_group");
$titem->xot_type = "file";
$titem->published = $template['access_to_whom'] != 'Private' || $template['tsugi_published'] == 1;
$titem->shared = $template['nrshared'] > 1;
$titem->editor_size = $xerte_toolkits_site->learning_objects->{$template['template_framework'] . "_" . $template['template_name']}->editor_size;
$titem->preview_size = $xerte_toolkits_site->learning_objects->{$template['template_framework'] . "_" . $template['template_name']}->preview_size;

$items[] = $titem;
}
}

// And now the times of the workspace itself
$foldertemplates = array_filter($templates, function($template) use ($folder_id){
return $template['folder'] == $folder_id;
});
foreach($foldertemplates as $template)
{
// Check whether shared LO is in recyclebin
if ($template['role'] != 'creator' && $template['creator_folder_name'] == "recyclebin") {
continue;
}

$titem = new stdClass();
$titem->id = $tree_id . "_" . $template['template_id'];
$titem->xot_id = $template['template_id'];
$titem->parent = $tree_id;
$titem->text = $template['project_name'];
if ($type == "")
$titem->type = strtolower($template['parent_template']);
else
$titem->type = strtolower($template['parent_template'] . "_group");
$titem->xot_type = "file";
$titem->published = $template['access_to_whom'] != 'Private' || $template['tsugi_published'] == 1;
$titem->shared = $template['nrshared'] > 1;
$titem->editor_size = $xerte_toolkits_site->learning_objects->{$template['template_framework'] . "_" . $template['template_name']}->editor_size;
$titem->preview_size = $xerte_toolkits_site->learning_objects->{$template['template_framework'] . "_" . $template['template_name']}->preview_size;

$items[] = $titem;
}

return $items;
}

/**
* Builds an array with the folders only of the folder suitable for jsTree
* Called by an AJAX function, that returns the array as a alternative JSON file for jstree
* @param $folder_id
* @param $sort_type
* @param int $group_id if we are looking a group not a folder
*/
function get_workspace_folders($folder_id, $tree_id, $sort_type, $copy_only=false, $type = ""){

/*
* use the global level for folder indenting
*/
global $xerte_toolkits_site;

$items = array();
/*
* select the folders in this folder
*/

$prefix = $xerte_toolkits_site->database_table_prefix;

if ($type == "") {
$query = "select folder_id, folder_name, folder_parent from {$prefix}folderdetails where login_id = ? and folder_parent != 0";
$params = array($_SESSION['toolkits_logon_id']);
}
/*
* Add some more to the query to sort the files
*/

if ($sort_type == "alpha_down") {
$query .= " order by folder_name DESC";
} elseif ($sort_type == "alpha_up") {
$query .= " order by folder_name ASC";
} elseif ($sort_type == "date_down") {
$query .= " order by date_created DESC";
} elseif ($sort_type == "date_up") {
$query .= " order by date_created ASC";
}

$query_response = db_query($query, $params);

/*
* recurse through the folders
*/


// Build tree
// Loop until all the tree_id's have a value
// Nr of loops equals the depths of the tree
// First loop (with parent = 0);
$nextlevel = array();
$unassigned_found = false;
$recyclebin = get_recycle_bin();
$recyclebin_tree_id = "ID_" . $_SESSION['toolkits_logon_id'] . "_F" . $recyclebin;
foreach($query_response as $index=>$row)
{
if ($row['folder_parent'] == $folder_id)
{
$query_response[$index]['tree_id'] = $tree_id . '_F' . $row['folder_id'];
$query_response[$index]['tree_parent_id'] = $tree_id;
$nextlevel[$row['folder_id']] = $query_response[$index]['tree_id']; // Watch out. do not use $row, it's not filled 2 lines up
}
else if ($row['folder_parent'] == $recyclebin)
{
$query_response[$index]['tree_id'] = $recyclebin_tree_id . '_F' . $row['folder_id'];
$query_response[$index]['tree_parent_id'] = $recyclebin_tree_id;
$nextlevel[$row['folder_id']] = $query_response[$index]['tree_id']; // Watch out. do not use $row, it's not filled 2 lines up
}
else
{
$unassigned_found = true;
}
}
while ($unassigned_found)
{
$currlevel = $nextlevel;
$nextlevel = array();
$unassigned_found = false;
foreach($query_response as $index=>$row)
{
if (isset($currlevel[$row['folder_parent']]))
{
$query_response[$index]['tree_id'] = $currlevel[$row['folder_parent']] . '_F' . $row['folder_id'];
$query_response[$index]['tree_parent_id'] = $currlevel[$row['folder_parent']];
$nextlevel[$row['folder_id']] = $query_response[$index]['tree_id'];
}
else{
if (!isset($row['tree_id']))
{
$unassigned_found = true;
}
}
}
}

return $query_response;
}

/**
* Builds an array with the files only of the folder suitable for jsTree
* Called by an AJAX function, that returns the array as a alternative JSON file for jstree
* @param $folder_id
* @param $sort_type
* @param int $group_id if we are looking for files in a group not folder.
*/

function get_workspace_templates($folder_id, $tree_id, $sort_type, $copy_only=false, $type = "")
{

global $xerte_toolkits_site;

$items = array();

$prefix = $xerte_toolkits_site->database_table_prefix;
$query = NULL;
$params = NULL;
if ($type == "") {
$query = "select td.template_name as project_name, otd.template_name,td.access_to_whom, td.tsugi_published, "
. " otd.parent_template, otd.template_framework, td.template_id, tr.role, count(tr2.template_id) as nrshared from {$prefix}templatedetails td, "
. " {$prefix}templaterights tr, {$prefix}originaltemplatesdetails otd left join {$prefix}templaterights tr2 on tr.template_id=tr2.template_id "
. " where td.template_id = tr.template_id and tr.user_id = ? "
. " and tr.folder= ? and otd.template_type_id = td.template_type_id ";
$query = "select td.template_name as project_name, otd.template_name,td.access_to_whom, td.tsugi_published, "
. " otd.parent_template, otd.template_framework, td.template_id, tr.role, tr.folder, fd3.folder_name as creator_folder_name, count(tr2.template_id) as nrshared "
. " from {$prefix}templatedetails td "
. " join {$prefix}templaterights tr on td.template_id=tr.template_id and tr.user_id=? "
. " join {$prefix}originaltemplatesdetails otd on otd.template_type_id = td.template_type_id "
. " join {$prefix}templaterights tr3 on td.template_id=tr3.template_id and tr3.role='creator' "
. " join {$prefix}folderdetails fd3 on tr3.folder=fd3.folder_id "
. " left join {$prefix}templaterights tr2 on td.template_id=tr2.template_id ";
$params = array($_SESSION['toolkits_logon_id']);
} else {
//select templates the same way as regularly, however, now check for group_id in template_group_rights
$query = "select td.template_name as project_name, otd.template_name,td.access_to_whom, td.tsugi_published, "
. " otd.parent_template, otd.template_framework, td.template_id, tgr.role, 2 as nrshared from {$prefix}templatedetails td, "
. " {$prefix}template_group_rights tgr, {$prefix}originaltemplatesdetails otd where td.template_id = tgr.template_id and tgr.group_id = ? "
. " and otd.template_type_id = td.template_type_id ";
$params = array($type);
}

if ($copy_only) {
$query .= " and (tr.role = 'creator' or tr.role ='co-author') ";
}

if ($type == "") {
$query .= " group by td.template_id, td.template_name, td.date_created, otd.template_name,td.access_to_whom, td.tsugi_published, otd.parent_template, otd.template_framework, tr.role, tr.folder,fd3.folder_name ";
}

if ($sort_type == "alpha_down") {
$query .= "order by tr.folder ASC, td.template_name DESC";
} elseif ($sort_type == "alpha_up") {
$query .= "order by tr.folder ASC, td.template_name ASC";
} elseif ($sort_type == "date_down") {
$query .= "order by tr.folder ASC, td.date_created DESC";
} elseif ($sort_type == "date_up") {
$query .= "order by tr.folder ASC, td.date_created ASC";
}


$query_response = db_query($query, $params);
return $query_response;
}


/**
* Builds an array with the whole structure of the group folder suitable for jsTree
* Called by an AJAX function, that returns the array as a alternative JSON file for jstree
Expand Down

0 comments on commit f9e0ae3

Please sign in to comment.