public static function mapByInflectionRank($ifs) { $result = array(); foreach ($ifs as $if) { $inflection = Inflection::get_by_id($if->inflectionId); if (!array_key_exists($inflection->rank, $result)) { $result[$inflection->rank] = array(); } $result[$inflection->rank][] = $if; } return $result; }
<?php require_once "../phplib/util.php"; $form = util_getRequestParameter('form'); $locVersion = util_getRequestParameter('locVersion'); $locVersions = pref_getLocVersions(); if ($locVersion && $form) { LocVersion::changeDatabase($locVersion); $form = StringUtil::cleanupQuery($form); smarty_assign('page_title', 'Verificare LOC: ' . $form); $ifs = loadLoc($form); $lexems = array(); $inflections = array(); foreach ($ifs as $if) { $lexems[] = Lexem::get_by_id($if->lexemId); $inflections[] = Inflection::get_by_id($if->inflectionId); } smarty_assign('form', $form); smarty_assign('selectedLocVersion', $locVersion); smarty_assign('ifs', $ifs); smarty_assign('lexems', $lexems); smarty_assign('inflections', $inflections); } else { smarty_assign('selectedLocVersion', $locVersions[1]->name); smarty_assign('page_title', 'Căutare formă flexionară în LOC ' . $form); } setlocale(LC_ALL, "ro_RO.utf8"); smarty_assign('locVersions', $locVersions); smarty_displayCommonPageWithSkin('scrabble-flexiune.ihtml'); function loadLoc($cuv) {
function validate($lexem, $original, $variantIds, $meanings) { if (!$lexem->form) { FlashMessage::add('Forma nu poate fi vidă.'); } $numAccents = mb_substr_count($lexem->form, "'"); // Note: we allow multiple accents for lexems like hárcea-párcea if ($numAccents && $lexem->noAccent) { FlashMessage::add('Ați indicat că lexemul nu necesită accent, dar forma conține un accent.'); } else { if (!$numAccents && !$lexem->noAccent) { FlashMessage::add('Adăugați un accent sau debifați câmpul "Necesită accent".'); } } foreach ($lexem->getLexemModels() as $lm) { $hasS = false; $hasP = false; for ($i = 0; $i < mb_strlen($lm->restriction); $i++) { $c = StringUtil::getCharAt($lm->restriction, $i); if ($c == 'T' || $c == 'U' || $c == 'I') { if ($lm->modelType != 'V' && $lm->modelType != 'VT') { FlashMessage::add("Restricția <b>{$c}</b> se aplică numai verbelor"); } } else { if ($c == 'S') { if ($lm->modelType == 'I' || $lm->modelType == 'T') { FlashMessage::add("Restricția <b>S</b> nu se aplică modelului {$lm->modelType}"); } $hasS = true; } else { if ($c == 'P') { if ($lm->modelType == 'I' || $lm->modelType == 'T') { FlashMessage::add("Restricția <b>P</b> nu se aplică modelului {$lm->modelType}"); } $hasP = true; } else { FlashMessage::add("Restricția <b>{$c}</b> este incorectă."); } } } } if ($hasS && $hasP) { FlashMessage::add("Restricțiile <b>S</b> și <b>P</b> nu pot coexista."); } $ifs = $lm->generateInflectedForms(); if (!is_array($ifs)) { $infl = Inflection::get_by_id($ifs); FlashMessage::add(sprintf("Nu pot genera flexiunea '%s' conform modelului %s%s", htmlentities($infl->description), $lm->modelType, $lm->modelNumber)); } } $variantOf = Lexem::get_by_id($lexem->variantOfId); if ($variantOf && !goodForVariantJson($meanings)) { FlashMessage::add("Acest lexem este o variantă a lui {$variantOf} și nu poate avea el însuși sensuri. " . "Este permis doar un sens, fără conținut, pentru indicarea surselor și a registrelor de folosire."); } if ($variantOf && !empty($variantIds)) { FlashMessage::add("Acest lexem este o variantă a lui {$variantOf} și nu poate avea el însuși variante."); } if ($variantOf && $variantOf->id == $lexem->id) { FlashMessage::add("Lexemul nu poate fi variantă a lui însuși."); } foreach ($variantIds as $variantId) { $variant = Lexem::get_by_id($variantId); if ($variant->id == $lexem->id) { FlashMessage::add('Lexemul nu poate fi variantă a lui însuși.'); } if ($variant->variantOfId && $variant->variantOfId != $lexem->id) { $other = Lexem::get_by_id($variant->variantOfId); FlashMessage::add("\"{$variant}\" este deja marcat ca variantă a lui \"{$other}\"."); } $variantVariantCount = Model::factory('Lexem')->where('variantOfId', $variant->id)->count(); if ($variantVariantCount) { FlashMessage::add("\"{$variant}\" are deja propriile lui variante."); } $variantMeanings = Model::factory('Meaning')->where('lexemId', $variant->id)->find_many(); if (!goodForVariant($variantMeanings)) { FlashMessage::add("\"{$variant}\" are deja propriile lui sensuri."); } } if ($lexem->structStatus == Lexem::STRUCT_STATUS_DONE && $original->structStatus != Lexem::STRUCT_STATUS_DONE && !util_isModerator(PRIV_EDIT)) { FlashMessage::add("Doar moderatorii pot marca structurarea drept terminată. Vă rugăm să folosiți valoarea „așteaptă moderarea”."); } return FlashMessage::getMessage() == null; }
util_assertModerator(PRIV_LOC); $submitButton = util_getRequestParameter('submitButton'); $inflectionIds = util_getRequestParameter('inflectionIds'); $newDescription = util_getRequestParameter('newDescription'); $newModelType = util_getRequestParameter('newModelType'); $deleteInflectionId = util_getRequestParameter('deleteInflectionId'); if ($deleteInflectionId) { $infl = Inflection::get_by_id($deleteInflectionId); $infl->delete(); util_redirect('flexiuni'); } if ($submitButton) { // Re-rank the inflections according to the order in $inflectionIds $modelTypeMap = array(); foreach ($inflectionIds as $inflId) { $infl = Inflection::get_by_id($inflId); $rank = array_key_exists($infl->modelType, $modelTypeMap) ? $modelTypeMap[$infl->modelType] + 1 : 1; $modelTypeMap[$infl->modelType] = $rank; $infl->rank = $rank; $infl->save(); } // Add a new inflection if one is given if ($newDescription) { $infl = Model::factory('Inflection')->create(); $infl->description = $newDescription; $infl->modelType = $newModelType; $infl->rank = $modelTypeMap[$newModelType] + 1; $infl->save(); } util_redirect('flexiuni'); }
$lexem->deleteLongInfinitive(); } $lexem->save(); // There are two reasons to regenerate the paradigm: the model has changed // or the form has changed. It's easier to do it every time. $lexem->regenerateParadigm(); log_userLog("Edited lexem {$lexem->id} ({$lexem->form})"); util_redirect("lexemEdit.php?lexemId={$lexem->id}"); } $definitions = Definition::loadByLexemId($lexem->id); $searchResults = SearchResult::mapDefinitionArray($definitions); $definitionLexem = mb_strtoupper(AdminStringUtil::internalize($lexem->form, false)); // Generate new inflected forms, but do not overwrite the old ones. $ifs = $lexem->generateParadigm(); if (!is_array($ifs)) { $infl = Inflection::get_by_id($ifs); if (!$errorMessage) { $errorMessage = "Nu pot genera flexiunea '" . htmlentities($infl->description) . "' " . "conform modelului {$lexem->modelType}{$lexem->modelNumber}."; } } else { $ifMap = InflectedForm::mapByInflectionRank($ifs); smarty_assign('ifMap', $ifMap); smarty_assign('searchResults', $searchResults); } $models = FlexModel::loadByType($lexem->modelType); $sources = LexemSources::getSourceArrayChecked($lexem->source); $sourceNames = LexemSources::getNamesOfSources($lexem->source); $canEditForm = !$lexem->isLoc || util_isModerator(PRIV_LOC); smarty_assign('lexem', $lexem); smarty_assign('sources', $sources); smarty_assign('sourceNames', $sourceNames);