/mod/brainstorm/operators/hierarchize/locallib.php
PHP | 261 lines | 187 code | 17 blank | 57 comment | 17 complexity | 25b38685447c105c5db0157977e2e3cc MD5 | raw file
- <?php
-
- include_once "{$CFG->dirroot}/mod/brainstorm/treelib.php";
-
- /**
- * Module Brainstorm V2
- * Operator : hierarchize
- * @author Valery Fremaux
- * @package Brainstorm
- * @date 20/12/2007
- */
-
- /**
- *
- * @uses CFG
- * @param int $brainstormid
- * @param int $userid
- * @param int $groupid
- * @param boolean $excludemyself
- * @param int $fatherid
- * @returns array
- */
- function hierarchize_get_childs($brainstormid, $userid=null, $groupid=0, $excludemyself=false, $fatherid=0){
- global $CFG;
-
- $accessClause = brainstorm_get_accessclauses($userid, $groupid, $excludemyself);
-
- $fatherClause = ($fatherid != 0) ? " AND od.itemdest = $fatherid " : ' AND (od.itemdest IS NULL OR od.itemdest = 0) ';
-
- $sql = "
- SELECT
- r.id,
- r.response,
- od.itemdest,
- od.intvalue,
- od.userid,
- od.groupid,
- od.id as odid
- FROM
- {$CFG->prefix}brainstorm_responses as r,
- {$CFG->prefix}brainstorm_operatordata as od
- WHERE
- r.id = od.itemsource AND
- operatorid = 'hierarchize' AND
- r.brainstormid = {$brainstormid}
- {$accessClause}
- {$fatherClause}
- ORDER BY
- od.intvalue,
- od.userid
- ";
- // echo $sql;
- if (!$records = get_records_sql($sql)){
- return array();
- }
- return $records;
- }
-
-
- /**
- *
- * @param int $brainstormid
- * @param array $referencelevelkeys
- * @param int $groupid
- * @param int $fatherid
- */
- function hierarchize_get_otherchilds($brainstormid, $referencelevelkeys, $groupid=0, $fatherid=0){
- $allchilds = order_get_childs($brainstormid, 0, $groupid, true, $fatherid);
- $agree = array();
- $disagree = array();
- if ($allchilds){
- foreach($allchilds as $child){
- if ($referencelevelkeys[$child->intvalue] == $child->id){
- $agree[$child->intvalue] = @$agree[$child->intvalue] + 1;
- }
- else{
- $disagree[$child->intvalue] = @$disagree[$child->intvalue] + 1;
- }
- }
- }
- $result->agree = &$agree;
- $result->disagree = &$disagree;
- return $result;
- }
-
- /**
- * refreshes the tree data if new responses where in in the meanwhile
- *
- */
- function hierarchize_refresh_tree($brainstormid, $groupid=0){
- global $CFG, $USER;
-
- // get those responses who are new
- $sql = "
- SELECT
- r.id,r.id
- FROM
- {$CFG->prefix}brainstorm_responses as r
- WHERE
- r.brainstormid = {$brainstormid} AND
- r.groupid = {$groupid} AND
- r.id NOT IN
- (SELECT
- od.itemsource
- FROM
- {$CFG->prefix}brainstorm_operatordata as od
- WHERE
- od.brainstormid = $brainstormid AND
- operatorid = 'hierarchize' AND
- od.groupid = {$groupid} AND
- od.userid = {$USER->id})
- ";
- // echo $sql;
- $diff = get_records_sql($sql);
- $maxordering = brainstorm_tree_get_max_ordering($brainstormid, null, $groupid, 1, 0);
- if ($diff){
- $treerecord->brainstormid = $brainstormid;
- $treerecord->userid = $USER->id;
- $treerecord->groupid = $groupid;
- $treerecord->operatorid = 'hierarchize';
- $treerecord->itemdest = 0;
- $treerecord->intvalue = $maxordering + 1;
- $treerecord->timemodified = time();
- foreach($diff as $adif){
- $treerecord->itemsource = $adif->id;
- if (!insert_record('brainstorm_operatordata', $treerecord)){
- error("Could not insert tree regeneration records");
- }
- $treerecord->intvalue++;
- }
- }
- }
-
- /**
- *
- * @param int $brainstormid
- * @param object $cm
- * @param int $userid
- * @param int $groupid
- * @param boolean $excludemyself
- * @param int $fatherid
- * @param string $prefix
- * @param int $indent
- * @param boolean $editing
- */
- function hierarchize_print_level($brainstormid, $cm, $userid, $groupid, $excludemyself, $fatherid, $prefix, $indent, $configdata, $editing=true){
- global $CFG;
-
- $subs = hierarchize_get_childs($brainstormid, $userid, $groupid, $excludemyself, $fatherid);
- if (!empty($subs)){
- $i = 0;
- $indent += 25;
- $level = $indent / 25;
- $subscount = 0;
- foreach($subs as $sub){
- $levelprefix = $prefix . '.' . ($i + 1);
- ?>
- <tr>
- <?php
- if ($editing){
- $up = ($i) ? "<a href=\"view.php?id={$cm->id}&operator=hierarchize&what=up&item={$sub->odid}\"><img src=\"{$CFG->pixpath}/t/up.gif\"></a>" : '' ;
- $down = ($i < count($subs) - 1) ? "<a href=\"view.php?id={$cm->id}&operator=hierarchize&what=down&item={$sub->odid}\"><img src=\"{$CFG->pixpath}/t/down.gif\"></a>" : '' ;
- $left = ($indent > 25) ? "<a href=\"view.php?id={$cm->id}&operator=hierarchize&what=left&item={$sub->odid}\"><img src=\"{$CFG->pixpath}/t/left.gif\"></a>" : '' ;
- if ((isset($configdata->maxarity) && $configdata->maxarity && $subscount >= $configdata->maxarity) || (isset($configdata->maxlevels) && $configdata->maxlevels && $level >= $configdata->maxlevels)){
- $right = '';
- }
- else{
- $right = ($i) ? "<a href=\"view.php?id={$cm->id}&operator=hierarchize&what=right&item={$sub->odid}\"><img src=\"{$CFG->pixpath}/t/right.gif\"></a>" : '' ;
- }
- ?>
- <td>
- <table cellspacing="3">
- <tr>
- <td width="10">
- <?php echo $left ?>
- </td>
- <td width="10">
- <?php echo $up ?>
- </td>
- <td width="10">
- <?php echo $down ?>
- </td>
- <td width="10">
- <?php echo $right ?>
- </td>
- </tr>
- </table>
- </td>
- <?php
- }
- ?>
- <td style="text-align : right; padding-right : <?php echo $indent - 23; ?>px" class="response">
- <b><?php echo $levelprefix ?>.</b> <?php echo $sub->response; ?>
- </td>
- </tr>
- <?php
- hierarchize_print_level($brainstormid, $cm, $userid, $groupid, $excludemyself, $sub->odid, $levelprefix, $indent, $configdata, $editing);
- $i++;
- $subscount = brainstorm_count_subs($sub->odid); // get subs status of previous entry
- }
- }
- }
-
- /**
- *
- * @param int $brainstormid
- * @param object $cm
- * @param int $userid
- * @param int $groupid
- * @param boolean $excludemyself
- * @param string $previouslevel
- */
- function hierarchize_print_levelindeepness($brainstormid, $cm, $userid=null, $groupid=0, $excludemyself=false, $fatherid=0){
- global $CFG;
-
- $subs = hierarchize_get_childs($brainstormid, $userid, $groupid, $excludemyself, $fatherid);
-
- $accessClause = brainstorm_get_accessclauses($userid, $groupid, false);
-
- if (!empty($subs)){
- // get column spanning counts
- $idlist = join("','", array_keys($subs));
- echo '<tr valign="top">';
- foreach($subs as $sub){
- echo '<td class="subtree">';
- echo $sub->response;
- echo '<br/><table width="100%">';
- hierarchize_print_levelindeepness($brainstormid, $cm, $userid, $groupid, $excludemyself, $sub->odid);
- echo '</table>';
- echo '</td>';
- }
- echo '</tr>';
- }
- }
-
- /**
- *
- *
- */
- function hierarchize_display(&$brainstorm, $userid, $groupid){
- $tree = hierarchize_get_childs($brainstorm->id, $userid, $groupid);
- ?>
- <center>
- <style>
- .response{ font-size : 1.2em ; border : 1px solid gray }
- .subtree{ font-size : 1.0em ; border : 1px solid gray }
- </style>
- <?php
- if ($tree){
- echo '<table width="80%">';
- hierarchize_print_levelindeepness($brainstorm->id, $brainstorm->cm, $userid, $groupid, 0);
- echo '</table>';
- }
- else{
- echo get_string('notreeset','brainstorm');
- }
- ?>
- </center>
- <?php
- }
- ?>