public function executeSelect(sfRequest $request) { $after = $request->getParameter('after'); // Prevent possible header insertion tricks $after = preg_replace("/\\s+/", " ", $after); $multiple = !!$request->getParameter('multiple'); if ($multiple) { $selection = preg_split("/\\s*,\\s*/", $request->getParameter('aMediaIds')); } else { $selection = array($request->getParameter('aMediaId') + 0); } $items = aMediaItemTable::retrieveByIds($selection); $ids = array(); foreach ($items as $item) { $ids[] = $item->getId(); } $options = array(); $optional = array('type', 'aspect-width', 'aspect-height', 'minimum-width', 'minimum-height', 'width', 'height', 'label'); foreach ($optional as $option) { if ($request->hasParameter($option)) { $options[$option] = $request->getParameter($option); } } aMediaTools::setSelecting($after, $multiple, $ids, $options); return $this->redirect("aMedia/index"); }
/** * Select a media item or items, then redirect to the URL * specified by the $after parameter, at which time the above * information retrieving methods are valid for use. * The $actions parameter should be the current actions class * ($this, if you are writing an executeFoo method). * $after is the URL to redirect to after the selection is completed or cancelled. * For backwards compatibility this URL will receive several GET method parameters, * however you should use the methods above rather than consulting them. The methods * above are not limited by URL length considerations. * $currentIds should contain a list of ids or a list of aMediaItems that are * currently selected (allowing the user to modify the list rather than making * an entirely new selection), or a single item or id, or false for no current selection. * $options is a hash which may contain: * multiple => true: allow multiple media items to be selected * 'type', 'aspect-width', 'aspect-height', 'minimum-width', 'minimum-height', * 'width', 'height': enforce these constraints on type or dimensions * type can currently be image, video or pdf * 'label': set the reminder message that appears at the top of the media browser * to remind the user why they are there and what they are looking for * 'cropping' => true: allow the user to crop each selected item. Cropping * parameters can be retrieved later with getCroppingInfo() * 'croppingInfo' => an array of existing cropping info as returned by * getCroppingInfo after a previous successful selection. Allows the user to * edit a selection with existing cropping choices * @param mixed $actions * @param mixed $after * @param mixed $currentIds * @param mixed $options * @return mixed */ public function select($actions, $after, $currentIds = false, $options = array()) { if ($currentIds === false) { $currentIds = array(); } elseif ($currentIds instanceof aMediaItem) { $currentIds = array($currentIds); } elseif (!is_array($currentIds)) { $currentIds = array($currentIds); } if ($currentIds[0] instanceof aMediaItem) { $currentIds = aArray::getIds($currentIds); } aMediaTools::setSelecting($after, $options['multiple'], $ids, $options); return $actions->redirect("aMedia/index"); }