Author: david Date: Mon Dec 7 09:43:18 2009 New Revision: 4108 Log: Move ISDF relations code to component.
Added: trunk/apps/qubit/modules/function/actions/relationshipsComponent.class.php (contents, props changed) trunk/apps/qubit/modules/function/templates/_relationships.php (contents, props changed) Modified: trunk/apps/qubit/modules/function/templates/editIsdfSuccess.php Added: trunk/apps/qubit/modules/function/actions/relationshipsComponent.class.php ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/apps/qubit/modules/function/actions/relationshipsComponent.class.php Mon Dec 7 09:43:18 2009 (r4108) @@ -0,0 +1,98 @@ +<?php + +/* + * This file is part of Qubit Toolkit. + * + * Qubit Toolkit is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * Qubit Toolkit is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Qubit Toolkit. If not, see <http://www.gnu.org/licenses/>. + */ + +class FunctionRelationshipsComponent extends sfComponent +{ + public static $NAMES = array( + 'authorizedFormOfName', + 'type', + 'category', + 'description', + 'dateStart', + 'dateEnd', + 'dateDisplay' + ); + + protected function addField($name) + { + switch ($name) + { + case 'type': + $this->form->setValidator($name, new sfValidatorString); + + $choices = array(); + $choices[null] = null; + + foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::FUNCTION_ID) as $term) + { + $choices[$this->context->routing->generate(null, array('module' => 'term', 'action' => 'show', 'id' => $term->id))] = $term; + } + + $this->form->setWidget($name, new sfWidgetFormSelect(array('choices' => $choices))); + + break; + + case 'category': + $this->form->setValidator($name, new sfValidatorString); + + $choices = array(); + $choices[null] = null; + + foreach (QubitTaxonomy::getTermsById(QubitTaxonomy::ACTOR_RELATION_TYPE_ID) as $term) + { + $choices[$this->context->routing->generate(null, array('module' => 'term', 'action' => 'show', 'id' => $term->id))] = $term; + } + + $this->form->setWidget($name, new sfWidgetFormSelect(array('choices' => $choices))); + + break; + + case 'authorizedFormOfName': + case 'dateStart': + case 'dateEnd': + case 'dateDisplay': + $this->form->setValidator($name, new sfValidatorString); + $this->form->setWidget($name, new sfWidgetFormInput); + + break; + + case 'description': + $this->form->setValidator($name, new sfValidatorString); + $this->form->setWidget($name, new sfWidgetFormTextarea); + + break; + } + } + + public function execute($request) + { + $this->form = new sfForm; + //$this->form->getValidatorSchema()->setOption('allow_extra_fields', true); + + $this->relatedFunctions = QubitRelation::getRelationsBySubjectOrObjectId($this->func->id); + + // HACK: Use static::$NAMES in PHP 5.3, + // http://php.net/oop5.late-static-bindings + $class = new ReflectionClass($this); + foreach ($class->getStaticPropertyValue('NAMES') as $name) + { + $this->addField($name); + } + } +} Added: trunk/apps/qubit/modules/function/templates/_relationships.php ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ trunk/apps/qubit/modules/function/templates/_relationships.php Mon Dec 7 09:43:18 2009 (r4108) @@ -0,0 +1,115 @@ +<?php if(0 < count($relatedFunctions)): ?> +<div class="form-item"> + <table class="inline" id="relatedFunctions"> + <caption><?php echo __('Related corporate bodies, archival materials and other resources'); ?></caption> + <tr> + <th style="width: 25%"><?php echo __('name'); ?></th> + <th style="width: 15%"><?php echo __('type'); ?></th> + <th style="width: 20%"><?php echo __('dates'); ?></th> + <th style="width: 30%"><?php echo __('description'); ?></th> + <th style="width: 10%; text-align: center"><?php echo image_tag('delete', array('align' => 'top', 'class' => 'deleteIcon')) ?></th> + </tr> + <?php if (0 < count($relatedFunctions)): ?> + <?php foreach ($relatedFunctions as $relatedFunction): ?> + <tr id="<?php echo 'functionRelation_'.$relatedFunction->getId() ?>" class="<?php echo 'related_obj_'.$relatedFunction->getId() ?>"> + <?php if ($relatedFunction->getObjectId() == $func->getId()): ?> + <td><?php echo $relatedFunction->getSubject()->getAuthorizedFormOfName() ?></td> + <?php else: ?> + <td><?php echo $relatedFunction->getObject()->getAuthorizedFormOfName() ?></td> + <?php endif; ?> + <td><?php echo $relatedFunction->getType() ?></td> + <td> + <?php if (0 < strlen($dateDisplay = $relatedFunction->getNoteByTypeId(QubitTerm::RELATION_NOTE_DATE_DISPLAY_ID)) || 0 < count($dateArray = $relatedFunction->getDates())): ?> + <?php if (0 < strlen($dateDisplay)): ?> + <?php echo $dateDisplay ?> + <?php elseif (2 == count($dateArray)): ?> + <?php echo __('%1% - %2%', array('%1%' => collapse_date($dateArray['start']), '%2%' => collapse_date($dateArray['end']))) ?> + <?php else: ?> + <?php echo collapse_date(array_shift($dateArray)) ?> + <?php endif; ?> + <?php endif; ?> + </td> + <td><?php echo $relatedFunction->getNoteByTypeId(QubitTerm::RELATION_NOTE_DESCRIPTION_ID) ?></td> + <td style="text-align: center;"> + <input type="checkbox" name="deleteRelations[<?php echo $relatedFunction->getId() ?>]" value="delete" class="multiDelete" /> + </td> + </tr> + <?php endforeach; ?> + <?php endif; ?> + </table> +</div> +<?php endif; ?> + +<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * --> +<!-- NOTE: The functionRelationDialog.js script cuts this *entire* --> +<!-- "functionRelation" table and pastes it in a YUI dialog object. --> +<!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * --> +<table class="inline" id="functionRelation"> + <caption><?php echo __('new relationship') ?></caption> + <tbody> + <tr> + <th colspan="4"> + <?php echo $form->authorizedFormOfName->label('authorized form(s) of name')->renderLabel() ?> + </th> + </tr> + <tr> + <td colspan="4"> + <?php echo $form->authorizedFormOfName->render() ?> + </td> + </tr> + <tr> + <th colspan="2" style="width: 50%"> + <?php echo $form->type->renderLabel() ?> + </th> + <th colspan="2" style="width: 50%"> + <?php echo $form->category->renderLabel() ?> + </th> + </tr> + <tr> + <td colspan="2"> + <?php echo $form->type->render() ?> + </td> + <td colspan="2"> + <?php echo $form->category->render() ?> + </td> + </tr> + <tr> + <th colspan="4"> + <?php echo $form->description->renderLabel() ?> + </th> + </tr> + <tr> + <td colspan="4"> + <?php echo $form->authorizedFormOfName->render() ?> + </td> + </tr> + <tr> + <th style="width: 25%"> + <?php echo $form->dateStart->label('date†')->renderLabel() ?> + </th> + <th style="width: 25%"> + <?php echo $form->dateEnd->label('end date†')->renderLabel() ?> + </th> + <th colspan="2" style="width: 50%"> + <?php echo $form->dateDisplay->label('date display†')->renderLabel() ?> + </th> + </tr> + <tr> + <td style="width: 25%"> + <?php echo $form->dateStart->render() ?> + </td> + <td style="width: 25%"> + <?php echo $form->dateEnd->render() ?> + </td> + <td colspan="2" style="width: 50%"> + <?php echo $form->dateDisplay->render() ?> + </td> + </tr> + <tr> + <td colspan="4"> + <?php echo __('%1% - required field', array('%1%' => '*'))?><br /> + <?php echo __('%1% - dates must be specified in ISO-8601 format (YYYY-MM-DD)', array('%1%' => '†'))?> + </td> + </tr> + </tbody> +</table> Modified: trunk/apps/qubit/modules/function/templates/editIsdfSuccess.php ============================================================================== --- trunk/apps/qubit/modules/function/templates/editIsdfSuccess.php Mon Dec 7 00:12:49 2009 (r4107) +++ trunk/apps/qubit/modules/function/templates/editIsdfSuccess.php Mon Dec 7 09:43:18 2009 (r4108) @@ -62,109 +62,7 @@ <fieldset class="collapsible collapsed" id="relationshipsArea"> <legend><?php echo __('relationships area'); ?></legend> - <div class="form-item"> - <table class="inline" id="relatedEntities"> - <caption><?php echo __('Related corporate bodies, archival materials and other resources'); ?></caption> - <tr> - <th style="width: 25%"><?php echo __('name'); ?></th> - <th style="width: 15%"><?php echo __('type'); ?></th> - <th style="width: 20%"><?php echo __('dates'); ?></th> - <th style="width: 30%"><?php echo __('description'); ?></th> - <th style="width: 10%; text-align: center"><?php echo image_tag('delete', array('align' => 'top', 'class' => 'deleteIcon')) ?></th> - </tr> - <?php if (0 < count($funcRelations)): ?> - <?php foreach ($funcRelations as $funcRelation): ?> - <tr id="<?php echo 'functionRelation_'.$funcRelation->getId() ?>" class="<?php echo 'related_obj_'.$funcRelation->getId() ?>"> - <?php if ($funcRelation->getObjectId() == $func->getId()): ?> - <td><?php echo $funcRelation->getSubject()->getAuthorizedFormOfName() ?></td> - <?php else: ?> - <td><?php echo $funcRelation->getObject()->getAuthorizedFormOfName() ?></td> - <?php endif; ?> - <td><?php echo $funcRelation->getType() ?></td> - <td> - <?php if (0 < strlen($dateDisplay = $funcRelation->getNoteByTypeId(QubitTerm::RELATION_NOTE_DATE_DISPLAY_ID)) || 0 < count($dateArray = $funcRelation->getDates())): ?> - <?php if (0 < strlen($dateDisplay)): ?> - <?php echo $dateDisplay ?> - <?php elseif (2 == count($dateArray)): ?> - <?php echo __('%1% - %2%', array('%1%' => collapse_date($dateArray['start']), '%2%' => collapse_date($dateArray['end']))) ?> - <?php else: ?> - <?php echo collapse_date(array_shift($dateArray)) ?> - <?php endif; ?> - <?php endif; ?> - </td> - <td><?php echo $funcRelation->getNoteByTypeId(QubitTerm::RELATION_NOTE_DESCRIPTION_ID) ?></td> - <td style="text-align: center;"> - <input type="checkbox" name="deleteRelations[<?php echo $funcRelation->getId() ?>]" value="delete" class="multiDelete" /> - </td> - </tr> - <?php endforeach; ?> - <?php endif; ?> - </table> - </div> - - <!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * --> - <!-- NOTE: The functionRelationDialog.js script cuts this *entire* --> - <!-- "functionRelation" table and pastes it in a YUI dialog object. --> - <!-- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * --> - <table class="inline" id="functionRelation"> - <caption><?php echo __('new relationship') ?></caption> - <tbody> - <tr> - <th style="width: 66%" colspan="3"> - <label for="editActorRelation_functionName" class="required_field"><?php echo __('Name of related entity') ?></label> - </th> - <th style="width: 34%"> - <label for="editActorRelation_categoryId"><?php echo __('Category of relationship') ?></label> - </th> - </tr> - <tr> - <td colspan="3" style="width: 66%"> - <?php // include_partial('functionNameAutoComplete', array('function' => $func))?> - </td> - <td style="width: 34%"> - <?php echo select_tag('editActorRelation[categoryId]', objects_for_select($funcRelationCategories, 'getId', 'getName')) ?> - </td> - </tr> - <tr> - <th colspan="4"> - <label for="editActorRelation_description"><?php echo __('Description of relationship') ?></label> - </th> - </tr> - <tr> - <td colspan="4" style="width: 100%"> - <?php echo textarea_tag('editActorRelation[description]', '', array('class' => 'resizable', 'style' => '30x3')) ?> - </td> - </tr> - <tr> - <th style="width: 25%"> - <label for="editActorRelation_startDate"><?php echo __('date&dagger') ?></label> - </th> - <th style="width: 25%"> - <label for="editActorRelation_endDate"><?php echo __('end date†') ?></label> - </th> - <th colspan="2" style="width: 50%"> - <label for="editActorRelation_dateDisplay"><?php echo __('date display') ?></label> - </th> - </tr> - <tr> - <td style="width: 25%"> - <?php echo input_tag('editActorRelation[startDate]') ?> - </td> - <td style="width: 25%"> - <?php echo input_tag('editActorRelation[endDate]') ?> - </td> - <td colspan="2" style="width: 50%"> - <?php echo input_tag('editActorRelation[dateDisplay]') ?> - </td> - </tr> - <tr> - <td colspan="4"> - <?php echo __('%1% - required field', array('%1%' => '*'))?><br /> - <?php echo __('%1% - dates must be specified in ISO-8601 format (YYYY-MM-DD)', array('%1%' => '†'))?> - </td> - </tr> - </tbody> - </table> + <?php include_component('function', 'relationships', array('func' => $func)) ?> </fieldset> <fieldset class="collapsible collapsed" id="controlArea"> @@ -202,4 +100,4 @@ <?php endif; ?> </ul> -</form> \ No newline at end of file +</form> -- You received this message because you are subscribed to the Google Groups "Qubit Toolkit Commits" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/qubit-commits?hl=en.
