コード例 #1
0
/**
 * 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;
}
コード例 #2
0
ファイル: wotdExport.php プロジェクト: florinp/dexonline
<?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');
コード例 #3
0
 /**
  * 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 '';
 }
コード例 #4
0
ファイル: wotdSave.php プロジェクト: florinp/dexonline
 /**
  * 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 '';
 }