| | 10 | $items = aMediaItemTable::retrieveByIds($selection); |
| | 11 | $ids = array(); |
| | 12 | $imageInfo = array(); |
| | 13 | $selection = array(); |
| | 14 | foreach ($items as $item) |
| | 15 | { |
| | 16 | $croppingInfo = array(); |
| | 17 | if ($item->isCrop()) |
| | 18 | { |
| | 19 | $croppingInfo = $item->getCroppingInfo(); |
| | 20 | $item = $item->getCropOriginal(); |
| | 21 | } |
| | 22 | $id = $item->id; |
| | 23 | $selection[] = $id; |
| | 24 | $info = array('width' => $item->width, 'height' => $item->height); |
| | 25 | $info = array_merge($info, $croppingInfo); |
| | 26 | $imageInfo[$item->id] = $info; |
| | 27 | } |
| | 28 | |
| | 29 | $cropping = isset($options['cropping']) && $options['cropping']; |
| | 30 | |
| | 215 | |
| | 216 | // refactored this into this static method from executeMultipleList() because it is now needed |
| | 217 | // for executeUpdateMultiplePreview() for cropping slideshow items |
| | 218 | static public function getSelectedItems() |
| | 219 | { |
| | 220 | $selection = self::getSelection(); |
| | 221 | if (!is_array($selection)) |
| | 222 | { |
| | 223 | throw new Exception("selection is not an array"); |
| | 224 | } |
| | 225 | // Work around the fact that whereIn doesn't evaluate to AND FALSE |
| | 226 | // when the array is empty (it just does nothing; which is an |
| | 227 | // interesting variation on MySQL giving you an ERROR when the |
| | 228 | // list is empty, sigh) |
| | 229 | if (count($selection)) |
| | 230 | { |
| | 231 | // Work around the unsorted results of whereIn. You can also |
| | 232 | // do that with a FIELD function |
| | 233 | $unsortedItems = Doctrine_Query::create()-> |
| | 234 | from('aMediaItem i')-> |
| | 235 | whereIn('i.id', $selection)-> |
| | 236 | execute(); |
| | 237 | $itemsById = array(); |
| | 238 | foreach ($unsortedItems as $item) |
| | 239 | { |
| | 240 | $itemsById[$item->getId()] = $item; |
| | 241 | } |
| | 242 | $items = array(); |
| | 243 | foreach ($selection as $id) |
| | 244 | { |
| | 245 | if (isset($itemsById[$id])) |
| | 246 | { |
| | 247 | $items[] = $itemsById[$id]; |
| | 248 | } |
| | 249 | } |
| | 250 | } |
| | 251 | else |
| | 252 | { |
| | 253 | $items = array(); |
| | 254 | } |
| | 255 | |
| | 256 | return $items; |
| | 257 | } |
| | 258 | |
| | 259 | static public function getAspectRatio() |
| | 260 | { |
| | 261 | if (self::getAttribute('aspect-width') && self::getAttribute('aspect-width')) |
| | 262 | { |
| | 263 | return self::getAttribute('aspect-width') / self::getAttribute('aspect-height'); |
| | 264 | } |
| | 265 | return 0; |
| | 266 | } |
| | 267 | |
| | 268 | static public function getSelectedThumbnailHeight() |
| | 269 | { |
| | 270 | $selectedConstraints = self::getOption('selected_constraints'); |
| | 271 | if (false === $selectedConstraints['height']) |
| | 272 | { |
| | 273 | if ($aspectRatio = self::getAspectRatio()) |
| | 274 | { |
| | 275 | return $selectedConstraints['width'] / $aspectRatio; |
| | 276 | } |
| | 277 | return 0; // Let's not divide by zero. |
| | 278 | } |
| | 279 | return $selectedConstraints['height']; |
| | 280 | } |
| | 281 | |
| | 282 | /** |
| | 283 | * This mirrors the default size math in aCrop.setAspectMask() in aCrop.js |
| | 284 | */ |
| | 285 | static public function setDefaultCropDimensions($mediaItem) |
| | 286 | { |
| | 287 | $imageInfo = self::getAttribute('imageInfo'); |
| | 288 | $aspectRatio = self::getAspectRatio(); |
| | 289 | |
| | 290 | if ($aspectRatio) |
| | 291 | { |
| | 292 | if ($aspectRatio > 1) |
| | 293 | { |
| | 294 | $imageInfo[$mediaItem->id]['cropWidth'] = $mediaItem->getWidth(); |
| | 295 | $imageInfo[$mediaItem->id]['cropHeight'] = floor($mediaItem->getWidth() / $aspectRatio); |
| | 296 | } |
| | 297 | else |
| | 298 | { |
| | 299 | $imageInfo[$mediaItem->id]['cropHeight'] = $mediaItem->getHeight(); |
| | 300 | $imageInfo[$mediaItem->id]['cropWidth'] = floor($mediaItem->getHeight() * $aspectRatio); |
| | 301 | } |
| | 302 | } |
| | 303 | else |
| | 304 | { |
| | 305 | $imageInfo[$mediaItem->id]['cropWidth'] = $mediaItem->getWidth(); |
| | 306 | $imageInfo[$mediaItem->id]['cropHeight'] = $mediaItem->getHeight(); |
| | 307 | } |
| | 308 | |
| | 309 | $imageInfo[$mediaItem->id]['cropLeft'] = 0; |
| | 310 | $imageInfo[$mediaItem->id]['cropTop'] = floor(($mediaItem->getHeight() - $imageInfo[$mediaItem->id]['cropHeight']) / 2); |
| | 311 | |
| | 312 | self::setAttribute('imageInfo', $imageInfo); |
| | 313 | } |