function Output() { if ($this->State != PLUGIN_STATE_READY) { return 0; } $licenseShortname = GetParm("lic", PARM_TEXT); $licenseId = GetParm("rf", PARM_NUMBER); $groupId = $_SESSION[Auth::GROUP_ID]; if (empty($licenseShortname) && empty($licenseId)) { return; } if ($licenseId) { $license = $this->licenseDao->getLicenseById($licenseId, $groupId); } else { $license = $this->licenseDao->getLicenseByShortName($licenseShortname, $groupId); } if ($license === null) { return; } $this->vars['shortName'] = $license->getShortName(); $this->vars['fullName'] = $license->getFullName(); $parent = $this->licenseDao->getLicenseParentById($license->getId()); if ($parent !== null) { $this->vars['parentId'] = $parent->getId(); $this->vars['parentShortName'] = $parent->getShortName(); } $licenseUrl = $license->getUrl(); if (strtolower($licenseUrl) == 'none') { $licenseUrl = NULL; } $this->vars['url'] = $licenseUrl; $this->vars['text'] = $license->getText(); $this->vars['risk'] = $license->getRisk(); return $this->render('popup_license.html.twig'); }
/** * @param int $licenseId * @return License */ protected function getCachedLicenseText($licenseId, $groupId) { if (!array_key_exists($licenseId, $this->licenseCache)) { $this->licenseCache[$licenseId] = $this->licenseDao->getLicenseById($licenseId, $groupId); } return $this->licenseCache[$licenseId]->getText(); }
/** * @param Highlight[] $highlights * @param int|null $groupId */ public function addReferenceTexts(&$highlights, $groupId = null) { $licenses = array(); foreach ($highlights as &$highlight) { if ($highlight->hasLicenseId()) { $licenseId = $highlight->getLicenseId(); if (!array_key_exists($licenseId, $licenses)) { $licenses[$licenseId] = $this->licenseDao->getLicenseById($licenseId, $groupId); } /** * @var License $license */ $license = $licenses[$licenseId]; $licenseReferenceText = ": '" . $this->getReferenceText($license, $highlight) . "'"; $includeReferenceText = $highlight->getType() != Highlight::MATCH && $highlight->getRefLength() > 0; $infoText = $license->getShortName() . ($includeReferenceText ? $licenseReferenceText : ""); $highlight->setInfoText($infoText); } } }
public function testGetLicenseId() { $this->testDb->createPlainTables(array('license_ref')); $this->testDb->insertData_license_ref($limit = 3); $licDao = new LicenseDao($this->dbManager); $lic0 = $this->dbManager->getSingleRow("Select rf_pk from license_ref limit 1"); $id = $lic0['rf_pk']; $lic = $licDao->getLicenseById($id); $this->assertInstanceOf('Fossology\\Lib\\Data\\License', $lic); $this->assertEquals($id, $lic->getId()); $invalidId = -1; $lic = $licDao->getLicenseById($invalidId); $this->assertNull($lic); }