/**
  * @return string
  * @throws \Propel\Runtime\Exception\PropelException
  */
 public function postArticle()
 {
     $data = \Kernel::getInstance()->app->request()->post();
     $article = new Article();
     $article->fromArray($data);
     return $this->response(['success' => (bool) $article->save()], 201);
 }
Beispiel #2
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      ConnectionInterface $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see save()
  */
 protected function doSave(ConnectionInterface $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aUser !== null) {
             if ($this->aUser->isModified() || $this->aUser->isNew()) {
                 $affectedRows += $this->aUser->save($con);
             }
             $this->setUser($this->aUser);
         }
         if ($this->aArticle !== null) {
             if ($this->aArticle->isModified() || $this->aArticle->isNew()) {
                 $affectedRows += $this->aArticle->save($con);
             }
             $this->setArticle($this->aArticle);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
                 $affectedRows += 1;
             } else {
                 $affectedRows += $this->doUpdate($con);
             }
             $this->resetModified();
         }
         if ($this->ratingsScheduledForDeletion !== null) {
             if (!$this->ratingsScheduledForDeletion->isEmpty()) {
                 \Models\RatingQuery::create()->filterByPrimaryKeys($this->ratingsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->ratingsScheduledForDeletion = null;
             }
         }
         if ($this->collRatings !== null) {
             foreach ($this->collRatings as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Beispiel #3
0
 public function articleSave()
 {
     //If saving a new article
     if ($_POST["save"] == "Přidat") {
         $article = new Article();
         $article->setIdUser($_POST["author"]);
         if (isset($_POST["image-article"])) {
             $data = explode(',', $_POST["image-article"]);
             if (count($data) == 2 && $data[0] == "data:image/png;base64" && base64_decode($data[1])) {
                 $dir = "includes/images/fullsize/";
                 $img = imagecreatefromstring(base64_decode($data[1]));
                 do {
                     $name = token(20) . ".png";
                     $path = $dir . $name;
                 } while (file_exists($path));
                 $i = new Image();
                 $i->setPath($name)->setThumbnailPath($name)->setType("fullsize")->save();
                 imagepng($img, $path);
                 $dir = "includes/images/960x540/";
                 $path = $dir . $name;
                 imagepng(resizeImg($img, 960, 540), $path);
                 $dir = "includes/images/50x50/";
                 $path = $dir . $name;
                 imagepng(resizeImg($img, 50, 50), $path);
             } else {
                 $this->addPopup('danger', 'Něco se pokazilo při nahrávání obrázku. Zkuste to prosím znovu.');
                 redirectTo('/administrace/clanky/pridat');
             }
         } else {
             $this->addPopup('danger', 'Něco se pokazilo při nahrávání obrázku. Zkuste to prosím znovu.');
             redirectTo('/administrace/clanky/pridat');
         }
         $im = ImageQuery::create()->filterByPath($name)->findOne();
         $article->setIdImage($im->getId());
         $article->setIdCategory($_POST["category"]);
         $article->setTitle($_POST["title"]);
         $article->setKeywords(str_replace(", ", ",", $_POST["keywords"]));
         $article->setContent($_POST["content"]);
         $article->save();
         $article = ArticleQuery::create()->orderByCreatedAt('desc')->findOne();
         $article->setUrl($article->getId());
         $article->save();
         $this->addPopup('success', 'Článek byl úspěšně přidán!');
         redirectTo("/administrace");
     } elseif ($_POST["save"] == "Upravit") {
         $article = ArticleQuery::create()->findPk($_POST["article"]);
         $article->setIdCategory($_POST["category"]);
         $article->setTitle($_POST["title"]);
         $article->setKeywords(str_replace(", ", ",", $_POST["keywords"]));
         $article->setContent($_POST["content"]);
         if (isset($_POST["image-article"])) {
             $data = explode(',', $_POST["image-article"]);
             if (count($data) == 2 && $data[0] == "data:image/png;base64" && base64_decode($data[1])) {
                 $dir = "includes/images/fullsize/";
                 $img = imagecreatefromstring(base64_decode($data[1]));
                 do {
                     $name = token(20) . ".png";
                     $path = $dir . $name;
                 } while (file_exists($path));
                 $i = new Image();
                 $i->setPath($name)->setThumbnailPath($name)->setType("fullsize")->save();
                 imagepng($img, $path);
                 $dir = "includes/images/960x540/";
                 $path = $dir . $name;
                 imagepng(resizeImg($img, 960, 540), $path);
                 $dir = "includes/images/50x50/";
                 $path = $dir . $name;
                 imagepng(resizeImg($img, 50, 50), $path);
                 $im = ImageQuery::create()->filterByPath($name)->findOne();
                 $article->setIdImage($im->getId());
             } else {
                 $this->addPopup('danger', 'Něco se pokazilo při nahrávání obrázku. Zkuste to prosím znovu.');
                 redirectTo('/administrace/clanek/' . $id . '/upravit');
             }
         }
         $article->save();
         $this->addPopup('success', 'Článek byl úspěšně upraven!');
         redirectTo("/administrace/clanky");
     }
 }