Пример #1
0
 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)));
     }
 }
Пример #2
0
 public function executeList()
 {
     if ($this->object instanceof Doctrine_Record) {
         //use special method if possible
         $refs = method_exists($this->object, 'getAllReferences') ? $this->object->getAllReferences() : $this->object->getReferencesByFields(null, Doctrine::HYDRATE_ARRAY);
     } else {
         //check table for special method in table
         $table = $this->model . 'Table';
         if (method_exists($table, 'getAllReferencesById')) {
             $refs = call_user_func(array($table, 'getAllReferencesById'), $this->object['id']);
         } else {
             $refs = ReferenceTable::getByModelAndId($this->model, $this->object['id']);
         }
     }
     $this->pager = new LsDoctrinePager($refs, $page = 1, $num = 10);
 }
 function uploadTmpFile($source, $overwrite = false, $debug = false, $localdir = false)
 {
     $filePath = $this->getTmpPath($source, $localdir);
     $size = filesize($filePath);
     $input = $this->s3->inputResource($f = fopen($filePath, "r"), $size);
     $url = ReferenceTable::generateS3path($source);
     if (!$overwrite && $this->s3->getObjectInfo(sfConfig::get('app_amazon_s3_bucket'), $url) !== false) {
         print "ALREADY UPLOADED: " . $url . "\n";
         return;
     }
     if (S3::putObject($input, sfConfig::get('app_amazon_s3_bucket'), $url, S3::ACL_PUBLIC_READ)) {
         print "UPLOADED: " . $url . "\n";
     } else {
         if ($debug) {
             print "Couldn't upload reference to S3: " . $url . "\n";
         }
     }
 }
Пример #4
0
 public function getDisplayName()
 {
     return ReferenceTable::getDisplayName($this);
 }
Пример #5
0
 static function getContactReferencesById($id)
 {
     $db = Doctrine_Manager::connection();
     $contact_arr = array();
     //get addresses this entity is in
     $sql = 'SELECT DISTINCT a.id FROM address a WHERE a.entity_id = ?';
     $stmt = $db->execute($sql, array($id));
     $addressIds = $stmt->fetchAll(PDO::FETCH_COLUMN);
     if (count($addressIds)) {
         $contact_arr['Address'] = '(r.object_model = ? AND r.object_id IN (' . implode(',', $addressIds) . '))';
     }
     $sql = 'SELECT DISTINCT e.id FROM email e WHERE e.entity_id = ?';
     $stmt = $db->execute($sql, array($id));
     $emailIds = $stmt->fetchAll(PDO::FETCH_COLUMN);
     if (count($emailIds)) {
         $contact_arr['Email'] = '(r.object_model = ? AND r.object_id IN (' . implode(',', $emailIds) . '))';
     }
     $sql = 'SELECT DISTINCT p.id FROM phone p WHERE p.entity_id = ?';
     $stmt = $db->execute($sql, array($id));
     $phoneIds = $stmt->fetchAll(PDO::FETCH_COLUMN);
     if (count($phoneIds)) {
         $contact_arr['Phone'] = '(r.object_model = ? AND r.object_id IN (' . implode(',', $phoneIds) . '))';
     }
     $refs = array();
     //get references for the relationships
     if (count($phoneIds) || count($emailIds) || count($addressIds)) {
         $sql = 'SELECT r.* FROM reference r WHERE ' . implode(' OR ', $contact_arr) . ' ORDER BY r.updated_at DESC';
         $stmt = $db->execute($sql, array_keys($contact_arr));
         $refs = array_merge($refs, $stmt->fetchAll(PDO::FETCH_ASSOC));
         $refs = ReferenceTable::consolidate($refs);
     }
     return $refs;
 }
Пример #6
0
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;
    }
}
Пример #7
0
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')) {
        ?>
    &nbsp;
    <span class="text_small"><?php 
        echo link_to('edit', 'reference/edit?id=' . $ref['id']);
        ?>
</span>
  <?php 
    }
    ?>
  <?php 
    if ($sf_user->hasCredential('deleter')) {