/** * @param ItemTreeBounds $itemTreeBound * @param int $groupId * @param boolean $onlyTried * @return array[] where array has keys ("bulkId","id","text","matched","tried","removedLicenses","addedLicenses") */ public function getBulkHistory(ItemTreeBounds $itemTreeBound, $groupId, $onlyTried = true) { $uploadTreeTableName = $itemTreeBound->getUploadTreeTableName(); $itemId = $itemTreeBound->getItemId(); $uploadId = $itemTreeBound->getUploadId(); $left = $itemTreeBound->getLeft(); $params = array($uploadId, $itemId, $left, $groupId); $stmt = __METHOD__ . "." . $uploadTreeTableName; $triedExpr = "\$3 between ut2.lft and ut2.rgt"; $triedFilter = ""; if ($onlyTried) { $triedFilter = "and " . $triedExpr; $stmt .= ".tried"; } $sql = "WITH alltried AS (\n SELECT lr.lrb_pk, ce.clearing_event_pk ce_pk, lr.rf_text, ce.uploadtree_fk,\n {$triedExpr} AS tried\n FROM license_ref_bulk lr\n LEFT JOIN highlight_bulk h ON lrb_fk = lrb_pk\n LEFT JOIN clearing_event ce ON ce.clearing_event_pk = h.clearing_event_fk\n LEFT JOIN {$uploadTreeTableName} ut ON ut.uploadtree_pk = ce.uploadtree_fk\n INNER JOIN {$uploadTreeTableName} ut2 ON ut2.uploadtree_pk = lr.uploadtree_fk\n WHERE ut2.upload_fk = \$1 AND lr.group_fk = \$4\n {$triedFilter}\n ORDER BY lr.lrb_pk\n ), aggregated_tried AS (\n SELECT DISTINCT ON(lrb_pk) lrb_pk, ce_pk, rf_text AS text, tried, matched\n FROM (\n SELECT DISTINCT ON(lrb_pk) lrb_pk, ce_pk, rf_text, tried, true AS matched FROM alltried WHERE uploadtree_fk = \$2\n UNION ALL\n SELECT DISTINCT ON(lrb_pk) lrb_pk, ce_pk, rf_text, tried, false AS matched FROM alltried WHERE uploadtree_fk != \$2 OR uploadtree_fk IS NULL\n ) AS result ORDER BY lrb_pk, matched DESC)\n SELECT lrb_pk, text, rf_shortname, removing, tried, ce_pk, matched\n FROM aggregated_tried\n INNER JOIN license_set_bulk lsb ON lsb.lrb_fk = lrb_pk\n INNER JOIN license_ref lrf ON lsb.rf_fk = lrf.rf_pk\n ORDER BY lrb_pk"; $this->dbManager->prepare($stmt, $sql); $res = $this->dbManager->execute($stmt, $params); $bulks = array(); while ($row = $this->dbManager->fetchArray($res)) { $bulkRun = $row['lrb_pk']; if (!array_key_exists($bulkRun, $bulks)) { $bulks[$bulkRun] = array("bulkId" => $row['lrb_pk'], "id" => $row['ce_pk'], "text" => $row['text'], "matched" => $this->dbManager->booleanFromDb($row['matched']), "tried" => $this->dbManager->booleanFromDb($row['tried']), "removedLicenses" => array(), "addedLicenses" => array()); } $key = $this->dbManager->booleanFromDb($row['removing']) ? 'removedLicenses' : 'addedLicenses'; $bulks[$bulkRun][$key][] = $row['rf_shortname']; } $this->dbManager->freeResult($res); return $bulks; }
/** * @brief Update forms * @param int $rf_pk - for the license to update, empty to add * @return string The input form */ function Updatefm($rf_pk) { $vars = array(); $rf_pk_update = ""; if (0 < count($_POST)) { $rf_pk_update = $_POST['rf_pk']; if (!empty($rf_pk)) { $rf_pk_update = $rf_pk; } else { if (empty($rf_pk_update)) { $rf_pk_update = $_GET['rf_pk']; } } } $vars['actionUri'] = "?mod=" . $this->Name . "&rf_pk={$rf_pk_update}"; $vars['req_marydone'] = array_key_exists('req_marydone', $_GET) ? $_GET['req_marydone'] : ''; $vars['req_shortname'] = array_key_exists('req_shortname', $_GET) ? $_GET['req_shortname'] : ''; $vars['risk_level'] = array_key_exists('risk_level', $_GET) ? intval($_GET['risk_level']) : 0; $parentMap = new LicenseMap($this->dbManager, 0, LicenseMap::CONCLUSION); $parentLicenes = $parentMap->getTopLevelLicenseRefs(); $vars['parentMap'] = array(0 => '[self]'); foreach ($parentLicenes as $licRef) { $vars['parentMap'][$licRef->getId()] = $licRef->getShortName(); } $reportMap = new LicenseMap($this->dbManager, 0, LicenseMap::REPORT); $reportLicenes = $reportMap->getTopLevelLicenseRefs(); $vars['reportMap'] = array(0 => '[self]'); foreach ($reportLicenes as $licRef) { $vars['reportMap'][$licRef->getId()] = $licRef->getShortName(); } if ($rf_pk) { $row = $this->dbManager->getSingleRow("SELECT * FROM ONLY license_ref WHERE rf_pk=\$1", array($rf_pk), __METHOD__ . '.forUpdate'); if ($row === false) { $text = _("No licenses matching this key"); $text1 = _("was found"); return "{$text} ({$rf_pk}) {$text1}."; } $row['rf_parent'] = $parentMap->getProjectedId($rf_pk); $row['rf_report'] = $reportMap->getProjectedId($rf_pk); } else { $row = array('rf_active' => 't', 'marydone' => 'f', 'rf_text_updatable' => 't', 'rf_parent' => 0, 'rf_report' => 0, 'rf_risk'); } foreach (array_keys($row) as $key) { if (array_key_exists($key, $_POST)) { $row[$key] = $_POST[$key]; } } $vars['boolYesNoMap'] = array("true" => "Yes", "false" => "No"); $row['rf_active'] = $this->dbManager->booleanFromDb($row['rf_active']) ? 'true' : 'false'; $row['marydone'] = $this->dbManager->booleanFromDb($row['marydone']) ? 'true' : 'false'; $row['rf_text_updatable'] = $this->dbManager->booleanFromDb($row['rf_text_updatable']) ? 'true' : 'false'; $row['risk_level'] = $row['rf_risk']; $vars['isReadOnly'] = !(empty($rf_pk) || $row['rf_text_updatable'] == 'true'); $vars['detectorTypes'] = array("1" => "Reference License", "2" => "Nomos"); $vars['rfId'] = $rf_pk ?: $rf_pk_update; $allVars = array_merge($vars, $row); return $this->renderString('admin_license-upload_form.html.twig', $allVars); }