/** * Returns a hash by image id of hashes containing cropping info: * cropLeft, cropTop, cropWidth, cropHeight. There may not be * cropping info for images that were never cropped. In such cases * you should refer to the original dimensions of the image * @return mixed */ public function getCroppingInfo() { $croppingInfo = array(); $imageInfo = aMediaTools::getAttribute('imageInfo', array()); $selection = aMediaTools::getSelection(); foreach ($selection as $item) { if (isset($imageInfo['cropLeft'])) { $info = array('cropLeft' => $imageInfo['cropLeft'], 'cropTop' => $imageInfo['cropTop'], 'cropWidth' => $imageInfo['cropWidth'], 'cropHeight' => $imageInfo['cropHeight']); $croppingInfo[$item->id] = $info; } } return $croppingInfo; }
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); }
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(); } }
<?php echo a_js_button(a_('Crop'), array('icon', 'a-crop', 'lite', 'no-label', 'alt')); ?> </li> <li> <?php echo a_js_button(a_('Delete'), array('icon', 'a-delete', 'lite', 'no-label', 'alt')); ?> </li> </ul> <div class="a-thumbnail-container" style="background-image: url('<?php echo url_for($item->getCropThumbnailUrl()); ?> '); overflow: hidden;"> <img src="<?php echo url_for($item->getCropThumbnailUrl()); ?> " class="a-thumbnail" style="visibility:hidden;" /> </div> </li> <?php a_js_call('apostrophe.setObjectId(?, ?)', $domId, $id); $n++; } ?> <?php a_js_call('apostrophe.mediaEnableSelect(?)', array('setCropUrl' => url_for('aMedia/crop'), 'removeUrl' => url_for('aMedia/multipleRemove'), 'updateMultiplePreviewUrl' => url_for('aMedia/updateMultiplePreview'), 'multipleAddUrl' => url_for('aMedia/multipleAdd'), 'ids' => aMediaTools::getSelection(), 'aspectRatio' => aMediaTools::getAspectRatio(), 'minimumSize' => array(aMediaTools::getAttribute('minimum-width'), aMediaTools::getAttribute('minimum-height')), 'maximumSize' => array(aMediaTools::getAttribute('maximum-width'), aMediaTools::getAttribute('maximum-height')), 'imageInfo' => aMediaTools::getAttribute('imageInfo')));
/** * 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); } }