Source for file DataManagerPrimativesModule.class.php

Documentation is available at DataManagerPrimativesModule.class.php

  1. <?php
  2. /**
  3. *
  4. * @package polyphony.repository.inputoutput
  5. *
  6. * @copyright Copyright &copy; 2005, Middlebury College
  7. * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License (GPL)
  8. *
  9. * @version $Id: DataManagerPrimativesModule.class.php,v 1.13 2007/09/19 14:04:48 adamfranco Exp $
  10. */
  11.  
  12. /**
  13. * Require the class we are extending
  14. *
  15. */
  16. require_once(dirname(__FILE__)."/../RepositoryInputOutputModule.interface.php");
  17. require_once(POLYPHONY."/main/library/DataManagerGUI/PrimitiveIO/inc.php");
  18.  
  19. /**
  20. * InputOutput modules are classes which generate HTML for the display or editing
  21. * of Records. Which InputOutput module to use is determined by the Type
  22. * of the RecordStructure corresponding to that Record. For example, a Structure
  23. * using the "DataManagerPrimitive" Type would use the DataManagerPrimative
  24. * InputOutput module for displaying generating forms for editing its data.
  25. *
  26. * @package polyphony.repository.inputoutput
  27. * @version $Id: DataManagerPrimativesModule.class.php,v 1.13 2007/09/19 14:04:48 adamfranco Exp $
  28. * @since $Date: 2007/09/19 14:04:48 $
  29. * @copyright 2004 Middlebury College
  30. */
  31.  
  32. class DataManagerPrimativesModule
  33. extends RepositoryInputOutputModuleInterface {
  34. /**
  35. * Constructor
  36. *
  37. * @return obj
  38. * @access public
  39. * @since 10/19/04
  40. */
  41. function DataManagerPrimativesModule () {
  42. }
  43. /**
  44. * Create wizard steps for editing the values of the specified Record and
  45. * add them to the wizard.
  46. *
  47. * @param object $record
  48. * @param object $wizard The wizard to add the steps to.
  49. * @param array $partStructures An ordered array of the partStructures to include.
  50. * @return void
  51. * @access public
  52. * @since 10/19/04
  53. */
  54. function createWizardStepsForPartStructures ( $record, $wizard, $partStructures ) {
  55. ArgumentValidator::validate($record, ExtendsValidatorRule::getRule("RecordInterface"));
  56. ArgumentValidator::validate($wizard, ExtendsValidatorRule::getRule("Wizard"));
  57. ArgumentValidator::validate($partStructures, ArrayValidatorRuleWithRule::getRule(ExtendsValidatorRule::getRule("PartStructure")));
  58. $recordStructure =$record->getRecordStructure();
  59. $recordStructureId =$recordStructure->getId();
  60. /* build an interface for editing this record! */
  61. $m = '';
  62.  
  63. $step =$wizard->addStep("record", new WizardStep());
  64. $step->setDisplayName(dgettext("polyphony","Edit Record"));
  65. // Go through each of the PartStructures and create a component for it
  66. foreach (array_keys($partStructures) as $key) {
  67. $partStructure =$partStructures[$key];
  68. $m .= $this->_addComponentForPartStructure($step, $record, $partStructure);
  69. $m .= "<br/>";
  70. }
  71.  
  72. $step->setContent($m);
  73.  
  74. }
  75. /**
  76. * Create wizard steps for editing the values of the specified Record and
  77. * add them to the wizard.
  78. *
  79. * @param object $record
  80. * @param object $wizard The wizard to add the steps to.
  81. * @return void
  82. * @access public
  83. * @since 10/19/04
  84. */
  85. function createWizardSteps ( $record, $wizard ) {
  86. ArgumentValidator::validate($record, new ExtendsValidatorRule("RecordInterface"));
  87. $recordStructure =$record->getRecordStructure();
  88. $recordStructureId =$recordStructure->getId();
  89. // Get all the partStrucutres
  90. $partStructureIterator =$recordStructure->getPartStructures();
  91. $partStructures = array();
  92. while($partStructureIterator->hasNext()) {
  93. $partStructures[] =$partStructureIterator->next();
  94. }
  95. $this->createWizardStepsForPartStructures($record, $wizard, $partStructures);
  96. }
  97. /**
  98. * Get the values submitted in the wizard and update the Record with them.
  99. *
  100. * @param object $record
  101. * @param object $wizard
  102. * @return void
  103. * @access public
  104. * @since 10/19/04
  105. */
  106. function updateFromWizard ( $record, $wizard ) {
  107. $recordStructure =$record->getRecordStructure();
  108. $recordStructureId =$recordStructure->getId();
  109. $properties =$wizard->getAllValues();
  110. $values =$properties["record"];
  111. // Delete the old parts
  112. $parts =$record->getParts();
  113. while ($parts->hasNext()) {
  114. $part =$parts->next();
  115. $partId =$part->getId();
  116. $record->deletePart($partId);
  117. }
  118. $parts =$record->getParts();
  119. if ($parts->hasNext()) print "have a part!!!"; // debug
  120. // Go through each of the partStructures and save any values as parts.
  121. $partStructures = $recordStructure->getPartStructures();
  122. while ($partStructures->hasNext()) {
  123. $partStructure =$partStructures->next();
  124. $partStructureId =$partStructure->getId();
  125. $partStructureType = $partStructure->getType();
  126. $valueObjClass =$partStructureType->getKeyword();
  127. $id = str_replace(".","_",$partStructureId->getIdString());
  128. if ($partStructure->isRepeatable()) {
  129. // Add a part for each property
  130. foreach (array_keys($values[$id]) as $valueIndex) {
  131. $value =$values[$id][$valueIndex]["value"];
  132. $newPart =$record->createPart($partStructureId, $value);
  133. }
  134. } else {
  135. // Add a part for the property
  136. $value =$values[$id];
  137. $newPart =$record->createPart($partStructureId, $value);
  138. }
  139. }
  140. }
  141.  
  142. /**
  143. * Generate HTML for displaying the Record
  144. *
  145. * @param object $record
  146. * @return string
  147. * @access public
  148. * @since 10/19/04
  149. */
  150. function generateDisplay ( $repositoryId, $assetId, $record ) {
  151. ArgumentValidator::validate($repositoryId, new ExtendsValidatorRule("Id"));
  152. ArgumentValidator::validate($assetId, new ExtendsValidatorRule("Id"));
  153. ArgumentValidator::validate($record, new ExtendsValidatorRule("RecordInterface"));
  154. // Get all the partstructures
  155. $recordStructure =$record->getRecordStructure();
  156. $partStructureIterator =$recordStructure->getPartStructures();
  157. $partStructures = array();
  158. while($partStructureIterator->hasNext()) {
  159. $partStructures[] =$partStructureIterator->next();
  160. }
  161. return $this->generateDisplayForPartStructure($asset, $record, $partStructures);
  162. }
  163.  
  164. /**
  165. * Generate HTML for displaying particular parts of the Record
  166. *
  167. * @param object $record The record to print.
  168. * @param array $partStructures An array of particular partstructures to print.
  169. * @return string
  170. * @access public
  171. * @since 10/19/04
  172. */
  173. function generateDisplayForPartStructures ( $repositoryId, $assetId, $record, $partStructures ) {
  174. ArgumentValidator::validate($repositoryId, new ExtendsValidatorRule("Id"));
  175. ArgumentValidator::validate($assetId, new ExtendsValidatorRule("Id"));
  176. ArgumentValidator::validate($record, new ExtendsValidatorRule("RecordInterface"));
  177. ArgumentValidator::validate($partStructures, new ArrayValidatorRuleWithRule(new ExtendsValidatorRule("PartStructure")));
  178.  
  179. $partIterator =$record->getParts();
  180. $parts = array();
  181. while($partIterator->hasNext()) {
  182. $part =$partIterator->next();
  183. $partStructure =$part->getPartStructure();
  184. $partStructureId =$partStructure->getId();
  185. if (!isset($parts[$partStructureId->getIdString()]) || !is_array($parts[$partStructureId->getIdString()]))
  186. $parts[$partStructureId->getIdString()] = array();
  187. $parts[$partStructureId->getIdString()][] =$part;
  188. }
  189. // print out the parts;
  190. ob_start();
  191. foreach (array_keys($partStructures) as $key) {
  192. $partStructure =$partStructures[$key];
  193. $partStructureId =$partStructure->getId();
  194. if(isset($parts[$partStructureId->getIdString()])) {
  195. if (is_array($parts[$partStructureId->getIdString()])) {
  196. foreach (array_keys($parts[$partStructureId->getIdString()]) as $key) {
  197. $part =$parts[$partStructureId->getIdString()][$key];
  198. $value =$part->getValue();
  199. print "\n<strong>".$partStructure->getDisplayName().":</strong> \n";
  200. print $value->asString();
  201. print "\n<br />";
  202. }
  203. }
  204. }
  205. }
  206. $html = ob_get_contents();
  207. ob_end_clean();
  208. return $html;
  209. }
  210.  
  211. /**
  212. * Returns the a string for the passed part structure corresponding to a {@link WizardComponent} that is added automatically.
  213. *
  214. * @param object WizardStep $wizard The wizard step to add components.
  215. * @param object Record $record The Record to modify.
  216. * @param object PartStructure $partStructure The partStructure to add the step for.
  217. * @return string
  218. * @access public
  219. * @since 8/30/04
  220. */
  221. function _addComponentForPartStructure ($wizardStep, $record, $partStructure) {
  222. $partStructureId =$partStructure->getId();
  223. $partStructureType =$partStructure->getType();
  224. $parts =$record->getPartsByPartStructure($partStructureId);
  225. // get the display name
  226. $name = $partStructure->getDisplayName();
  227. // get the id
  228. $id = str_replace(".","_",$partStructureId->getIdString());
  229. // get the datamanager data type
  230. $dataType = $partStructureType->getKeyword();
  231. // get the correct component for this data type
  232. $component = PrimitiveIOManager::createComponent($dataType);
  233. if (!$component) return '';
  234. $m = '';
  235. if ($partStructure->isRepeatable()) {
  236. // replace $component with a wrapper.
  237. $mult = new WRepeatableComponentCollection();
  238. $mult->setElementLayout("[[value]]");
  239. $mult->addComponent("value", $component);
  240. $mult->setStartingNumber(0);
  241. $mult->setAddLabel(dgettext("polyphony", "Add New ")
  242. .$partStructure->getDisplayName());
  243. $mult->setRemoveLabel(dgettext("polyphony", "Remove ")
  244. .$partStructure->getDisplayName());
  245. $component =$mult;
  246. $m = "<table border='0'><tr><td valign='top'><b>$name</b>:</td><td valign='top'>[[$id]]</td></tr></table>";
  247. // set our values
  248. while($parts->hasNext()) {
  249. $part =$parts->next();
  250. $collection = array();
  251. $collection['value'] =$part->getValue();
  252. $component->addValueCollection($collection);
  253. unset($collection);
  254. }
  255. } else {
  256. $m = "<b>$name</b>: [[$id]]";
  257. // set the default value.
  258. if ($parts->hasNext()) {
  259. $part =$parts->next();
  260. $value =$part->getValue();
  261. $component->setValue($value);
  262. }
  263. }
  264. // add the component
  265. $wizardStep->addComponent($id, $component);
  266. return $m;
  267. /* THIS CODE IS OLD
  268. // Switch for any special partStructure types
  269. switch (TRUE) {
  270. // default Works for most part types
  271. default:
  272. $property =$step->createProperty(strval($partStructureId->getIdString()),
  273. new AlwaysTrueValidatorRule,
  274. $partStructure->isMandatory());
  275. ob_start();
  276. print "\n<em>".$partStructure->getDescription()."</em>\n<hr />";
  277. print "\n<br /><strong>".$partStructure->getDisplayName()."</strong>:";
  278. print " <input type='text'";
  279. print " name='".$partStructureId->getIdString()."'";
  280. print " value='[[".$partStructureId->getIdString()."]]' /> ";
  281. print " [[".$partStructureId->getIdString()."|Error]]";
  282. if ($partStructure->isRepeatable()) {
  283. print "\n<br />[Buttons] <em>"._("Click here to save the value above.")."</em>";
  284. print "\n<br /><hr />";
  285. print _("Already Added:");
  286. print "\n<table>";
  287. print "[List]\n<tr>";
  288. print "\n<td valign='top'>[ListButtons]<br />[ListMoveButtons]</td>";
  289. print "\n<td style='padding-bottom: 20px'>";
  290. print "\n\t<strong>".$partStructure->getDisplayName().":</strong>"
  291. ." [[".$partStructureId->getIdString()."]]";
  292. print "</td>\n</tr>[/List]\n</table>";
  293. }
  294. $step->setText(ob_get_contents());
  295. ob_end_clean();
  296. // If we have parts, load their values as the defaults.
  297. while ($parts->hasNext()) {
  298. $part =$parts->next();
  299. $currentPartStructure =$part->getPartStructure();
  300. if ($partStructureId->isEqual($currentPartStructure->getId())) {
  301. $valueObj =$part->getValue();
  302. $property->setValue($valueObj->asString());
  303. if ($partStructure->isRepeatable()) {
  304. $step->saveCurrentPropertiesAsNewSet();
  305. } else {
  306. break;
  307. }
  308. }
  309. }
  310. }
  311. */
  312. }
  313. }
  314.  
  315. ?>

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