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))); } }
public function getDisplayName() { return ReferenceTable::getDisplayName($this); }
function reference_link($reference, $excerptLength = null) { use_helper('LsText'); $text = $excerptLength ? excerpt(ReferenceTable::getDisplayName($reference), $excerptLength) : ReferenceTable::getDisplayName($reference); if (stripos($reference['source'], 'http') === 0) { return link_to($text, $reference['source'], 'target=_blank'); } else { return $text; } }
slot('header_text', $object->getName()); slot('header_link', method_exists($object, 'getInternalUrl') ? $object->getInternalUrl() : strtolower(get_class($object)) . '/view?id=' . $object->id); ?> <?php include_partial('global/section', array('title' => 'Source Links', 'action' => array('credential' => 'contributor', 'text' => 'add', 'url' => 'reference/add?model=' . get_class($object) . '&id=' . $object->id), 'pointer' => 'Articles documenting info about ' . $object->getName())); ?> <div class="padded"> <?php $refs = method_exists($object, 'getAllReferences') ? $object->getAllReferences() : $object->getReferencesByFields(); foreach ($refs as $ref) { ?> <span class="text_big"><?php echo link_to(ReferenceTable::getDisplayName($ref), $ref['source']); ?> </span> <?php if ($sf_user->hasCredential('editor')) { ?> <span class="text_small"><?php echo link_to('edit', 'reference/edit?id=' . $ref['id']); ?> </span> <?php } ?> <?php if ($sf_user->hasCredential('deleter')) {