/** * @inheritdoc */ protected function buildForm() { $formBuilder = $this->formBuilder; $carousels = CarouselQuery::create()->orderByPosition()->find(); /** @var \Carousel\Model\Carousel $carousel */ foreach ($carousels as $carousel) { $id = $carousel->getId(); $formBuilder->add('position' . $id, 'text', ['label' => $this->translator->trans('Image position in carousel', [], Carousel::DOMAIN_NAME), 'label_attr' => ['for' => 'position' . $id], 'required' => false, 'attr' => ['placeholder' => $this->translator->trans('Image position in carousel', [], Carousel::DOMAIN_NAME)]])->add('alt' . $id, 'text', ['label' => $this->translator->trans('Alternative image text', [], Carousel::DOMAIN_NAME), 'label_attr' => ['for' => 'alt' . $id], 'required' => false, 'attr' => ['placeholder' => $this->translator->trans('Displayed when image is not visible', [], Carousel::DOMAIN_NAME)]])->add('url' . $id, 'url', ['label' => $this->translator->trans('Image URL', [], Carousel::DOMAIN_NAME), 'label_attr' => ['for' => 'url' . $id], 'required' => false, 'attr' => ['placeholder' => $this->translator->trans('Please enter a valid URL', [], Carousel::DOMAIN_NAME)]])->add('title' . $id, 'text', ['constraints' => [], 'required' => false, 'label' => $this->translator->trans('Title'), 'label_attr' => ['for' => 'title_field' . $id], 'attr' => ['placeholder' => $this->translator->trans('A descriptive title')]])->add('chapo' . $id, 'textarea', ['constraints' => [], 'required' => false, 'label' => $this->translator->trans('Summary'), 'label_attr' => ['for' => 'summary_field' . $id, 'help' => $this->translator->trans('A short description, used when a summary or an introduction is required')], 'attr' => ['rows' => 3, 'placeholder' => $this->translator->trans('Short description text')]])->add('description' . $id, 'textarea', ['constraints' => [], 'required' => false, 'label' => $this->translator->trans('Detailed description'), 'label_attr' => ['for' => 'detailed_description_field' . $id, 'help' => $this->translator->trans('The detailed description.')], 'attr' => ['rows' => 5]])->add('postscriptum' . $id, 'textarea', ['constraints' => [], 'required' => false, 'label' => $this->translator->trans('Conclusion'), 'label_attr' => ['for' => 'conclusion_field' . $id, 'help' => $this->translator->trans('A short text, used when an additional or supplemental information is required.')], 'attr' => ['placeholder' => $this->translator->trans('Short additional text'), 'rows' => 3]]); } }
public function deleteAction() { if (null !== ($response = $this->checkAuth(AdminResources::MODULE, ['carousel'], AccessManager::DELETE))) { return $response; } $imageId = $this->getRequest()->request->get('image_id'); if ($imageId != "") { $carousel = CarouselQuery::create()->findPk($imageId); if (null !== $carousel) { $carousel->delete(); } } return $this->redirectToConfigurationPage(); }
/** * Performs an INSERT on the database, given a Carousel or Criteria object. * * @param mixed $criteria Criteria or Carousel object containing data that is used to create the INSERT statement. * @param ConnectionInterface $con the ConnectionInterface connection to use * @return mixed The new primary key. * @throws PropelException Any exceptions caught during processing will be * rethrown wrapped into a PropelException. */ public static function doInsert($criteria, ConnectionInterface $con = null) { if (null === $con) { $con = Propel::getServiceContainer()->getWriteConnection(CarouselTableMap::DATABASE_NAME); } if ($criteria instanceof Criteria) { $criteria = clone $criteria; // rename for clarity } else { $criteria = $criteria->buildCriteria(); // build Criteria from Carousel object } if ($criteria->containsKey(CarouselTableMap::ID) && $criteria->keyContainsValue(CarouselTableMap::ID)) { throw new PropelException('Cannot insert a value for auto-increment primary key (' . CarouselTableMap::ID . ')'); } // Set the correct dbName $query = CarouselQuery::create()->mergeWith($criteria); try { // use transaction because $criteria could contain info // for more than one table (I guess, conceivably) $con->beginTransaction(); $pk = $query->doInsert($con); $con->commit(); } catch (PropelException $e) { $con->rollBack(); throw $e; } return $pk; }
/** * this method returns a Propel ModelCriteria * * @return \Propel\Runtime\ActiveQuery\ModelCriteria */ public function buildModelCriteria() { $search = CarouselQuery::create(); $this->configureI18nProcessing($search, ['ALT', 'TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM']); $orders = $this->getOrder(); // Results ordering foreach ($orders as $order) { switch ($order) { case "alpha": $search->addAscendingOrderByColumn('i18n_TITLE'); break; case "alpha-reverse": $search->addDescendingOrderByColumn('i18n_TITLE'); break; case "manual-reverse": $search->orderByPosition(Criteria::DESC); break; case "manual": $search->orderByPosition(Criteria::ASC); break; case "random": $search->clearOrderByColumns(); $search->addAscendingOrderByColumn('RAND()'); break 2; break; } } return $search; }
/** * Get the Query instance for this object * * @return ModelCriteria */ public function getQueryInstance() { return CarouselQuery::create(); }
/** * Returns a new ChildCarouselQuery object. * * @param string $modelAlias The alias of a model in the query * @param Criteria $criteria Optional Criteria to build the query from * * @return ChildCarouselQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof \Carousel\Model\CarouselQuery) { return $criteria; } $query = new \Carousel\Model\CarouselQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
/** * this method returns a Propel ModelCriteria * * @return \Propel\Runtime\ActiveQuery\ModelCriteria */ public function buildModelCriteria() { $search = CarouselQuery::create(); $this->configureI18nProcessing($search, ['ALT', 'TITLE', 'CHAPO', 'DESCRIPTION', 'POSTSCRIPTUM']); $search->orderByPosition(); return $search; }
/** * Get the associated ChildCarousel object * * @param ConnectionInterface $con Optional Connection object. * @return ChildCarousel The associated ChildCarousel object. * @throws PropelException */ public function getCarousel(ConnectionInterface $con = null) { if ($this->aCarousel === null && $this->id !== null) { $this->aCarousel = ChildCarouselQuery::create()->findPk($this->id, $con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aCarousel->addCarouselI18ns($this); */ } return $this->aCarousel; }
/** * Removes this object from datastore and sets delete attribute. * * @param ConnectionInterface $con * @return void * @throws PropelException * @see Carousel::setDeleted() * @see Carousel::isDeleted() */ public function delete(ConnectionInterface $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getServiceContainer()->getWriteConnection(CarouselTableMap::DATABASE_NAME); } $con->beginTransaction(); try { $deleteQuery = ChildCarouselQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }