public function testMainLicenseIds() { $this->testDb->createPlainTables(array('upload_clearing_license')); $uploadId = 101; $mainLicIdsInitially = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId); assertThat($mainLicIdsInitially, is(emptyArray())); $this->clearingDao->makeMainLicense($uploadId, $this->groupId, $licenseId = 402); $mainLicIdsAfterAddingOne = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId); assertThat($mainLicIdsAfterAddingOne, arrayContaining(array($licenseId))); $this->clearingDao->makeMainLicense($uploadId, $this->groupId, $licenseId); $mainLicIdsAfterAddingOneTwice = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId); assertThat($mainLicIdsAfterAddingOneTwice, is(arrayWithSize(1))); $this->clearingDao->makeMainLicense($uploadId, $this->groupId, $licenseId2 = 403); $mainLicIdsAfterAddingOther = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId); assertThat($mainLicIdsAfterAddingOther, arrayContainingInAnyOrder(array($licenseId, $licenseId2))); $this->clearingDao->removeMainLicense($uploadId, $this->groupId, $licenseId2); $mainLicIdsAfterRemovingOne = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId); assertThat($mainLicIdsAfterRemovingOne, is(arrayWithSize(1))); $this->clearingDao->removeMainLicense($uploadId, $this->groupId, $licenseId2); $mainLicIdAfterRemovingSomethingNotInSet = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId); assertThat($mainLicIdAfterRemovingSomethingNotInSet, is(arrayWithSize(1))); $this->clearingDao->removeMainLicense($uploadId, $this->groupId + 1, $licenseId); $mainLicIdAfterInsertToOtherGroup = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId); assertThat($mainLicIdAfterInsertToOtherGroup, is(arrayWithSize(1))); $this->clearingDao->removeMainLicense($uploadId + 1, $this->groupId, $licenseId); $mainLicIdAfterInsertToOtherUpload = $this->clearingDao->getMainLicenseIds($uploadId, $this->groupId); assertThat($mainLicIdAfterInsertToOtherUpload, is(arrayWithSize(1))); }
/** * @return Response */ function Output() { $userId = Auth::getUserId(); $groupId = Auth::getGroupId(); $action = GetParm("do", PARM_STRING); $uploadId = GetParm("upload", PARM_INTEGER); $uploadTreeId = GetParm("item", PARM_INTEGER); $licenseId = GetParm("licenseId", PARM_INTEGER); $sort0 = GetParm("sSortDir_0", PARM_STRING); $orderAscending = isset($sort0) ? $sort0 === "asc" : true; switch ($action) { case "licenses": return new JsonResponse($this->doLicenses($orderAscending, $groupId, $uploadId, $uploadTreeId)); case "licenseDecisions": return new JsonResponse($this->doClearings($orderAscending, $groupId, $uploadId, $uploadTreeId)); case "addLicense": $this->clearingDao->insertClearingEvent($uploadTreeId, $userId, $groupId, $licenseId, false, ClearingEventTypes::USER); return new JsonResponse(); case "removeLicense": $this->clearingDao->insertClearingEvent($uploadTreeId, $userId, $groupId, $licenseId, true, ClearingEventTypes::USER); return new JsonResponse(); case "makeMainLicense": $this->clearingDao->makeMainLicense($uploadId, $groupId, $licenseId); return new JsonResponse(); case "removeMainLicense": $this->clearingDao->removeMainLicense($uploadId, $groupId, $licenseId); return new JsonResponse(); case "setNextPrev": case "setNextPrevCopyRight": case "setNextPrevIp": case "setNextPrevEcc": return new JsonResponse($this->doNextPrev($action, $uploadId, $uploadTreeId, $groupId)); case "updateClearings": $id = GetParm("id", PARM_STRING); if (isset($id)) { list($uploadTreeId, $licenseId) = explode(',', $id); $what = GetParm("columnId", PARM_INTEGER) == 3 ? 'comment' : 'reportinfo'; $changeTo = GetParm("value", PARM_RAW); $this->clearingDao->updateClearingEvent($uploadTreeId, $userId, $groupId, $licenseId, $what, $changeTo); } return $this->createPlainResponse("success"); default: return $this->createPlainResponse("fail"); } }