static function loadAllForLexems($lexems) { $map = array(); foreach ($lexems as $l) { $vs = Visual::get_all_by_lexemeId($l->id); foreach ($vs as $v) { $map[$v->id] = $v; } $vts = VisualTag::get_all_by_lexemeId($l->id); foreach ($vts as $vt) { $v = Visual::get_by_id($vt->imageId); $map[$v->id] = $v; } } foreach ($map as $v) { $v->ensureThumb(); } return array_values($map); }
function handleLexemActions() { $lexemId = util_getRequestParameter('lexemId'); $lexem = Lexem::get_by_id($lexemId); $associateDefinitionId = util_getRequestParameter('associateDefinitionId'); if ($associateDefinitionId) { LexemDefinitionMap::associate($lexem->id, $associateDefinitionId); util_redirect("lexemEdit.php?lexemId={$lexem->id}"); } $dissociateDefinitionId = util_getRequestParameter('dissociateDefinitionId'); if ($dissociateDefinitionId) { LexemDefinitionMap::dissociate($lexem->id, $dissociateDefinitionId); util_redirect("lexemEdit.php?lexemId={$lexem->id}"); } $createDefinition = util_getRequestParameter('createDefinition'); $miniDefTarget = util_getRequestParameter('miniDefTarget'); if ($createDefinition) { $def = Model::factory('Definition')->create(); $def->userId = session_getUserId(); $def->sourceId = Source::get_by_shortName('Neoficial')->id; $def->lexicon = $lexem->formNoAccent; $def->internalRep = '@' . mb_strtoupper(AdminStringUtil::internalize($lexem->form, false)) . '@ v. @' . $miniDefTarget . '.@'; $def->htmlRep = AdminStringUtil::htmlize($def->internalRep, $def->sourceId); $def->status = Definition::ST_ACTIVE; $def->save(); LexemDefinitionMap::associate($lexem->id, $def->id); util_redirect("lexemEdit.php?lexemId={$lexem->id}"); } $deleteLexem = util_getRequestParameter('deleteLexem'); if ($deleteLexem) { $homonyms = Model::factory('Lexem')->where('formNoAccent', $lexem->formNoAccent)->where_not_equal('id', $lexem->id)->find_many(); $lexem->delete(); SmartyWrap::assign('lexem', $lexem); SmartyWrap::assign('homonyms', $homonyms); SmartyWrap::displayAdminPage('admin/lexemDeleted.tpl'); exit; } $cloneLexem = util_getRequestParameter('cloneLexem'); if ($cloneLexem) { $newLexem = $lexem->cloneLexem(); log_userLog("Cloned lexem {$lexem->id} ({$lexem->form}), new id is {$newLexem->id}"); util_redirect("lexemEdit.php?lexemId={$newLexem->id}"); } $mergeLexem = util_getRequestParameter('mergeLexem'); $mergeLexemId = util_getRequestParameter('mergeLexemId'); if ($mergeLexem) { $other = Lexem::get_by_id($mergeLexemId); if ($lexem->form != $other->form) { FlashMessage::add('Nu pot unifica lexemele deoarece accentele diferă. Rezolvați diferența și încercați din nou.'); util_redirect("lexemEdit.php?lexemId={$lexem->id}"); } $defs = Definition::loadByLexemId($lexem->id); foreach ($defs as $def) { LexemDefinitionMap::associate($other->id, $def->id); } // Add lexem models from $lexem to $other if the form is the same. Exclude T-type models. $displayOrder = count($other->getLexemModels()); foreach ($lexem->getLexemModels() as $lm) { if ($lm->modelType != 'T' && !$other->hasModel($lm->modelType, $lm->modelNumber)) { $lm->lexemId = $other->id; $lm->displayOrder = ++$displayOrder; $lm->save(); } } // Add meanings from $lexem to $other and renumber their displayOrder and breadcrumb // displayOrders are generated sequentially regardless of level. // Breadcrumbs follow levels so only their first part changes. $counter = Model::factory('Meaning')->where('lexemId', $other->id)->count(); $numRoots = Model::factory('Meaning')->where('lexemId', $other->id)->where('parentId', 0)->count(); $meanings = Model::factory('Meaning')->where('lexemId', $lexem->id)->order_by_asc('displayOrder')->find_many(); foreach ($meanings as $m) { $m->lexemId = $other->id; $m->displayOrder = ++$counter; $parts = explode('.', $m->breadcrumb, 2); $parts[0] += $numRoots; $m->breadcrumb = implode('.', $parts); $m->save(); } // Add images and image tags from $lexem to $other $visuals = Visual::get_all_by_lexemeId($lexem->id); foreach ($visuals as $v) { $v->lexemeId = $other->id; $v->save(); } $visualTags = VisualTag::get_all_by_lexemeId($lexem->id); foreach ($visualTags as $vt) { $vt->lexemeId = $other->id; $vt->save(); } $lexem->delete(); util_redirect("lexemEdit.php?lexemId={$other->id}"); } }