public function testConstruct() { $licenseViewProxy0 = new LicenseViewProxy(0); $query0 = $licenseViewProxy0->getDbViewQuery(); $expected0 = "SELECT {$this->almostAllColumns},0 AS group_fk FROM ONLY license_ref"; assertThat($query0, is($expected0)); $licenseViewProxy123 = new LicenseViewProxy(123, array('diff' => true)); $query123 = $licenseViewProxy123->getDbViewQuery(); $expected123 = "SELECT {$this->almostAllColumns},group_fk FROM license_candidate WHERE group_fk=123"; assertThat($query123, is($expected123)); $licenseViewProxy0123 = new LicenseViewProxy(123); $query0123 = $licenseViewProxy0123->getDbViewQuery(); $expected0123 = "{$expected123} UNION {$expected0}"; assertThat($query0123, is($expected0123)); }
/** * @return string[] with keys being shortname */ protected function getLicenseTexts() { $licenseTexts = array(); $licenseViewProxy = new LicenseViewProxy($this->groupId, array(LicenseViewProxy::OPT_COLUMNS => array('rf_pk', 'rf_shortname', 'rf_text'))); $this->dbManager->prepare($stmt = __METHOD__, $licenseViewProxy->getDbViewQuery()); $res = $this->dbManager->execute($stmt); while ($row = $this->dbManager->fetchArray($res)) { if (array_key_exists($row['rf_pk'], $this->includedLicenseIds)) { $licenseTexts[$row['rf_shortname']] = $row['rf_text']; } } foreach ($this->includedLicenseIds as $license => $customText) { if (true !== $customText) { $licenseTexts[$license] = $customText; } } $this->dbManager->freeResult($res); return $licenseTexts; }
public function getTopLevelLicenseRefs() { $licenseView = new LicenseViewProxy($this->groupId, array('columns' => array('rf_pk', 'rf_shortname', 'rf_fullname')), 'license_visible'); $query = $licenseView->asCTE() . ' SELECT rf_pk, rf_shortname, rf_fullname FROM ' . $licenseView->getDbViewName() . ' LEFT JOIN license_map ON rf_pk=rf_fk AND rf_fk!=rf_parent AND usage=$1' . ' WHERE license_map_pk IS NULL'; $stmt = __METHOD__ . ".{$this->usageId},{$this->groupId}"; $this->dbManager->prepare($stmt, $query); $res = $this->dbManager->execute($stmt, array($this->usageId)); $topLevel = array(); while ($row = $this->dbManager->fetchArray($res)) { $topLevel[$row['rf_pk']] = new LicenseRef($row['rf_pk'], $row['rf_shortname'], $row['rf_fullname']); } return $topLevel; }
/** * @param string $newShortname * @param int $groupId * @return bool */ public function isNewLicense($newShortname, $groupId) { $licenceViewDao = new LicenseViewProxy($groupId, array('columns' => array('rf_shortname'))); $sql = 'SELECT count(*) cnt FROM (' . $licenceViewDao->getDbViewQuery() . ') AS license_all WHERE rf_shortname=$1'; $duplicatedRef = $this->dbManager->getSingleRow($sql, array($newShortname), __METHOD__ . ".{$groupId}"); return $duplicatedRef['cnt'] == 0; }