public function setSelectObject(Doctrine_Record $object, $autoSelect = false, $contactInfo = false) { $this->_selectObject = $object; if ($object instanceof Relationship) { //when editing a Relationship, show all Relationship references //plus all references for Entity1 and Entity2 //plus 5 most recent references for Entity1's Relationships //plus 5 most recent references for Entity2's Relationships $refs = RelationshipTable::getReferencesForRelationship($object); } else { if ($object instanceof Entity && $contactInfo == true) { $refs = EntityTable::getContactReferencesById($object->id); } else { $refs = $object->getReferencesByFields(null, Doctrine::HYDRATE_ARRAY); if ($object instanceof Entity) { //when editing an Entity, show all Entity references //plus 10 most recent references for the Entity's Relationships $refs = array_merge($refs, EntityTable::getRecentRelationshipReferencesQuery($object, 10)->setHydrationMode(Doctrine::HYDRATE_ARRAY)->execute()); } } } $tmpRefs = array(); $uniqueRefs = array(); //consolidate references foreach ($refs as $ref) { if (!isset($tmpRefs[$ref['source']])) { $tmpRefs[$ref['source']] = array($ref['name']); $uniqueRefs[] = $ref; } else { if (!in_array($ref['name'], $tmpRefs[$ref['source']])) { $tmpRefs[$ref['source']][] = $ref['name']; $uniqueRefs[] = $ref; } } } $refs = $uniqueRefs; if (count($refs)) { //create choices array $choices = array('' => ''); foreach ($refs as $ref) { $choices[$ref['id']] = ReferenceTable::getDisplayName($ref); } //add select widget $widgets = array(); $widgets['existing_source'] = new sfWidgetFormSelect(array('choices' => $choices)); $widgets = array_merge($widgets, $this->getWidgetSchema()->getFields()); $this->setWidgets($widgets); if ($autoSelect && count($directRefs = $object->getReferencesByFields()->getData()) == 1) { $this->setDefault('existing_source', $directRefs[0]->id); } $this->widgetSchema->setLabels(array('source' => 'Source URL', 'name' => 'Display name', 'source_detail' => 'Location in source')); $this->widgetSchema->setHelps(array('source' => $this->_sourceHelp, 'name' => $this->_nameHelp, 'source_detail' => 'eg: Chapter 5, pp 75-80', 'publication_date' => LsFormHelp::$dateHelp, 'excerpt' => 'relevant section(s) of the source text')); $this->widgetSchema->setNameFormat('reference[%s]'); //make source validator optional $this->validatorSchema['existing_source'] = new sfValidatorChoice(array('choices' => array_keys($choices))); } }
} ?> </div> <br /> <br /> <?php include_partial('global/section', array('title' => 'Source Links', 'pointer' => 'Articles documenting info on this page')); ?> <div class="padded reference-list"> <?php $refs = EntityTable::getContactReferencesById($entity->id); foreach ($refs as $ref) { ?> <?php echo reference_link($ref, 50); ?> <br /> <?php } ?> </div> <p><?php echo button_to('Done', $entity->getInternalUrl('view')); ?>