protected function initRelation(Block $block, $timetable)
 {
     $externalStopPointId = $block->getStopPoint();
     // all blocks are linked at least to a timetable
     $this->block->setTimetable($timetable);
     if (!empty($externalStopPointId)) {
         // link block to this stop point
         $this->block->setStopPoint($this->getStopPointReference($externalStopPointId, $timetable));
     }
 }
 public function __construct(Block $block)
 {
     $layout = $block->getTimetable()->getLineConfig()->getLayoutConfig();
     $extension = new CalendarExtension();
     $this->hoursRange = $extension->calendarRange($layout);
     // add at least one empty frequency to show empty form
     if (count($block->getFrequencies()) == 0) {
         $frequency = new Frequency();
         $block->setFrequencies(new ArrayCollection(array($frequency)));
     }
 }
 /**
  * find a block by Route Id And DomId
  *
  * @param  string $lineId Line Id in meth db
  * @param  string $domId  Dom Id in layout
  * @return Block  Entity or null
  */
 public function findByTimetableAndDomId($timetableId, $domId)
 {
     $block = $this->findOneBy(array('timetable' => $timetableId, 'domId' => $domId));
     // no block found so create first a non persistent block
     if (empty($block)) {
         $block = new Block();
         $block->setDomId($domId);
         $timetable = $this->getEntityManager()->getRepository('CanalTPMttBundle:Timetable')->find($timetableId);
         $block->setTimetable($timetable);
     }
     return $block;
 }
Esempio n. 4
0
 public function process(Block $formBlock, $timetable)
 {
     $file = $formBlock->getContent();
     // convert into png if a jpeg was given
     if ($file->getMimeType() == ImgType::MIME_IMAGETYPE_JPEG) {
         $input = imagecreatefromjpeg($file->getRealPath());
         list($width, $height) = getimagesize($file->getRealPath());
         $output = imagecreatetruecolor($width, $height);
         imagecopy($output, $input, 0, 0, 0, 0, $width, $height);
         imagepng($output, $file->getRealPath() . '.png');
         imagedestroy($output);
         imagedestroy($input);
         $pngFile = new File($file->getRealPath() . '.png');
         $media = $this->mediaManager->saveByTimetable($timetable, $pngFile, $this->block->getDomId());
     } else {
         $media = $this->mediaManager->saveByTimetable($timetable, $file, $this->block->getDomId());
     }
     // TODO: saved with domain, we should store without it. Waiting for mediaDataCollector to be updated
     $formBlock->setContent($this->mediaManager->getUrlByMedia($media) . '?' . time());
     $this->saveBlock($formBlock, $timetable);
 }
Esempio n. 5
0
 private function createBlock(ObjectManager $em, $timetable, $typeId = BlockRepository::TEXT_TYPE)
 {
     $block = new Block();
     $block->setTimetable($timetable);
     $block->setTypeId($typeId);
     $block->setDomId('timegrid_block_1');
     $block->setContent('test');
     $block->setTitle('title');
     $em->persist($block);
     return $block;
 }
Esempio n. 6
0
 public function copy(Block $origBlock, Block $destBlock, $destTimetable)
 {
     $origImgMediaPath = $this->findMediaPathByTimeTable($origBlock->getTimetable(), $origBlock->getDomId());
     if (!empty($origImgMediaPath)) {
         copy($origImgMediaPath, $origImgMediaPath . '.bak');
         $destMedia = $this->saveByTimetable($destTimetable, new File($origImgMediaPath), $origBlock->getDomId());
         $destBlock->setContent($this->mediaDataCollector->getUrlByMedia($destMedia));
         // no rename because of the NFS bug
         copy($origImgMediaPath . '.bak', $origImgMediaPath);
         unlink($origImgMediaPath . '.bak');
     }
 }
 private function duplicateCalendarsInterpretion($calendar, array &$calendarsSorted, Block $block)
 {
     if (in_array($calendar->id, $this->calendars)) {
         $calendar = clone $calendar;
         $calendar->id .= '-' . count($this->calendars);
         $calendarsSorted[$calendar->id] = $calendar;
         $block->setContent($calendar->id);
     }
     $this->calendars[] = $calendar->id;
     return $calendar;
 }