コード例 #1
0
 /**
  * Test citation generation
  *
  * @return void
  * @access public
  */
 public function testCitations()
 {
     global $interface;
     foreach ($this->_citations as $current) {
         $cb = new CitationBuilder($current['raw']);
         $tpl = $cb->getAPA();
         // Normalize whitespace:
         $apa = trim(preg_replace("/\\s+/", " ", $interface->fetch($tpl)));
         $this->assertEquals($current['apa'], $apa);
         $tpl = $cb->getMLA();
         // Normalize whitespace:
         $mla = trim(preg_replace("/\\s+/", " ", $interface->fetch($tpl)));
         $this->assertEquals($current['mla'], $mla);
         // Repeat tests using newer getCitation method:
         $tpl = $cb->getCitation('APA');
         // Normalize whitespace:
         $apa = trim(preg_replace("/\\s+/", " ", $interface->fetch($tpl)));
         $this->assertEquals($current['apa'], $apa);
         $tpl = $cb->getCitation('MLA');
         // Normalize whitespace:
         $mla = trim(preg_replace("/\\s+/", " ", $interface->fetch($tpl)));
         $this->assertEquals($current['mla'], $mla);
     }
     // Test a couple of illegal citation formats:
     $this->assertEquals('', $cb->getCitation('Citation'));
     $this->assertEquals('', $cb->getCitation('SupportedCitationFormats'));
     $this->assertEquals('', $cb->getCitation('badgarbage'));
 }
コード例 #2
0
 public function getCitation($format)
 {
     require_once ROOT_DIR . '/sys/CitationBuilder.php';
     // Build author list:
     $authors = array();
     $primary = $this->eContentRecord->author;
     if (!empty($primary)) {
         $authors[] = $primary;
     }
     $authors = array_unique(array_merge($authors, $this->eContentRecord->getPropertyArray('author2')));
     // Collect all details for citation builder:
     $publishers = array($this->eContentRecord->publisher);
     $pubDates = $this->eContentRecord->getPropertyArray('publishDate');
     $pubPlaces = array();
     $details = array('authors' => $authors, 'title' => $this->eContentRecord->title, 'subtitle' => $this->eContentRecord->subTitle, 'pubPlace' => count($pubPlaces) > 0 ? $pubPlaces[0] : null, 'pubName' => count($publishers) > 0 ? $publishers[0] : null, 'pubDate' => count($pubDates) > 0 ? $pubDates[0] : null, 'edition' => $this->eContentRecord->getPropertyArray('edition'), 'source' => $this->eContentRecord->source, 'format' => $this->eContentRecord->format());
     // Build the citation:
     $citation = new CitationBuilder($details);
     switch ($format) {
         case 'APA':
             return $citation->getAPA();
         case 'MLA':
             return $citation->getMLA();
         case 'AMA':
             return $citation->getAMA();
         case 'ChicagoAuthDate':
             return $citation->getChicagoAuthDate();
         case 'ChicagoHumanities':
             return $citation->getChicagoHumanities();
     }
     return '';
 }
コード例 #3
0
 /**
  * Assign necessary Smarty variables and return a template name
  * to load in order to display the requested citation format.
  * For legal values, see getCitationFormats().  Returns null if
  * format is not supported.
  *
  * @param   string  $format     Citation format to display.
  * @access  public
  * @return  string              Name of Smarty template file to display.
  */
 public function getCitation($format)
 {
     require_once ROOT_DIR . '/sys/CitationBuilder.php';
     // Build author list:
     $authors = array();
     $primary = $this->getAuthor();
     if (!empty($primary)) {
         $authors[] = $primary;
     }
     $authors = array_unique(array_merge($authors, $this->getContributors()));
     // Collect all details for citation builder:
     $publishers = $this->getPublishers();
     $pubDates = $this->getPublicationDates();
     $pubPlaces = $this->getPlacesOfPublication();
     $details = array('authors' => $authors, 'title' => $this->getTitle(), 'subtitle' => $this->getSubtitle(), 'pubPlace' => count($pubPlaces) > 0 ? $pubPlaces[0] : null, 'pubName' => count($publishers) > 0 ? $publishers[0] : null, 'pubDate' => count($pubDates) > 0 ? $pubDates[0] : null, 'edition' => $this->getEdition(), 'format' => $this->getFormats());
     // Build the citation:
     $citation = new CitationBuilder($details);
     switch ($format) {
         case 'APA':
             return $citation->getAPA();
         case 'AMA':
             return $citation->getAMA();
         case 'ChicagoAuthDate':
             return $citation->getChicagoAuthDate();
         case 'ChicagoHumanities':
             return $citation->getChicagoHumanities();
         case 'MLA':
             return $citation->getMLA();
     }
     return '';
 }