/** * 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')); }
function launch() { global $interface; //Get all lists for the user // Fetch List object if (isset($_REQUEST['id'])) { /** @var UserList $list */ $list = UserList::staticGet($_GET['listId']); } $interface->assign('favList', $list); // Get all titles on the list // $favorites = $list->getListEntries(); // $favList = new FavoriteHandler($favorites, null, $list->id, false); //TODO: test this $favList = new FavoriteHandler($list, null, false); $citationFormat = $_REQUEST['citationFormat']; $citationFormats = CitationBuilder::getCitationFormats(); $interface->assign('citationFormat', $citationFormats[$citationFormat]); $citations = $favList->getCitations($citationFormat); $interface->assign('citations', $citations); // Display Page $interface->assign('listId', strip_tags($_REQUEST['id'])); $interface->setTemplate('listCitations.tpl'); $interface->display('layout.tpl'); }
function launch() { global $interface; global $configArray; global $user; //Get all lists for the user // Fetch List object if (isset($_REQUEST['id'])) { $list = User_list::staticGet($_GET['listId']); } $interface->assign('favList', $list); // Get all titles on the list $favorites = $list->getResources(null); $favList = new FavoriteHandler($favorites, null, $list->id, false); $citationFormat = $_REQUEST['citationFormat']; $citationFormats = CitationBuilder::getCitationFormats(); $interface->assign('citationFormat', $citationFormats[$citationFormat]); $citations = $favList->getCitations($citationFormat); $interface->assign('citations', $citations); // Display Page $interface->assign('listId', strip_tags($_REQUEST['id'])); $interface->setTemplate('listCitations.tpl'); $interface->display('layout.tpl'); }
function getCitationFormatsForm() { global $interface; $interface->assign('popupTitle', 'Please select a citation format'); $interface->assign('listId', $_REQUEST['listId']); $citationFormats = CitationBuilder::getCitationFormats(); $interface->assign('citationFormats', $citationFormats); $pageContent = $interface->fetch('MyResearch/getCitationFormatPopup.tpl'); $interface->assign('popupContent', $pageContent); return $interface->fetch('popup-wrapper.tpl'); }
/** * Get an array of strings representing citation formats supported * by this record's data (empty if none). * * @return array Strings representing citation formats. * @access public */ public function getCitationFormats() { return CitationBuilder::getSupportedCitationFormats(); }
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 ''; }
/** * 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 ''; }