Esempio n. 1
0
 public function addComment($values, $sub = false)
 {
     $data = ['byUser' => $this->userId, 'unregName' => isset($values->unregname) ? $values->unregname : null, 'date' => Helper::datTime(), 'text' => $this->fixComment($values->text), 'deleted' => 0];
     if ($sub !== false) {
         $data['forComment'] = $sub;
     } else {
         $data['forId'] = $this->forId;
         $data['forWhat'] = $this->forWhat;
     }
     return $this->commentDat($sub)->insert($data);
 }
Esempio n. 2
0
 /**
  * Check if pass code is OK and returns name of user
  * @param string $lostPasswordCode
  * @return string
  */
 public function newPasswordCheck($lostPasswordCode)
 {
     $data = $this->userDat()->where('lostPasswordCode', $lostPasswordCode)->fetch();
     if (!$data) {
         return false;
     }
     $timeDiff = (new \Nette\Utils\DateTime(Helper::datTime()))->diff($data->lostPasswordCodeTime);
     if ($timeDiff->y == 0 && $timeDiff->m == 0 && $timeDiff->d <= 2) {
         return Helper::combineUserName($data, false);
     }
     return false;
 }
Esempio n. 3
0
 public function updateArticle($values)
 {
     $data = ['url' => $this->checkUnique($values->title, 'articleDat', $values->id), 'title' => $values->title, 'text' => $values->text, 'keyWords' => $values->keyWords, 'underSection' => $values->underSection === 0 ? null : $values->underSection, 'underSubSection' => $values->underSubSection === 0 ? null : $values->underSubSection, 'underSerial' => $values->underSerial === 0 ? null : $values->underSerial, 'lastChange' => Helper::datTime(), 'commentsAllow' => $values->commentsAllow, 'voteAllow' => $values->voteAllow, 'description' => $values->description];
     if (!empty($values->byUser) && empty($values->byUnregUser)) {
         $data['byUser'] = $values->byUser;
         $data['byUnregUser'] = null;
     }
     if (!empty($values->byUnregUser)) {
         $data['byUnregUser'] = $values->byUnregUser;
         $data['byUser'] = null;
     }
     if (isset($values->published)) {
         $data['published'] = $values->published;
     }
     if (isset($values->deleted)) {
         $data['deleted'] = $values->deleted;
     }
     if ($values->photo->isOK()) {
         $photo = $this->genName($values->photo, $values->title);
         $this->savePhoto($photo);
         $data['photo'] = $photo['name'];
     }
     $this->articleDat()->where('id', $values->id)->update($data);
     if ($values->underSerial && $values->underSerial != $values->oldSerial) {
         if ($values->oldSerial) {
             $oldAO = $this->serialDat()->where('id', $values->oldSerial)->fetch()->articleOrder;
             $this->serialDat()->where('id', $values->oldSerial)->update(['articleOrder' => $this->delArticleFromSerial($values->id, $oldAO)]);
         }
         $newAO = $this->serialDat()->where('id', $values->underSerial)->fetch()->articleOrder;
         $this->serialDat()->where('id', $values->underSerial)->update(['articleOrder' => $this->addArticleToSerial($values->id, $newAO)]);
     }
 }
Esempio n. 4
0
 /**
  * Add to database
  * @param array $values
  * @param int $userId
  */
 public function addNews($values, $userId)
 {
     $this->newsDat()->insert(['byUser' => $userId, 'url' => $this->checkUnique($values->title), 'title' => $values->title, 'text' => $values->text, 'keyWords' => $values->keyWords ? $values->keyWords : '', 'date' => \App\Helper\Helper::datTime()]);
 }