| 114 | | if (!aMediaTools::isMultiple()) |
| 115 | | { |
| 116 | | throw new Exception("multiple list component, but multiple is off"); |
| 117 | | } |
| 118 | | $selection = aMediaTools::getSelection(); |
| 119 | | if (!is_array($selection)) |
| 120 | | { |
| 121 | | throw new Exception("selection is not an array"); |
| 122 | | } |
| 123 | | // Work around the fact that whereIn doesn't evaluate to AND FALSE |
| 124 | | // when the array is empty (it just does nothing; which is an |
| 125 | | // interesting variation on MySQL giving you an ERROR when the |
| 126 | | // list is empty, sigh) |
| 127 | | if (count($selection)) |
| 128 | | { |
| 129 | | // Work around the unsorted results of whereIn. You can also |
| 130 | | // do that with a FIELD function |
| 131 | | $unsortedItems = Doctrine_Query::create()-> |
| 132 | | from('aMediaItem i')-> |
| 133 | | whereIn('i.id', $selection)-> |
| 134 | | execute(); |
| 135 | | $itemsById = array(); |
| 136 | | foreach ($unsortedItems as $item) |
| 137 | | { |
| 138 | | $itemsById[$item->getId()] = $item; |
| 139 | | } |
| 140 | | $this->items = array(); |
| 141 | | foreach ($selection as $id) |
| 142 | | { |
| 143 | | if (isset($itemsById[$id])) |
| 144 | | { |
| 145 | | $this->items[] = $itemsById[$id]; |
| 146 | | } |
| 147 | | } |
| 148 | | } |
| 149 | | else |
| 150 | | { |
| 151 | | $this->items = array(); |
| 152 | | } |
| | 124 | $this->items = aMediaTools::getSelectedItems(); |
| | 125 | } |
| | 126 | |
| | 127 | public function executeMultiplePreview() |
| | 128 | { |
| | 129 | $this->items = aMediaTools::getSelectedItems(); |