/** * Creates a matrix with 7 columns, one per day of week, and as many rows (weeks) as necessary. * Every cell contains a dictionary with the wotd, the definition and other info. */ function createCalendar($year, $month) { $days = listDaysOfMonth($year, $month); $today = date('Y-m-d'); $calendar = array(); // Pad beginning $startDow = date('N', strtotime("{$year}-{$month}-01")); for ($i = 1; $i < $startDow; $i++) { $calendar[] = array(); } // Create a record per day foreach ($days as $i => $date) { $wotd = WordOfTheDay::get_by_displayDate($date); $wotdr = $wotd ? WordOfTheDayRel::get_by_wotdId($wotd->id) : null; $def = $wotdr ? Definition::get_by_id($wotdr->refId) : null; $visible = $def && ($date <= $today || util_isModerator(PRIV_WOTD)); $calendar[] = array('wotd' => $wotd, 'def' => $def, 'visible' => $visible, 'dayOfMonth' => $i + 1); } // Pad end while (count($calendar) % 7 != 0) { $calendar[] = array(); } // Wrap 7 records per line $weeks = array(); while (count($calendar)) { $weeks[] = array_splice($calendar, 0, 7); } return $weeks; }
}); $wordCount = Definition::getWordCount(); $wordCountRough = $wordCount - $wordCount % 10000; SmartyWrap::assign('page_title', 'Dicționar explicativ al limbii române'); SmartyWrap::assign('onHomePage', '1'); SmartyWrap::assign('letters', preg_split('//u', 'aăâbcdefghiîjklmnopqrsștțuvwxyz')); SmartyWrap::assign('words_total', util_formatNumber($wordCount, 0)); SmartyWrap::assign('words_rough', util_formatNumber($wordCountRough, 0)); SmartyWrap::assign('words_last_month', util_formatNumber(Definition::getWordCountLastMonth(), 0)); SmartyWrap::assign('widgets', $widgets); SmartyWrap::assign('numEnabledWidgets', $numEnabledWidgets); /* WotD part */ $wotd = WordOfTheDay::getTodaysWord(); if (!$wotd) { WordOfTheDay::updateTodaysWord(); $wotd = WordOfTheDay::getTodaysWord(); } $defId = WordOfTheDayRel::getRefId($wotd->id); $def = Model::factory('Definition')->where('id', $defId)->where('status', ST_ACTIVE)->find_one(); SmartyWrap::assign('thumbUrl', $wotd->getThumbUrl()); SmartyWrap::assign('title', $def->lexicon); SmartyWrap::assign('today', date('Y/m/d')); /* WotM part */ $wotm = WordOfTheMonth::getCurrentWotM(); $def = Model::factory('Definition')->where('id', $wotm->definitionId)->where('status', ST_ACTIVE)->find_one(); SmartyWrap::assign('thumbUrlM', $wotm->getThumbUrl()); SmartyWrap::assign('articol', $wotm->article); SmartyWrap::assign('titleM', $def->lexicon); SmartyWrap::assign('todayM', date('Y/m')); $page = Config::get('global.aprilFoolsDay') ? 'index-afd.ihtml' : 'index.ihtml'; SmartyWrap::displayPageWithSkin($page);
} if (!$sendEmail) { print "---- DRY RUN ----\n"; } $messages = array(); $firstProblem = 0; for ($d = 0; $d <= NUM_DAYS; $d++) { $date = date("Y-m-d", strtotime("+{$d} days")); // Check that exactly one WotD exists $wotds = WordOfTheDay::get_all_by_displayDate($date); if (count($wotds) != 1) { $messages[$date] = count($wotds) ? sprintf("Există %s cuvinte", count($wotds)) : "Nu există niciun cuvânt"; continue; } // Check that it has exactly one WotD rel $rels = WordOfTheDayRel::get_all_by_wotdId($wotds[0]->id); if (count($rels) != 1) { $messages[$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) { $messages[$date] = sprintf("Definiția cu id-ul %s nu există", $rels[0]->refId); continue; } // Check that there is an image if (!$wotds[0]->image) { $messages[$date] = sprintf("Definiția '%s' nu are o imagine asociată", $def->lexicon); continue; }
<?php require_once "../../phplib/util.php"; util_assertModerator(PRIV_WOTD); $month = util_getRequestParameter('month'); $year = util_getRequestParameter('year'); $month = sprintf("%02d", $month); $wotds = Model::factory('WordOfTheDay')->where_like('displayDate', "{$year}-{$month}-%")->order_by_asc('displayDate')->find_many(); $wotdSet = array(); foreach ($wotds as $wotd) { $wotdr = WordOfTheDayRel::get_by_wotdId($wotd->id); $def = Definition::get_by_id($wotdr->refId); $wotdSet[] = array('wotd' => $wotd, 'def' => $def); } SmartyWrap::assign('month', $month); SmartyWrap::assign('year', $year); SmartyWrap::assign('recentLinks', RecentLink::loadForUser()); SmartyWrap::assign('wotdSet', $wotdSet); SmartyWrap::displayAdminPage('admin/wotdExport.tpl');
/** * Deletes a row from the wotd table * @access protected * @return string * */ protected function doDelete() { $wotd = WordOfTheDay::get_by_id($this->id); $wotd->delete(); $wotdr = WordOfTheDayRel::get_by_wotdId($this->id); $wotdr->delete(); return ''; }
/** * Saves the data * @access protected * @return error string (empty for success) * */ protected function doSave() { if ($this->id != null) { $wotd = WordOfTheDay::get_by_id($this->id); } else { $wotd = Model::factory('WordOfTheDay')->create(); $wotd->userId = session_getUserId(); } $today = date('Y-m-d', time()); $isPast = $wotd->displayDate && $wotd->displayDate < $today; if ($isPast && $this->displayDate != $wotd->displayDate) { return 'Nu puteți modifica data pentru un cuvânt al zilei deja afișat'; } if (!$this->refId) { return 'Trebuie să alegeți o definiție'; } $wotd->displayDate = $this->displayDate ? $this->displayDate : null; $wotd->priority = $this->priority; $wotd->image = $this->image; $wotd->description = $this->description; $wotd->save(); $wotdr = WordOfTheDayRel::get_by_wotdId($wotd->id); if (!$wotdr) { $wotdr = Model::factory('WordOfTheDayRel')->create(); } $wotdr->refId = $this->refId; $wotdr->refType = $this->refType ? $this->refType : 'Definition'; $wotdr->wotdId = $wotd->id; $wotdr->save(); return ''; }