PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/mod/brainstorm/operators/hierarchize/locallib.php

https://github.com/galitush2005/RTL-BIDI-Hebrew-Moodle-Plugins
PHP | 261 lines | 187 code | 17 blank | 57 comment | 17 complexity | 25b38685447c105c5db0157977e2e3cc MD5 | raw file
  1. <?php
  2. include_once "{$CFG->dirroot}/mod/brainstorm/treelib.php";
  3. /**
  4. * Module Brainstorm V2
  5. * Operator : hierarchize
  6. * @author Valery Fremaux
  7. * @package Brainstorm
  8. * @date 20/12/2007
  9. */
  10. /**
  11. *
  12. * @uses CFG
  13. * @param int $brainstormid
  14. * @param int $userid
  15. * @param int $groupid
  16. * @param boolean $excludemyself
  17. * @param int $fatherid
  18. * @returns array
  19. */
  20. function hierarchize_get_childs($brainstormid, $userid=null, $groupid=0, $excludemyself=false, $fatherid=0){
  21. global $CFG;
  22. $accessClause = brainstorm_get_accessclauses($userid, $groupid, $excludemyself);
  23. $fatherClause = ($fatherid != 0) ? " AND od.itemdest = $fatherid " : ' AND (od.itemdest IS NULL OR od.itemdest = 0) ';
  24. $sql = "
  25. SELECT
  26. r.id,
  27. r.response,
  28. od.itemdest,
  29. od.intvalue,
  30. od.userid,
  31. od.groupid,
  32. od.id as odid
  33. FROM
  34. {$CFG->prefix}brainstorm_responses as r,
  35. {$CFG->prefix}brainstorm_operatordata as od
  36. WHERE
  37. r.id = od.itemsource AND
  38. operatorid = 'hierarchize' AND
  39. r.brainstormid = {$brainstormid}
  40. {$accessClause}
  41. {$fatherClause}
  42. ORDER BY
  43. od.intvalue,
  44. od.userid
  45. ";
  46. // echo $sql;
  47. if (!$records = get_records_sql($sql)){
  48. return array();
  49. }
  50. return $records;
  51. }
  52. /**
  53. *
  54. * @param int $brainstormid
  55. * @param array $referencelevelkeys
  56. * @param int $groupid
  57. * @param int $fatherid
  58. */
  59. function hierarchize_get_otherchilds($brainstormid, $referencelevelkeys, $groupid=0, $fatherid=0){
  60. $allchilds = order_get_childs($brainstormid, 0, $groupid, true, $fatherid);
  61. $agree = array();
  62. $disagree = array();
  63. if ($allchilds){
  64. foreach($allchilds as $child){
  65. if ($referencelevelkeys[$child->intvalue] == $child->id){
  66. $agree[$child->intvalue] = @$agree[$child->intvalue] + 1;
  67. }
  68. else{
  69. $disagree[$child->intvalue] = @$disagree[$child->intvalue] + 1;
  70. }
  71. }
  72. }
  73. $result->agree = &$agree;
  74. $result->disagree = &$disagree;
  75. return $result;
  76. }
  77. /**
  78. * refreshes the tree data if new responses where in in the meanwhile
  79. *
  80. */
  81. function hierarchize_refresh_tree($brainstormid, $groupid=0){
  82. global $CFG, $USER;
  83. // get those responses who are new
  84. $sql = "
  85. SELECT
  86. r.id,r.id
  87. FROM
  88. {$CFG->prefix}brainstorm_responses as r
  89. WHERE
  90. r.brainstormid = {$brainstormid} AND
  91. r.groupid = {$groupid} AND
  92. r.id NOT IN
  93. (SELECT
  94. od.itemsource
  95. FROM
  96. {$CFG->prefix}brainstorm_operatordata as od
  97. WHERE
  98. od.brainstormid = $brainstormid AND
  99. operatorid = 'hierarchize' AND
  100. od.groupid = {$groupid} AND
  101. od.userid = {$USER->id})
  102. ";
  103. // echo $sql;
  104. $diff = get_records_sql($sql);
  105. $maxordering = brainstorm_tree_get_max_ordering($brainstormid, null, $groupid, 1, 0);
  106. if ($diff){
  107. $treerecord->brainstormid = $brainstormid;
  108. $treerecord->userid = $USER->id;
  109. $treerecord->groupid = $groupid;
  110. $treerecord->operatorid = 'hierarchize';
  111. $treerecord->itemdest = 0;
  112. $treerecord->intvalue = $maxordering + 1;
  113. $treerecord->timemodified = time();
  114. foreach($diff as $adif){
  115. $treerecord->itemsource = $adif->id;
  116. if (!insert_record('brainstorm_operatordata', $treerecord)){
  117. error("Could not insert tree regeneration records");
  118. }
  119. $treerecord->intvalue++;
  120. }
  121. }
  122. }
  123. /**
  124. *
  125. * @param int $brainstormid
  126. * @param object $cm
  127. * @param int $userid
  128. * @param int $groupid
  129. * @param boolean $excludemyself
  130. * @param int $fatherid
  131. * @param string $prefix
  132. * @param int $indent
  133. * @param boolean $editing
  134. */
  135. function hierarchize_print_level($brainstormid, $cm, $userid, $groupid, $excludemyself, $fatherid, $prefix, $indent, $configdata, $editing=true){
  136. global $CFG;
  137. $subs = hierarchize_get_childs($brainstormid, $userid, $groupid, $excludemyself, $fatherid);
  138. if (!empty($subs)){
  139. $i = 0;
  140. $indent += 25;
  141. $level = $indent / 25;
  142. $subscount = 0;
  143. foreach($subs as $sub){
  144. $levelprefix = $prefix . '.' . ($i + 1);
  145. ?>
  146. <tr>
  147. <?php
  148. if ($editing){
  149. $up = ($i) ? "<a href=\"view.php?id={$cm->id}&amp;operator=hierarchize&amp;what=up&amp;item={$sub->odid}\"><img src=\"{$CFG->pixpath}/t/up.gif\"></a>" : '' ;
  150. $down = ($i < count($subs) - 1) ? "<a href=\"view.php?id={$cm->id}&amp;operator=hierarchize&amp;what=down&amp;item={$sub->odid}\"><img src=\"{$CFG->pixpath}/t/down.gif\"></a>" : '' ;
  151. $left = ($indent > 25) ? "<a href=\"view.php?id={$cm->id}&amp;operator=hierarchize&amp;what=left&amp;item={$sub->odid}\"><img src=\"{$CFG->pixpath}/t/left.gif\"></a>" : '' ;
  152. if ((isset($configdata->maxarity) && $configdata->maxarity && $subscount >= $configdata->maxarity) || (isset($configdata->maxlevels) && $configdata->maxlevels && $level >= $configdata->maxlevels)){
  153. $right = '';
  154. }
  155. else{
  156. $right = ($i) ? "<a href=\"view.php?id={$cm->id}&amp;operator=hierarchize&amp;what=right&amp;item={$sub->odid}\"><img src=\"{$CFG->pixpath}/t/right.gif\"></a>" : '' ;
  157. }
  158. ?>
  159. <td>
  160. <table cellspacing="3">
  161. <tr>
  162. <td width="10">
  163. <?php echo $left ?>
  164. </td>
  165. <td width="10">
  166. <?php echo $up ?>
  167. </td>
  168. <td width="10">
  169. <?php echo $down ?>
  170. </td>
  171. <td width="10">
  172. <?php echo $right ?>
  173. </td>
  174. </tr>
  175. </table>
  176. </td>
  177. <?php
  178. }
  179. ?>
  180. <td style="text-align : right; padding-right : <?php echo $indent - 23; ?>px" class="response">
  181. <b><?php echo $levelprefix ?>.</b> <?php echo $sub->response; ?>
  182. </td>
  183. </tr>
  184. <?php
  185. hierarchize_print_level($brainstormid, $cm, $userid, $groupid, $excludemyself, $sub->odid, $levelprefix, $indent, $configdata, $editing);
  186. $i++;
  187. $subscount = brainstorm_count_subs($sub->odid); // get subs status of previous entry
  188. }
  189. }
  190. }
  191. /**
  192. *
  193. * @param int $brainstormid
  194. * @param object $cm
  195. * @param int $userid
  196. * @param int $groupid
  197. * @param boolean $excludemyself
  198. * @param string $previouslevel
  199. */
  200. function hierarchize_print_levelindeepness($brainstormid, $cm, $userid=null, $groupid=0, $excludemyself=false, $fatherid=0){
  201. global $CFG;
  202. $subs = hierarchize_get_childs($brainstormid, $userid, $groupid, $excludemyself, $fatherid);
  203. $accessClause = brainstorm_get_accessclauses($userid, $groupid, false);
  204. if (!empty($subs)){
  205. // get column spanning counts
  206. $idlist = join("','", array_keys($subs));
  207. echo '<tr valign="top">';
  208. foreach($subs as $sub){
  209. echo '<td class="subtree">';
  210. echo $sub->response;
  211. echo '<br/><table width="100%">';
  212. hierarchize_print_levelindeepness($brainstormid, $cm, $userid, $groupid, $excludemyself, $sub->odid);
  213. echo '</table>';
  214. echo '</td>';
  215. }
  216. echo '</tr>';
  217. }
  218. }
  219. /**
  220. *
  221. *
  222. */
  223. function hierarchize_display(&$brainstorm, $userid, $groupid){
  224. $tree = hierarchize_get_childs($brainstorm->id, $userid, $groupid);
  225. ?>
  226. <center>
  227. <style>
  228. .response{ font-size : 1.2em ; border : 1px solid gray }
  229. .subtree{ font-size : 1.0em ; border : 1px solid gray }
  230. </style>
  231. <?php
  232. if ($tree){
  233. echo '<table width="80%">';
  234. hierarchize_print_levelindeepness($brainstorm->id, $brainstorm->cm, $userid, $groupid, 0);
  235. echo '</table>';
  236. }
  237. else{
  238. echo get_string('notreeset','brainstorm');
  239. }
  240. ?>
  241. </center>
  242. <?php
  243. }
  244. ?>