Source for file add_group.act.php

Documentation is available at add_group.act.php

  1. <?php
  2.  
  3. /**
  4. * @package polyphony.agents
  5. * @copyright Copyright &copy; 2005, Middlebury College
  6. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  7. * @version $Id: add_group.act.php,v 1.9 2007/09/19 14:04:52 adamfranco Exp $
  8. ***/
  9.  
  10. require_once(POLYPHONY."/main/library/AbstractActions/MainWindowAction.class.php");
  11.  
  12. /**
  13. * Allows the addition of a group using a Wizard interface.
  14. *
  15. * @package polyphony.agents
  16. * @copyright Copyright &copy; 2005, Middlebury College
  17. * @author Gabriel Schine
  18. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  19. * @version $Id: add_group.act.php,v 1.9 2007/09/19 14:04:52 adamfranco Exp $
  20. */
  21. class add_groupAction extends MainWindowAction
  22. {
  23. /**
  24. * Check Authorizations
  25. *
  26. * @return boolean
  27. * @access public
  28. * @since 4/26/05
  29. */
  30. function isAuthorizedToExecute () {
  31. // Check that the user can create an asset here.
  32. $authZ = Services::getService("AuthZ");
  33. $idManager = Services::getService("Id");
  34.  
  35. return $authZ->isUserAuthorized(
  36. $idManager->getId("edu.middlebury.authorization.add_children"),
  37. $idManager->getId("edu.middlebury.agents.all_groups"));
  38. }
  39.  
  40. /**
  41. * Return the "unauthorized" string to pring
  42. *
  43. * @return string
  44. * @access public
  45. * @since 4/26/05
  46. */
  47. function getUnauthorizedMessage () {
  48. return _("You are not authorized to create <em>Groups</em>.");
  49. }
  50.  
  51. /**
  52. * Build the content for this action
  53. *
  54. * @return void
  55. * @access public
  56. * @since 4/26/05
  57. */
  58. function buildContent () {
  59. $harmoni = Harmoni::instance();
  60. $centerPane =$this->getActionRows();
  61. $cacheName = 'create_group_wizard';
  62. // $this->cancelWizard($cacheName);
  63. $this->runWizard ( $cacheName, $centerPane );
  64. }
  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.  
  76. // Instantiate the wizard, then add our steps.
  77. ob_start();
  78. print "<h2>"._("Create Group")."</h2>";
  79. print "<b>"._("Display name")."</b>: [[display_name]]<br/>";
  80. print "<b>"._("Description")." ("._("optional").")"."</b>: <br/>[[description]] <br/>";
  81. print "<b>"._("Type")."</b>: [[type]] ("._("or use fields below to create a new type").")<br/>";
  82. print "<br/>";
  83. print "<b>"._("Type domain")."</b>: [[type_domain]]<br/>";
  84. print "<b>"._("Type authority")."</b>: [[type_authority]]<br/>";
  85. print "<b>"._("Type keyword")."</b>: [[type_keyword]]<br/>";
  86. print "<b>"._("Type description")."</b>:<br/> [[type_description]]<br/>";
  87. print "<div align='right'>[[_cancel]]\n[[_save]]</div>";
  88. print "[[members]]";
  89. if (RequestContext::value("agents") && count(($list=unserialize(RequestContext::value("agents")))) > 0 && is_array($list)) {
  90. // print out a list of agents
  91. print "<div>"._("The group will be created with the following members:")."<ul>\n";
  92. $agentManager = Services::getService("Agent");
  93. $idManager = Services::getService("Id");
  94. foreach ($list as $idString) {
  95. $id =$idManager->getId($idString);
  96. if ($agentManager->isGroup($id)) {
  97. $agent =$agentManager->getGroup($id);
  98. $name = _("Group").": ".$agent->getDisplayName();
  99. } else if ($agentManager->isAgent($id)) {
  100. $agent =$agentManager->getAgent($id);
  101. $name = _("Agent").": ".$agent->getDisplayName();
  102. }
  103. print "<li>$name</li>\n";
  104. }
  105. print "</ul></div>";
  106. }
  107. $wizard = SimpleWizard::withText(ob_get_contents());
  108. ob_end_clean();
  109.  
  110. // Create the properties.
  111. $displayNameProp =$wizard->addComponent("display_name", new WTextField());
  112. $displayNameProp->setErrorText(_("A value for this field is required."));
  113. $displayNameProp->setErrorRule(new WECNonZeroRegex("[\\w]+"));
  114.  
  115. $descriptionProp =$wizard->addComponent("description", WTextArea::withRowsAndColumns(3,50));
  116.  
  117. $property =$wizard->addComponent("type", new WSelectList());
  118. $property->addOption("NONE", _("Use Fields Below..."));
  119. $agentMgr = Services::getService("Agent");
  120. $types =$agentMgr->getGroupTypes();
  121. while ($types->hasNext()) {
  122. $type =$types->next();
  123. $typeKey = urlencode(HarmoniType::typeToString($type));
  124. $property->addOption($typeKey, HarmoniType::typeToString($type));
  125. }
  126. $property->setValue("NONE");
  127.  
  128. $property =$wizard->addComponent("type_domain", new WTextField());
  129. $property->setStartingDisplayText(_("Domain, i.e. 'groups'"));
  130.  
  131. $property =$wizard->addComponent("type_authority", new WTextField());
  132. $property->setStartingDisplayText(_("Authority, i.e. 'edu.middlebury'"));
  133.  
  134. $property =$wizard->addComponent("type_keyword", new WTextField());
  135. $property->setStartingDisplayText(_("Keyword, i.e 'classes"));
  136. $property =$wizard->addComponent("type_description", WTextArea::withRowsAndColumns(3, 50));
  137. $wizard->addComponent("_save", WSaveButton::withLabel(_("Create Group")));
  138. $wizard->addComponent("_cancel", new WCancelButton());
  139. $members =$wizard->addComponent("members", new WHiddenField());
  140. if (RequestContext::value("agents")) {
  141. // the members of the group to be created. an array of agent ids
  142. $members->setValue(RequestContext::value("agents"));
  143. }
  144.  
  145. return $wizard;
  146. }
  147.  
  148. /**
  149. * Save our results. Tearing down and unsetting the Wizard is handled by
  150. * in {@link runWizard()} and does not need to be implemented here.
  151. *
  152. * @param string $cacheName
  153. * @return boolean TRUE if save was successful and tear-down/cleanup of the
  154. * Wizard should ensue.
  155. * @access public
  156. * @since 4/28/05
  157. */
  158. function saveWizard ( $cacheName ) {
  159. $wizard =$this->getWizard($cacheName);
  160.  
  161. if (!$wizard->validate()) return false;
  162.  
  163. // Make sure we have a valid Repository
  164. $idManager = Services::getService("Id");
  165. $authZ = Services::getService("AuthZ");
  166.  
  167. $properties =$wizard->getAllValues();
  168.  
  169. // check if they entered a valid type.
  170. if ($properties["type"] == "NONE") {
  171. $domain = $properties["type_domain"];
  172. $authority = $properties["type_authority"];
  173. $keyword = $properties["type_keyword"];
  174. if (!($domain && $authority && $keyword)) return false;
  175. $desc = $properties["type_description"];
  176. $theType = new Type($domain, $authority, $keyword, $desc);
  177. } else {
  178. $theType = Type::fromString(urldecode($properties["type"]));
  179. }
  180. // empty properties set
  181. $propObj = new HarmoniProperties(new Type("Properties", "edu.middlebury.polyphony", "Generic"));
  182. $agents = Services::getService("Agent");
  183. $group =$agents->createGroup($properties["display_name"], $theType, $properties["description"], $propObj);
  184. if ($properties["members"] && count(($list=unserialize($properties["members"]))) > 0) {
  185. $ids = Services::getService("Id");
  186. $agents = Services::getService("Agent");
  187. foreach ($list as $agentId) {
  188. $id =$ids->getId($agentId);
  189. if ($agents->isGroup($id)) {
  190. $agent =$agents->getGroup($id);
  191. } else if ($agents->isAgent($id)) {
  192. $agent =$agents->getAgent($id);
  193. }
  194. $group->add($agent);
  195. }
  196. }
  197. return true;
  198. }
  199.  
  200. /**
  201. * Return the URL that this action should return to when completed.
  202. *
  203. * @return string
  204. * @access public
  205. * @since 4/28/05
  206. */
  207. function getReturnUrl () {
  208. $harmoni = Harmoni::instance();
  209. $url = $harmoni->history->getReturnURL("polyphony/agents/add_group");
  210. if (!$url) $url = $harmoni->request->quickURL("agents","add_delete_group");
  211. return $url;
  212. }
  213. } // END class add_groupAction
  214.  
  215. ?>

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