Source for file createnewtype.act.php

Documentation is available at createnewtype.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: createnewtype.act.php,v 1.5 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 createnewtypeAction
  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 type 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 Type.");
  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 Type.");
  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 = "createnewtypeWizard";
  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(_("Please choose the name and type for this type:"));
  83. // Create the type chooser.
  84. $select = new WSelectList();
  85. //$select->addOption('',"Canonical Course Type");
  86. $select->addOption('can',"Canonical Course Type");
  87. $select->addOption('can_stat',"Canonical Course Status Type");
  88. $select->addOption('offer',"Course Offering Type");
  89. $select->addOption('offer_stat',"Course Offering Status Type");
  90. $select->addOption('section',"Course Section Type");
  91. $select->addOption('section_stat',"Course Section Status Type");
  92. $select->addOption('enroll_stat',"Enrollment Status Type");
  93. $select->addOption('grade',"Course Grading Type");
  94. $select->addOption('term',"Term Type");
  95. //$select->setValue('');
  96. $typeProp =$step->addComponent("typetype", $select);
  97. //$typeProp->setErrorText("<nobr>"._("A value for this field is required.")."</nobr>");
  98. //$typeProp->setErrorRule(new WECNonZeroRegex("[\\w]+"));
  99. // Create the title
  100. $titleProp =$step->addComponent("keyword", new WTextField());
  101. $titleProp->setErrorText("<nobr>"._("A value for this field is required.")."</nobr>");
  102. $titleProp->setErrorRule(new WECNonZeroRegex("[\\w]+"));
  103. // Create the description
  104. $descriptionProp =$step->addComponent("description", WTextArea::withRowsAndColumns(10,30));
  105. // Create the step text
  106. ob_start();
  107. print "\n<font size=+2><h2>"._("Type creator")."</h2></font>";
  108. print "\n<h2>"._("Type")."</h2>";
  109. print "\n"._("Please choose a type of <em>type</em> to create: ");
  110. print "\n<br />[[typetype]]";
  111. print "\n<h2>"._("Keyword")."</h2>";
  112. print "\n"._("The keyword of the <em>type</em>: ");
  113. print "\n<br />[[keyword]]";
  114. print "\n<h2>"._("Description")."</h2>";
  115. print "\n"._("The optional description of the <em>type</em>: ");
  116. print "\n<br />[[description]]";
  117. print "\n<div style='width: 400px'> &nbsp; </div>";
  118. $step->setContent(ob_get_contents());
  119. ob_end_clean();
  120. return $wizard;
  121. }
  122. /**
  123. * Save our results. Tearing down and unsetting the Wizard is handled by
  124. * in {@link runWizard()} and does not need to be implemented here.
  125. *
  126. * @param string $cacheName
  127. * @return boolean TRUE if save was successful and tear-down/cleanup of the
  128. * Wizard should ensue.
  129. * @access public
  130. * @since 4/28/05
  131. */
  132. function saveWizard ( $cacheName ) {
  133. $wizard =$this->getWizard($cacheName);
  134. // Make sure we have a valid Repository
  135. $courseManager = Services::getService("CourseManagement");
  136. $idManager = Services::getService("Id");
  137. $courseManagementId =$idManager->getId("edu.middlebury.coursemanagement");
  138.  
  139. // First, verify that we chose a parent that we can add children to.
  140. $authZ = Services::getService("AuthZ");
  141. if ($authZ->isUserAuthorized(
  142. $idManager->getId("edu.middlebury.authorization.add_children"),
  143. $courseManagementId))
  144. {
  145. $values = $wizard->getAllValues();
  146. printpre($values);
  147. $type = new Type("CourseManagement", "edu.middlebury",$values['namedescstep']['keyword'],
  148. $values['namedescstep']['description']);
  149. $courseManager->_typeToIndex($values['namedescstep']['typetype'], $type);
  150. RequestContext::sendTo($this->getReturnUrl());
  151. exit();
  152. return TRUE;
  153. }
  154. // If we don't have authorization to add to the picked parent, send us back to
  155. // that step.
  156. else {
  157. return FALSE;
  158. }
  159. }
  160. /**
  161. * Return the URL that this action should return to when completed.
  162. *
  163. * @return string
  164. * @access public
  165. * @since 4/28/05
  166. */
  167. function getReturnUrl () {
  168. $harmoni = Harmoni::instance();
  169. $url =$harmoni->request->mkURL("admin", "main");
  170. return $url->write();
  171. }
  172. }
  173.  
  174. ?>

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