Add media.

@Route("/{id}/addmedia/{type}", name="admin_product_new_media")
@Method("GET")
@Template("FlowcodeShopBundle:AdminProduct:media_new.html.twig")
177284
public function addMediaProductAction(Product $product, $type = null)
    {
        if ($type == 'type_image_file') {
            return $this->redirectToRoute('admin_product_new_image', array('id' => $product->getId()));
        }
        $entity = new Media();
        $entity->setMediaType($type);
        $form = $this->mediaCreateCreateForm($entity, $product);

        return array(
            'type' => $type,
            'entity' => $entity,
            'product' => $product,
            'form' => $form->createView(),
        );
    }
978222
public function addMedia($material_id) {
		$material = WechatMaterial::findOne($material_id);
		if(!$material) {
			throw new ErrorException('数据查询失败');
		}

		$data = $this->getData('/cgi-bin/media/upload', [
			'access_token' => $this->getAccessToken(),
			'type' => $material->type,
		], ['media' => '@' . $material->localFile]);
		$material->cleanTmp();

		if($this->errcode == 0) {
			$materialMedia = new WechatMaterialMedia;
			$materialMedia->appid = $this->app->appid;
			$materialMedia->material_id = $material->id;
			$materialMedia->media_id = $data['media_id'];
			$materialMedia->expired_at = $data['created_at'] + $this->effectiveTimeOfTemporaryMaterial;
			if($materialMedia->save()) {
				return $materialMedia->id;
			}
		}

		return 0;
	}
1166804
public function putAction($id, Request $request)
    {
        $mediaTitle = $request->get('title', 'Untitled media');
        $mediaFolderUid = $request->get('media_folder', null);
        $media = $this->getMediaRepository()->find($id);
        $currentMediaFoldierUid = $media->getMediaFolder()->getUid();

        if (null === $media) {
            throw new BadRequestHttpException(sprintf('Cannot find media with id `%s`.', $id));
        }

        $media->setTitle($mediaTitle);

        if ((null !== $mediaFolderUid) && ($mediaFolderUid !== $currentMediaFoldierUid)) {
            $mediaFolder = $this->getMediaFolderRepository()->find($mediaFolderUid);
            if (null !== $mediaFolder) {
                $media->setMediaFolder($mediaFolder);
            }
        }

        $this->autoCommitContent($media->getContent());
        $this->getEntityManager()->persist($media);
        $this->getEntityManager()->flush();

        return $this->createJsonResponse(null, 204);
    }
579698
public function addProductAction(Product $product, $quantity, Request $request)
    {
        // Find OrderCollection
        $orderCollection = $this->getCurrentCart();

        $quantity = array_key_exists('quantity', $_POST) ? (int) $_POST['quantity'] : $quantity;

        try
        {
            if ('-' == $request->get('remove'))
            {
                $quantity = -1 * $quantity;
            }

            // Add Product to OrderCollection
            $lineItem = $orderCollection->addProduct($product, $quantity);

            // Persisting cascades to Order and OrderCollection
            $em = $this->getDoctrine()->getEntityManager();
            $em->persist($lineItem);
            $em->flush();

            if ($quantity > 0) {
                $notice = 'Added '.$quantity.' '
                    .$product->getUnitForNumber($quantity).' of '
                    .$product->getName().' to your cart';
            } else {
                $quantity = abs($quantity);
                $notice = 'Removed '.$quantity.' '
                    .$product->getUnitForNumber($quantity).' of '
                    .$product->getName().' from your cart';
            }

            // Set flash message
            $this->get('session')->getFlashBag()->add('notice', $notice);

            // Save the OrderCollection to the session
            $this->getRequest()->getSession()->set('cart_id', $orderCollection->getId());
        }
        catch (\Exception $e)
        {
            // could not add Product to cart
        }

        $last_route = $request->get('referer');

        if (in_array($last_route, array('_welcome')))
        {
            return $this->redirect($this->generateUrl($last_route));
        }

        return $this->redirect($this->generateUrl('Profile_product_show', array(
            'product_slug' => $product->getSlug(),
            'slug'         => $product->getSeller()->getSlug(),
        )));
    }
1218313
public function putAction(Request $request, $productId)
    {
        $locale = $request->get('locale');
        $parameters = $request->request->all();

        $product = $this->fetchProduct($productId);

        $content = $this->getProductContentMapper()->map($product, $parameters, $locale);
        $this->getEntityManager()->flush();

        $view = $this->view($content, Response::HTTP_OK);

        return $this->handleView($view);
    }
599883
public function moveMediaAction(Request $request)
    {
        if (!$request->isXmlHttpRequest()) {
            throw new NotFoundHttpException();
        }

        $folder = $this->findFolderById($request->attributes->get('id'));

        /** @var \Ekyna\Bundle\MediaBundle\Model\MediaInterface $media */
        $media = $this->get('ekyna_media.media.repository')->find($request->attributes->get('mediaId'));
        if (null === $media) {
            throw new NotFoundHttpException('Media not found.');
        }

        if ($folder === $media->getFolder()) {
            $result = array('success' => true);
        } else {
            $media->setFolder($folder);
            $event = $this->get('ekyna_media.media.operator')->update($media);
            if (!$event->hasErrors()) {
                $result = array('success' => true);
            } else {
                $result = array('success' => false);
            }
        }

        $response = new Response(json_encode($result));
        $response->headers->add(array('Content-Type' => 'application/json'));
        return $response;
    }
361003
def add_media(self, mrl):
        
        if isinstance(mrl, basestring):
            mrl = (self.get_instance() or get_default_instance()).media_new(mrl)
        return libvlc_media_list_add_media(self, mrl)
137954
public function newAction(Request $request)
    {
        $stream = $this->get('oktolab_media_stream')->createStream();
        $form = $this->createForm(StreamType::class, $stream);
        $form->add(
            'submit',
            SubmitType::class,
            [
                'label' => 'oktolab_media.new_stream_button',
                'attr' => ['class' => 'btn btn-primary']
            ]
        );

        if ($request->getMethod() == "POST") {
            $form->handleRequest($request);
            if ($form->isValid()) {
                $em = $this->getDoctrine()->getManager();
                $em->persist($stream);
                $em->flush();

                $this->get('session')->getFlashBag()->add(
                    'success',
                    'oktolab_media.success_create_stream'
                );

                return $this->redirect(
                    $this->generateUrl(
                        'oktolab_media_stream_show',
                        ['uniqID' => $stream->getUniqID()]
                    )
                );
            } else {
                $this->get('session')->getFlashBag()->add(
                    'error',
                    'oktolab_media.error_create_stream'
                );
            }
        }

        return ['form'   => $form->createView()];
    }
652577
private function createMedia()
    {
        if($this->option('media') || $this->option('all')) {
            $this->comment('Creating dummy media...');
            $output = (new \MediaSeeder())
                ->setCommand($this)
                ->run($this->getDefaultOption('media'));
            $this->info($output);
        }
        return $this;
    }
816826
public function createAction(Request $request)
    {
        $templateRepository = $this->get('phlexible_media_template.template_manager');

        $type = $request->get('type');
        $key = $request->get('key');

        switch ($type) {
            case 'image':
                $template = new ImageTemplate();
                $template->setCache(false);
                break;
            case 'video':
                $template = new VideoTemplate();
                $template->setCache(true);
                break;
            case 'audio':
                $template = new AudioTemplate();
                $template->setCache(true);
                break;
            default:
                throw new InvalidArgumentException("Unknown template type $type");
        }

        $template->setKey($key);

        $templateRepository->updateTemplate($template);

        return new ResultResponse(true, 'New "'.$type.'" template "'.$key.'" created.');
    }
786714
public function listAction()
    {
        $repository = $this->get('phlexible_media_template.template_manager');

        $allTemplates = $repository->findAll();

        $templates = [];
        foreach ($allTemplates as $template) {
            if (substr($template->getKey(), 0, 4) === '_mm_') {
                continue;
            }

            $templates[] = [
                'key' => $template->getKey(),
                'type' => $template->getType(),
            ];
        }

        return new JsonResponse(['templates' => $templates]);
    }
812722
public function newAction()
    {
        $entity = new ProductOrderItem();
        $form   = $this->createCreateForm($entity);

        return array(
            'entity' => $entity,
            'form'   => $form->createView(),
        );
    }
114644
public function addMaterial($filename, $type = 'image', $description = [])
    {
        if (!in_array($type, ['image', 'voice', 'video', 'thumb'])) {
            throw new InvalidResponseException('Invalid Media Type.', '0');
        }
        $url = "https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=ACCESS_TOKEN&type={$type}";
        $this->registerApi($url, __FUNCTION__, func_get_args());
        return $this->httpPostForJson($url, ['media' => Tools::createCurlFile($filename), 'description' => Tools::arr2json($description)], false);
    }
1097328
public function editMediaAction(Product $product, Media $entity, $type, Request $request)
    {
        if (!$entity) {
            throw $this->createNotFoundException('Unable to find Media entity.');
        }

        $editForm = $this->mediaCreateEditForm($entity, $product, $type);

        return array(
            'entity' => $entity,
            'type' => $type,
            'product' => $product,
            'edit_form' => $editForm->createView(),
        );
    }
1042116
@Nonnull
  public CSSMediaList addMedia (@Nonnull final ECSSMedium... aMediaList)
  {
    ValueEnforcer.notNull (aMediaList, "MediaList");

    m_aMedia.addAll (aMediaList);
    return this;
  }
1197133
def add_media(device_types, media_type, paths)
      media_type = media_type.to_s

      device_types.each do |device_type|
        UI.verbose("Adding #{media_type}s to #{device_type}...")
        device_udid = TestCommandGenerator.device_udid(device_type)

        UI.message("Launch Simulator #{device_type}")
        Helper.backticks("xcrun instruments -w #{device_udid} &> /dev/null")

        paths.each do |path|
          UI.message("Adding '#{path}'")

          # Attempting addmedia since addphoto and addvideo are deprecated
          output = Helper.backticks("xcrun simctl addmedia #{device_udid} #{path.shellescape} &> /dev/null")

          # Run legacy addphoto and addvideo if addmedia isn't found
          # Output will be empty strin gif it was a success
          # Output will contain "usage: simctl" if command not found
          if output.include?('usage: simctl')
            Helper.backticks("xcrun simctl add#{media_type} #{device_udid} #{path.shellescape} &> /dev/null")
          end
        end
      end
    end
1264680
public function postAction(Request $request, $productId)
    {
        $locale = $this->getLocale($request);
        $mediaId = $request->get('mediaId', '');

        try {
            $em = $this->getDoctrine()->getManager();
            /** @var Product $product */
            $product = $this->getProductManager()->findByIdAndLocale($productId, $locale);
            $media = $this->getMediaManager()->getById($mediaId, $locale);

            if (!$product) {
                throw new EntityNotFoundException($this->getProductEntityName(), $productId);
            }

            if (!$media) {
                throw new EntityNotFoundException($this->getMediaEntityName(), $mediaId);
            }

            if ($product->containsMedia($media)) {
                throw new RestException('Relation already exists');
            }

            //FIXME this is just a temporary solution
            // issue https://github.com/massiveart/POOL-ALPIN/issues/1467
            $this->removeDefaultPrices($product);
            $product->addMedia($media);
            $em->flush();

            $view = $this->view($media, 200);
        } catch (EntityNotFoundException $enfe) {
            $view = $this->view($enfe->toArray(), 404);
        } catch (RestException $exc) {
            $view = $this->view($exc->toArray(), 400);
        } catch (\Exception $e) {
            $view = $this->view($e->getMessage(), 400);
        }

        return $this->handleView($view);
    }