12 namespace Fossology\UI\Page;
18 use Symfony\Component\HttpFoundation\JsonResponse;
19 use Symfony\Component\HttpFoundation\Request;
20 use Symfony\Component\HttpFoundation\Response;
33 const NAME =
"admin_license_compatibility_rules";
131 function __construct()
133 parent::__construct(self::NAME,
135 self::TITLE =>
"License Compatibility Rules",
136 self::MENU_LIST =>
"Admin::License Admin::Compatibility Rules",
137 self::REQUIRES_LOGIN =>
true,
140 $this->compatibilityDao = $this->
getObject(
'dao.compatibility');
141 $this->licenseDao = $this->
getObject(
'dao.license');
148 protected function handle(Request $request)
150 if ($request->get(self::UPDATE_PARAM_NAME, 0) == 1) {
151 return new JsonResponse($this->
updateRules($request),
152 JsonResponse::HTTP_OK);
153 } elseif ($request->get(
"action", 0) ===
"deleterule") {
154 return new JsonResponse($this->
deleteRules($request),
155 JsonResponse::HTTP_OK);
175 $licenseType = $SysConf[
'SYSCONFIG'][
'LicenseTypes'];
176 $licenseType = explode(
',', $licenseType);
177 $licenseType = array_map(
'trim', $licenseType);
178 $licenseType = [
"---", ...$licenseType];
179 $vars[
'licenseTypes'] = array_combine($licenseType, $licenseType);
181 $vars[
'ruleArray'] = $this->compatibilityDao->getAllRules();
183 $licenseArray = $this->licenseDao->getLicenseArray(0);
184 $licenseArray = array_column($licenseArray,
'shortname',
'id');
186 $licenseList = [0 =>
"---"];
187 $licenseList += $licenseArray;
188 $vars[
'licenseArray'] = $licenseList;
189 return $this->
render(
'admin_license_compatibility_rules.html.twig',
190 $this->mergeWithDefault($vars));
205 $licFirstName = $request->get(self::FIRST_LIC_NAME_PARAM_NAME);
206 $insertFirstName = $request->get(self::INSERT_FIRST_LIC_NAME_PARAM_NAME);
208 $licSecondName = $request->get(self::SECOND_LIC_NAME_PARAM_NAME);
209 $insertSecondName = $request->get(self::INSERT_SECOND_LIC_NAME_PARAM_NAME);
211 $licFirstType = $request->get(self::FIRST_LIC_TYPE_PARAM_NAME);
212 $insertFirstType = $request->get(self::INSERT_FIRST_LIC_TYPE_PARAM_NAME);
214 $licSecondType = $request->get(self::SECOND_LIC_TYPE_PARAM_NAME);
215 $insertSecondType = $request->get(self::INSERT_SECOND_LIC_TYPE_PARAM_NAME);
217 $licText = $request->get(self::TEXT_PARAM_NAME);
218 $insertText = $request->get(self::INSERT_TEXT_PARAM_NAME);
220 $licResult = $request->get(self::RESULT_PARAM_NAME);
221 $insertResult = $request->get(self::INSERT_RESULT_PARAM_NAME);
223 if (!empty($licFirstName)) {
224 foreach ($licFirstName as $rulePk => $firstLic) {
225 if ($firstLic ==
"0") {
226 $rules[$rulePk][
'firstLic'] =
null;
228 $rules[$rulePk][
'firstLic'] = $firstLic;
232 if (!empty($licSecondName)) {
233 foreach ($licSecondName as $rulePk => $secondLic) {
234 if ($secondLic ==
"0") {
235 $rules[$rulePk][
'secondLic'] =
null;
237 $rules[$rulePk][
'secondLic'] = $secondLic;
241 if (!empty($licFirstType)) {
242 foreach ($licFirstType as $rulePk => $firstType) {
243 if ($firstType ==
"---") {
244 $rules[$rulePk][
'firstType'] =
null;
246 $rules[$rulePk][
'firstType'] = $firstType;
250 if (!empty($licSecondType)) {
251 foreach ($licSecondType as $rulePk => $secondType) {
252 if ($secondType ==
"---") {
253 $rules[$rulePk][
'secondType'] =
null;
255 $rules[$rulePk][
'secondType'] = $secondType;
259 if (!empty($licText)) {
260 foreach ($licText as $rulePk => $text) {
261 $rules[$rulePk][
'comment'] = $text;
264 if (!empty($licResult)) {
265 foreach ($licResult as $rulePk => $result) {
266 $rules[$rulePk][
'result'] = $result;
270 if (! empty($rules)) {
272 $update[
'updated'] = $this->compatibilityDao->updateRuleFromArray(
274 }
catch (\UnexpectedValueException $e) {
275 $update[
'updated'] = $e->getMessage();
279 $update[
"inserted"] = $this->
insertRules($insertFirstName,
280 $insertSecondName, $insertFirstType, $insertSecondType, $insertText,
296 $firstTypeArray, $secondTypeArray, $commentArray,
300 if ((!empty($firstNameArray) && !empty($secondNameArray)
301 && !empty($firstTypeArray) && !empty($secondTypeArray)
302 && !empty($commentArray))) {
303 for ($i = 0; $i < count($commentArray); $i++) {
304 if ($firstNameArray[$i] ==
"0") {
305 $firstNameArray[$i] =
null;
307 if ($secondNameArray[$i] ==
"0") {
308 $secondNameArray[$i] =
null;
310 if ($firstTypeArray[$i] ==
"---") {
311 $firstTypeArray[$i] =
null;
313 if ($secondTypeArray[$i] ==
"---") {
314 $secondTypeArray[$i] =
null;
316 $returnVal[] = $this->compatibilityDao->insertRule($firstNameArray[$i],
317 $secondNameArray[$i], $firstTypeArray[$i], $secondTypeArray[$i],
318 $commentArray[$i], $resultArray[$i]);
320 $returnVal[
'status'] = 0;
322 if (count(array_filter($returnVal,
function($val) {
325 $returnVal[
'status'] |= 1;
328 if (in_array(-1, $returnVal)) {
329 $returnVal[
'status'] |= 1 << 1;
332 if (in_array(-2, $returnVal)) {
333 $returnVal[
'status'] |= 1 << 2;
347 $rulePk = $request->get(
"rule");
348 $val = $this->compatibilityDao->deleteRule($rulePk);
349 $returnVal[
'status'] = $val ? 1 : -1;
354 register_plugin(
new AdminLicenseCompatibilityRules());
Contains the constants and helpers for authentication of user.
render($templateName, $vars=null, $headers=null)
deleteRules(Request $request)
Delete a rule from the UI.
const INSERT_FIRST_LIC_TYPE_PARAM_NAME
updateRules(Request $request)
Update the already existing rules.
const FIRST_LIC_TYPE_PARAM_NAME
const INSERT_RESULT_PARAM_NAME
const INSERT_SECOND_LIC_TYPE_PARAM_NAME
const INSERT_SECOND_LIC_NAME_PARAM_NAME
const INSERT_TEXT_PARAM_NAME
const INSERT_FIRST_LIC_NAME_PARAM_NAME
const SECOND_LIC_TYPE_PARAM_NAME
insertRules($firstNameArray, $secondNameArray, $firstTypeArray, $secondTypeArray, $commentArray, $resultArray)
Insert new rules from the UI.
const FIRST_LIC_NAME_PARAM_NAME
const SECOND_LIC_NAME_PARAM_NAME