Source for file createnewterm.act.php

Documentation is available at createnewterm.act.php

  1. <?php
  2. /**
  3. * @package polyphony.coursemanagement
  4. *
  5. * @copyright Copyright &copy; 2006, Middlebury College
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  7. *
  8. * @version $Id: createnewterm.act.php,v 1.4 2007/09/19 14:04:54 adamfranco Exp $
  9. */
  10.  
  11. require_once(POLYPHONY."/main/library/AbstractActions/MainWindowAction.class.php");
  12. require_once(HARMONI."/utilities/StatusStars.class.php");
  13.  
  14. class createnewtermAction
  15. extends MainWindowAction
  16. {
  17. /**
  18. * Check Authorizations
  19. *
  20. * @return boolean
  21. * @access public
  22. * @since 4/26/05
  23. */
  24. function isAuthorizedToExecute () {
  25. // Check that the user can create a term here.
  26. $authZ = Services::getService("AuthZ");
  27. $idManager = Services::getService("Id");
  28. return $authZ->isUserAuthorized(
  29. $idManager->getId("edu.middlebury.authorization.add_children"),
  30. $idManager->getId("edu.middlebury.coursemanagement")
  31. );
  32. }
  33. /**
  34. * Return the "unauthorized" string to pring
  35. *
  36. * @return string
  37. * @access public
  38. * @since 4/26/05
  39. */
  40. function getUnauthorizedMessage () {
  41. return _("You are not authorized to create a CourseManagement Term.");
  42. }
  43. /**
  44. * Return the heading text for this action, or an empty string.
  45. *
  46. * @return string
  47. * @access public
  48. * @since 4/26/05
  49. */
  50. function getHeadingText () {
  51. return _("Create a Term.");
  52. }
  53. /**
  54. * Build the content for this action
  55. *
  56. * @return void
  57. * @access public
  58. * @since 4/26/05
  59. */
  60. function buildContent () {
  61. $harmoni = Harmoni::instance();
  62. $actionRows =$this->getActionRows();
  63. $cacheName = "createnewtermWizard";
  64. $this->runWizard ( $cacheName, $actionRows );
  65. }
  66. /**
  67. * Create a new Wizard for this action. Caching of this Wizard is handled by
  68. * {@link getWizard()} and does not need to be implemented here.
  69. *
  70. * @return object Wizard
  71. * @access public
  72. * @since 4/28/05
  73. */
  74. function createWizard () {
  75. $harmoni = Harmoni::instance();
  76. //$courseManager = Services::getService("CourseManagement");
  77. //$canonicalCourseIterator =$courseManager->getCanonicalCourses();
  78. // Instantiate the wizard, then add our steps.
  79. $wizard = SimpleStepWizard::withDefaultLayout();
  80. // :: Name and Description ::
  81. $step =$wizard->addStep("namedescstep", new WizardStep());
  82. $step->setDisplayName(_("Select options for the new term:"));
  83. //displayname
  84. $titleProp =$step->addComponent("displayname", new WTextField());
  85. $titleProp->setErrorText("<nobr>"._("A value for this field is required.")."</nobr>");
  86. $titleProp->setErrorRule(new WECNonZeroRegex("[\\w]+"));
  87. // Create the type chooser.
  88. $select = new WSelectList();
  89. $typename = "term";
  90. $dbHandler = Services::getService("DBHandler");
  91. $query= new SelectQuery;
  92. $query->addTable('cm_'.$typename."_type");
  93. $query->addColumn('id');
  94. $query->addColumn('keyword');
  95. $res=$dbHandler->query($query);
  96. while($res->hasMoreRows()){
  97. $row = $res->getCurrentRow();
  98. $res->advanceRow();
  99. $select->addOption($row['id'],$row['keyword']);
  100. }
  101. $typeProp =$step->addComponent("termtype", $select);
  102. //$courseManager = Services::getService("CourseManagement");
  103. //$select->addOption('',"Canonical Course Type");
  104. /*$select->addOption('can',"Canonical Course Type");
  105. $select->addOption('can_stat',"Canonical Course Status Type");
  106. $select->addOption('offer',"Course Offering Type");
  107. $select->addOption('offer_stat',"Course Offering Status Type");
  108. $select->addOption('section',"Course Section Type");
  109. $select->addOption('section_stat',"Course Section Status Type");
  110. $select->addOption('enroll_stat',"Enrollment Status Type");
  111. $select->addOption('grade',"Course Grading Type");
  112. $select->addOption('term',"Term Type");*/
  113. //$select->setValue('');
  114. //$typeProp->setErrorText("<nobr>"._("A value for this field is required.")."</nobr>");
  115. //$typeProp->setErrorRule(new WECNonZeroRegex("[\\w]+"));
  116. // Create the display name
  117. // Create the step text
  118. ob_start();
  119. print "\n<font size=+2><h2>"._("Term creator")."</h2></font>";
  120. print "\n<h2>"._("Keyword")."</h2>";
  121. print "\n"._("The name of the <em>term</em>: ");
  122. print "\n<br />[[displayname]]";
  123. print "\n<h2>"._("Type")."</h2>";
  124. print "\n"._("Please choose a type of <em>term</em>: ");
  125. print "\n<br />[[termtype]]";
  126. print "\n<div style='width: 400px'> &nbsp; </div>";
  127. $step->setContent(ob_get_contents());
  128. ob_end_clean();
  129. return $wizard;
  130. }
  131. /**
  132. * Save our results. Tearing down and unsetting the Wizard is handled by
  133. * in {@link runWizard()} and does not need to be implemented here.
  134. *
  135. * @param string $cacheName
  136. * @return boolean TRUE if save was successful and tear-down/cleanup of the
  137. * Wizard should ensue.
  138. * @access public
  139. * @since 4/28/05
  140. */
  141. function saveWizard ( $cacheName ) {
  142. $wizard =$this->getWizard($cacheName);
  143. // Make sure we have a valid Repository
  144. $courseManager = Services::getService("CourseManagement");
  145. $idManager = Services::getService("Id");
  146. $courseManagementId =$idManager->getId("edu.middlebury.coursemanagement");
  147.  
  148. // First, verify that we chose a parent that we can add children to.
  149. $authZ = Services::getService("AuthZ");
  150. if ($authZ->isUserAuthorized(
  151. $idManager->getId("edu.middlebury.authorization.add_children"),
  152. $courseManagementId))
  153. {
  154. $values = $wizard->getAllValues();
  155. printpre($values);
  156. $type =$courseManager->_indexToType($values['namedescstep']['termtype'],'term');
  157. $schedule = null;
  158. $term =$courseManager->createTerm($type,$schedule);
  159. $term->updateDisplayName($values['namedescstep']['displayname']);
  160. RequestContext::sendTo($this->getReturnUrl());
  161. exit();
  162. return TRUE;
  163. }
  164. // If we don't have authorization to add to the picked parent, send us back to
  165. // that step.
  166. else {
  167. return FALSE;
  168. }
  169. }
  170. /**
  171. * Return the URL that this action should return to when completed.
  172. *
  173. * @return string
  174. * @access public
  175. * @since 4/28/05
  176. */
  177. function getReturnUrl () {
  178. $harmoni = Harmoni::instance();
  179. $url =$harmoni->request->mkURL("admin", "main");
  180. return $url->write();
  181. }
  182. }
  183.  
  184. ?>

Documentation generated on Wed, 19 Sep 2007 10:22:26 -0400 by phpDocumentor 1.3.0RC3