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); }
/** * 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); } }