public static function loadPositionsByLexemIdsDefinitionIds($lmMap, $defIds) { $positionMap = array(); foreach ($lmMap as $lmIds) { if (!empty($lmIds)) { // Load all positions in all definitions for this LexemModel set $query = sprintf('select distinct definitionId, position from FullTextIndex ' . 'where lexemModelId in (%s) ' . 'and definitionId in (%s) ' . 'order by definitionId, position', implode(',', $lmIds), implode(',', $defIds)); $results = db_getArrayOfRows($query, PDO::FETCH_NUM); $results[] = array(-1, -1); // sentinel // Now iterate in defId order and collect position arrays $i = 0; while ($i < count($results) - 1) { $defId = $results[$i][0]; $positions = array(); // collect positions here $j = $i; while ($results[$j][0] == $defId) { // same defId $positions[] = $results[$j][1]; $j++; } if (array_key_exists($defId, $positionMap)) { $positionMap[$defId][] = $positions; } else { $positionMap[$defId] = array($positions); } $i = $j; } } } return $positionMap; }
public static function loadAllTitles() { $rows = db_getArrayOfRows("select section, title from WikiArticle left join WikiSection using (pageId) order by section, title"); $result = array(); foreach ($rows as $row) { $result[$row['section']][] = array($row['title'], WikiArticle::wikiTitleToUrlTitle($row['title'])); } return $result; }
if (!is_int($showSource) || $showSource != 1) { $showSource = DEFAULT_SHOW_LIST; } $noSkin = (int) util_getRequestParameter('k'); if (!is_int($noSkin) || $noSkin != 1) { $noSkin = DEFAULT_SHOW_LIST; } /* $query = sprintf('select id from Lexem order by rand() limit %d', $listLength); $ids = db_getArray($query); $query = sprintf(RANDOM_WORDS_QUERY, $showSource?SOURCE_PART_RANDOM_WORDS:'', implode(",",$ids)); $forms = db_getArrayOfRows($query); */ $wotd = ''; if (is_null($wListLength)) { $query = sprintf(RANDOM_WORDS_QUERY, $showSource ? SOURCE_PART_RANDOM_WORDS : '', $listLength); } else { $query = sprintf(RANDOM_WOTD_QUERY, $wListLength); $wotd = ' ale zilei'; } $forms = db_getArrayOfRows($query); $cnt = count($forms); if ($noSkin) { SmartyWrap::assign('forms', $forms); SmartyWrap::displayWithoutSkin('randomWordListSimple.ihtml'); } else { SmartyWrap::assign('forms', $forms); SmartyWrap::assign('page_title', "O listă de {$cnt} de cuvinte{$wotd} alese la întâmplare."); SmartyWrap::display('randomWordList.ihtml'); }
// Check that it has exactly one WotD rel $rels = WordOfTheDayRel::get_all_by_wotdId($wotd->id); if (count($rels) != 1) { addError($date, count($rels) ? sprintf("Există %s definiții asociate", count($rels)) : "Nu există nicio definiție asociată"); continue; } // Check that the definition exists $def = Definition::get_by_id($rels[0]->refId); if (!$def) { addError($date, sprintf("Definiția cu id-ul %s nu există", $rels[0]->refId)); continue; } // Check that we haven't had the same word or a similar one in the past. // Currently we look for words that contain, or are contained by, the proposed word. $query = sprintf("select d.lexicon, w.displayDate " . "from WordOfTheDay w, WordOfTheDayRel r, Definition d " . "where w.id = r.wotdId " . "and r.refId = d.id " . "and r.refType = 'Definition' " . "and w.displayDate < '%s' " . "and char_length(lexicon) >= 4 " . "and ((instr('%s', lexicon) > 0) or (lexicon like '%%%s%%'))", $date, $def->lexicon, $def->lexicon); $dups = db_getArrayOfRows($query); if (count($dups)) { $msg = "Cuvântul {$def->lexicon} seamnănă cu următoarele cuvinte deja propuse:"; foreach ($dups as $dup) { $msg .= " {$dup[0]} ({$dup[1]})"; } addInfo($date, $msg); } // Check that there is an artist $artist = WotdArtist::getByDate($date); if (!$artist) { addError($date, 'Niciun artist nu este asignat; verificați conținutul fișierului docs/imageCredits/wotd.desc'); } // Check that there is an image if (!$wotd->image) { $assignedImage = assignImageByName($wotd, $def);