public function executeMultipleList($request) { if (!aMediaTools::isMultiple()) { throw new Exception("multiple list component, but multiple is off"); } $selection = aMediaTools::getSelection(); if (!is_array($selection)) { throw new Exception("selection is not an array"); } // Work around the fact that whereIn doesn't evaluate to AND FALSE // when the array is empty (it just does nothing; which is an // interesting variation on MySQL giving you an ERROR when the // list is empty, sigh) if (count($selection)) { // Work around the unsorted results of whereIn. You can also // do that with a FIELD function $unsortedItems = Doctrine_Query::create()->from('aMediaItem i')->whereIn('i.id', $selection)->execute(); $itemsById = array(); foreach ($unsortedItems as $item) { $itemsById[$item->getId()] = $item; } $this->items = array(); foreach ($selection as $id) { if (isset($itemsById[$id])) { $this->items[] = $itemsById[$id]; } } } else { $this->items = array(); } }
// Compatible with sf_escaping_strategy: true $label = isset($label) ? $sf_data->getRaw('label') : null; $limitSizes = isset($limitSizes) ? $sf_data->getRaw('limitSizes') : null; $pager = isset($pager) ? $sf_data->getRaw('pager') : null; $pagerUrl = isset($pagerUrl) ? $sf_data->getRaw('pagerUrl') : null; $results = isset($results) ? $sf_data->getRaw('results') : null; ?> <?php use_helper('a'); ?> <?php $type = aMediaTools::getAttribute('type'); $selecting = aMediaTools::isSelecting(); $multipleStyle = $type === 'image' || aMediaTools::isMultiple(); ?> <?php $body_class = 'a-media a-media-index'; $body_class .= $selecting ? ' a-media-selecting' : ''; $body_class .= ' ' . $layout['name']; ?> <?php slot('body_class', $body_class); ?> <?php slot('a-page-header'); ?>
<?php use_helper('I18N'); $type = $mediaItem->getType(); $id = $mediaItem->getId(); $serviceUrl = $mediaItem->getServiceUrl(); $slug = $mediaItem->getSlug(); ?> <?php if (aMediaTools::isSelecting()) { ?> <?php if (aMediaTools::isMultiple()) { ?> <?php $linkAttributes = 'href = "#" onClick="' . jq_remote_function(array("update" => "a-media-selection-list", 'complete' => "aUI('a-media-selection-list');", "url" => "aMedia/multipleAdd?id={$id}")) . '; return false;"'; ?> <?php } else { ?> <?php $linkAttributes = 'href = "' . url_for("aMedia/selected?id={$id}") . '"'; ?> <?php } ?> <?php } else {
public function executeSelected(sfRequest $request) { $controller = $this->getController(); $this->forward404Unless(aMediaTools::isSelecting()); if (aMediaTools::isMultiple()) { $selection = aMediaTools::getSelection(); // Ooops best to get this before clearing it huh $after = aMediaTools::getAfter(); // Oops I forgot to call this in the multiple case aMediaTools::clearSelecting(); // I thought about submitting this like a multiple select, // but there's no clean way to implement that feature in // addParam, and it wastes URL space anyway // (remember the 1024-byte limit) // addParamsNoDelete never attempts to eliminate a field just because // its value is empty. This is how we distinguish between cancellation // and selecting zero items return $this->redirect(aUrl::addParamsNoDelete($after, array("aMediaIds" => implode(",", $selection)))); } // Single select $id = $request->getParameter('id'); $item = Doctrine::getTable("aMediaItem")->find($id); $this->forward404Unless($item); $after = aMediaTools::getAfter(); $after = aUrl::addParams($after, array("aMediaId" => $id)); aMediaTools::clearSelecting(); return $this->redirect($after); }
<?php // This linkHref is duplicate code from mediaItem // This was the quickest / easiest way to ensure $linkHref was defined when mediaItemMeta is returned with Ajax ?> <?php if (aMediaTools::isSelecting()) { ?> <?php // When we are selecting downloadables *in general*, we don't want cropping etc., just simple selection ?> <?php // When we are selecting single images *specifically*, we do force the cropping UI. ?> <?php if (aMediaTools::isMultiple() || $mediaItem->getType() === 'image' && aMediaTools::getType() !== '_downloadable') { ?> <?php $linkHref = "#select-media-item"; ?> <?php } else { ?> <?php // Non-image single select. The multiple add action is a bit of a misnomer here ?> <?php // and redirects to aMedia/selected after adding the media item ?> <?php $linkHref = url_for('aMedia/multipleAdd?id=' . $mediaItem->getId());
/** * DOCUMENT ME * @param sfWebRequest $request * @return mixed */ public function executeSelected(sfWebRequest $request) { $this->hasPermissionsForSelect(); $this->forward404Unless(aMediaTools::isSelecting()); $selection = aMediaTools::getSelection(); $imageInfo = aMediaTools::getAttribute('imageInfo'); // Get all the items in preparation for possible cropping if (count($selection)) { $items = Doctrine::getTable('aMediaItem')->createQuery('m')->whereIn('m.id', $selection)->execute(); } else { $items = array(); } $items = aArray::listToHashById($items); $newSelection = array(); foreach ($selection as $id) { $nid = $id; // Try not to make gratuitous crops if (isset($imageInfo[$id])) { $item = $items[$id]; $i = $imageInfo[$id]; if ($item->getCroppable() && isset($i['cropLeft']) && ($i['cropLeft'] > 0 || $i['cropTop'] > 0 || $i['cropWidth'] != $item->width || $i['cropHeight'] != $item->height)) { // We need to make a crop $item = $items[$id]; $crop = $item->findOrCreateCrop($imageInfo[$id]); $crop->save(); $nid = $crop->id; } $newSelection[] = $nid; } } // Ooops best to get this before clearing it huh $after = aMediaTools::getAfter(); // addParamsNoDelete never attempts to eliminate a field just because // its value is empty. This is how we distinguish between cancellation // and selecting zero items if (!aMediaTools::isMultiple()) { // Call this too soon and you lose isMultiple aMediaTools::clearSelecting(); if (count($newSelection)) { $after = aUrl::addParams($after, array("aMediaId" => $newSelection[0])); return $this->redirect($after); } else { // Our image UI lets you trash your single selection. Which makes sense. // So implement a way of passing that back. It's up to the // receiving action to actually respect it of course $after = aUrl::addParams($after, array("aMediaUnset" => 1)); return $this->redirect($after); } } else { aMediaTools::clearSelecting(); $url = aUrl::addParamsNoDelete($after, array("aMediaIds" => implode(",", $newSelection))); return $this->redirect($url); } }