/** * Function creates new gallery and saves it to database. * Gallery has user id, title, tag and date of creation. * Title and tag are entered by user. */ public function action() { checkUnauthorizedAccess(); $main = new Main(); $main->setPageTitle("Create gallery"); $body = new \templates\AddGallery(); $main->setBody($body); echo $main; $username = $_SESSION['username']; if (post('addGallery')) { $userID = UserRepository::getIdByUsername($username); $title = trim(post('galleryTitle')); $tag = trim(post('galleryTag')); $dateOfCreation = date('Y-m-d H:i:s'); //server side validation of data $error = false; if (strlen($title) < 4 || strlen($title) > 25) { $error = true; } if (strlen($tag) < 3 || strlen($tag) > 25) { $error = true; } if (!$error) { $gallery = new Gallery(); $gallery->setUserID($userID); $gallery->setTitle($title); $gallery->setTag($tag); $gallery->setCreated($dateOfCreation); try { GalleryRepository::addGallery($gallery); redirect(\route\Route::get("listGalleries")->generate()); } catch (\PDOException $e) { $e->getMessage(); } } } }
/** * @param ChildGallery $gallery The ChildGallery object to add. */ protected function doAddGallery(ChildGallery $gallery) { $this->collGalleries[] = $gallery; $gallery->setUser($this); }
/** * Validates and create the gallery resource * @param array $data the data with which the model will be populated * @return the created gallery model */ public function store($author_id, $data) { $data['author_id'] = $author_id; $this->validation($data); return \Models\Gallery::create($data); }
/** * Filter the query by a related \Models\Gallery object * * @param \Models\Gallery|ObjectCollection $gallery the related object to use as filter * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return ChildUserQuery The current query, for fluid interface */ public function filterByGallery($gallery, $comparison = null) { if ($gallery instanceof \Models\Gallery) { return $this->addUsingAlias(UserTableMap::COL_ID, $gallery->getIdUser(), $comparison); } elseif ($gallery instanceof ObjectCollection) { return $this->useGalleryQuery()->filterByPrimaryKeys($gallery->getPrimaryKeys())->endUse(); } else { throw new PropelException('filterByGallery() only accepts arguments of type \\Models\\Gallery or Collection'); } }
public function saveGallery() { $dir = "includes/images/fullsize/"; foreach ($_POST["image"] as $post) { $d = explode(',', $post); $img = imagecreatefromstring(base64_decode($d[1])); do { $name = token(20) . ".png"; $path = $dir . $name; } while (file_exists($path)); $i = new Image(); $i->setPath($name)->setDescription("Fotografie z galerie " . $_POST["title"])->setThumbnailPath($name)->setType("fullsize")->save(); imagepng(resizeImg($img, 1280, 720), $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); $names[] = $name; } $gal = new Gallery(); $gal->setIdUser($_POST["author"]); $token = token(50); $gal->setName($token); $gal->save(); $imgs = ImageQuery::create()->filterByPath($names)->find(); $gal = GalleryQuery::create()->filterByName($token)->findOne(); $gal->setName($_POST["title"]); $gal->save(); foreach ($imgs as $i) { $map = new ImageGalleryMap(); $map->setIdImage($i->getId()); $map->setIdGallery($gal->getId()); $map->save(); } $this->addPopup('success', 'Galerie byla úspěšně vytvořena.'); redirectTo('/administrace/galerie'); }
private static function insert(Gallery $model) { $db = Database::getInstance('app'); $query = "INSERT INTO gallery (source,carousel,title,description,post_date,titleBG,descriptionBG) VALUES (:source, :carousel, :title, :description, :post_date, :titleBG, :descriptionBG);"; $result = $db->prepare($query); $result->execute([':source' => $model->getSource(), ':carousel' => $model->getCarousel(), ':title' => $model->getTitle(), ':description' => $model->getDescription(), ':post_date' => $model->getPost_date(), ':titleBG' => $model->getTitleBG(), ':descriptionBG' => $model->getDescriptionBG()]); $model->setId($db->lastId()); }
/** * Creates gallery and saves it to database. * @param Gallery $gallery */ public static function addGallery(Gallery $gallery) { $db = Database::getInstance(); $query = $db->prepare('INSERT INTO gallery (userid,title,tag,created) VALUES (?, ?, ?, ?)'); $query->execute([$gallery->getUserID(), $gallery->getTitle(), $gallery->getTag(), $gallery->getCreated()]); }