Beispiel #1
0
 /**
  * Ensure the proper deployment of the module's images.
  *
  * TODO : this method does not take care of internationalization. This is a bug.
  *
  * @param Module              $module     the module
  * @param string              $folderPath the image folder path
  * @param ConnectionInterface $con
  *
  * @throws \Thelia\Exception\ModuleException
  * @throws \Exception
  * @throws \UnexpectedValueException
  */
 public function deployImageFolder(Module $module, $folderPath, ConnectionInterface $con = null)
 {
     try {
         $directoryBrowser = new \DirectoryIterator($folderPath);
     } catch (\UnexpectedValueException $e) {
         throw $e;
     }
     if (null === $con) {
         $con = Propel::getConnection(ModuleImageTableMap::DATABASE_NAME);
     }
     /* browse the directory */
     $imagePosition = 1;
     /** @var \DirectoryIterator $directoryContent */
     foreach ($directoryBrowser as $directoryContent) {
         /* is it a file ? */
         if ($directoryContent->isFile()) {
             $fileName = $directoryContent->getFilename();
             $filePath = $directoryContent->getPathName();
             /* is it a picture ? */
             if (Image::isImage($filePath)) {
                 $con->beginTransaction();
                 $image = new ModuleImage();
                 $image->setModuleId($module->getId());
                 $image->setPosition($imagePosition);
                 $image->save($con);
                 $imageDirectory = sprintf("%s/../../../../local/media/images/module", __DIR__);
                 $imageFileName = sprintf("%s-%d-%s", $module->getCode(), $image->getId(), $fileName);
                 $increment = 0;
                 while (file_exists($imageDirectory . '/' . $imageFileName)) {
                     $imageFileName = sprintf("%s-%d-%d-%s", $module->getCode(), $image->getId(), $increment, $fileName);
                     $increment++;
                 }
                 $imagePath = sprintf('%s/%s', $imageDirectory, $imageFileName);
                 if (!is_dir($imageDirectory)) {
                     if (!@mkdir($imageDirectory, 0777, true)) {
                         $con->rollBack();
                         throw new ModuleException(sprintf("Cannot create directory : %s", $imageDirectory), ModuleException::CODE_NOT_FOUND);
                     }
                 }
                 if (!@copy($filePath, $imagePath)) {
                     $con->rollBack();
                     throw new ModuleException(sprintf("Cannot copy file : %s to : %s", $filePath, $imagePath), ModuleException::CODE_NOT_FOUND);
                 }
                 $image->setFile($imageFileName);
                 $image->save($con);
                 $con->commit();
                 $imagePosition++;
             }
         }
     }
 }
Beispiel #2
0
 /**
  * Declares an association between this object and a ChildModuleImage object.
  *
  * @param                  ChildModuleImage $v
  * @return                 \Thelia\Model\ModuleImageI18n The current object (for fluent API support)
  * @throws PropelException
  */
 public function setModuleImage(ChildModuleImage $v = null)
 {
     if ($v === null) {
         $this->setId(NULL);
     } else {
         $this->setId($v->getId());
     }
     $this->aModuleImage = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the ChildModuleImage object, it will not be re-added.
     if ($v !== null) {
         $v->addModuleImageI18n($this);
     }
     return $this;
 }
Beispiel #3
0
 /**
  * Filter the query by a related \Thelia\Model\ModuleImage object
  *
  * @param \Thelia\Model\ModuleImage|ObjectCollection $moduleImage  the related object to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildModuleQuery The current query, for fluid interface
  */
 public function filterByModuleImage($moduleImage, $comparison = null)
 {
     if ($moduleImage instanceof \Thelia\Model\ModuleImage) {
         return $this->addUsingAlias(ModuleTableMap::ID, $moduleImage->getModuleId(), $comparison);
     } elseif ($moduleImage instanceof ObjectCollection) {
         return $this->useModuleImageQuery()->filterByPrimaryKeys($moduleImage->getPrimaryKeys())->endUse();
     } else {
         throw new PropelException('filterByModuleImage() only accepts arguments of type \\Thelia\\Model\\ModuleImage or Collection');
     }
 }
Beispiel #4
0
 /**
  * Exclude object from result
  *
  * @param   ChildModuleImage $moduleImage Object to remove from the list of results
  *
  * @return ChildModuleImageQuery The current query, for fluid interface
  */
 public function prune($moduleImage = null)
 {
     if ($moduleImage) {
         $this->addUsingAlias(ModuleImageTableMap::ID, $moduleImage->getId(), Criteria::NOT_EQUAL);
     }
     return $this;
 }
 /**
  * Filter the query by a related \Thelia\Model\ModuleImage object
  *
  * @param \Thelia\Model\ModuleImage|ObjectCollection $moduleImage The related object(s) to use as filter
  * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
  *
  * @return ChildModuleImageI18nQuery The current query, for fluid interface
  */
 public function filterByModuleImage($moduleImage, $comparison = null)
 {
     if ($moduleImage instanceof \Thelia\Model\ModuleImage) {
         return $this->addUsingAlias(ModuleImageI18nTableMap::ID, $moduleImage->getId(), $comparison);
     } elseif ($moduleImage instanceof ObjectCollection) {
         if (null === $comparison) {
             $comparison = Criteria::IN;
         }
         return $this->addUsingAlias(ModuleImageI18nTableMap::ID, $moduleImage->toKeyValue('PrimaryKey', 'Id'), $comparison);
     } else {
         throw new PropelException('filterByModuleImage() only accepts arguments of type \\Thelia\\Model\\ModuleImage or Collection');
     }
 }