/** * Helper to return image of the current image. * * @param string $type Derivative type of the image. * @return void */ protected function _sendImage($type = null) { $request = $this->getRequest(); $itemId = $request->getParam('id'); $item = get_record_by_id('item', $itemId); if (empty($item)) { throw new Omeka_Controller_Exception_404(); } $index = $request->getParam('image'); // Get the index. if ($index != '000') { $index = preg_replace('`^[0]*`', '', $index); $index--; } else { $index = 0; } $bookreader = new BookReader($item); $part = $request->getParam('part'); $bookreader->setPart($part); if (is_null($type)) { $scale = $request->getParam('scale'); $type = $bookreader->getSizeType($scale); // Set a default, even it's normally useless. $type = $type ?: 'fullsize'; } $imagesFiles = $bookreader->getLeaves(); $file = $imagesFiles[$index]; // No file, so a blank image if (empty($file)) { $filepath = 'images/blank.png'; $image = file_get_contents(physical_path_to($filepath)); $this->getResponse()->clearBody(); $this->getResponse()->setHeader('Content-Type', 'image/jpeg'); $this->getResponse()->setBody($image); } else { $this->_helper->redirector->gotoUrlAndExit($file->getWebPath($type)); } }
/** * Sort all files of an item by name. * * @param Item $item * @param boolean $mixFileTypes * * @return void */ protected function _sortFiles($item, $mixFileTypes = false) { if ($item->fileCount() < 2) { return; } if ($mixFileTypes) { $list = $item->Files; BookReader_Creator::sortFilesByOriginalName($list, false); } else { $bookreader = new BookReader($item); // Get leaves and remove blank ones. $leaves = array_filter($bookreader->getLeaves()); $non_leaves = array_filter($bookreader->getNonLeaves()); // Manage the case where there is no BookReader data. if (empty($leaves) && empty($non_leaves)) { $list = $item->Files; BookReader_Creator::sortFilesByOriginalName($list, false); } else { // Order them separately. BookReader_Creator::sortFilesByOriginalName($leaves, false); BookReader_Creator::sortFilesByOriginalName($non_leaves, false); // Finally, merge them. $list = array_merge($leaves, $non_leaves); } } // To avoid issues with unique index when updating (order should be // unique for each file of an item), all orders are reset to null before // true process. $db = $this->_db; $bind = array($item->id); $sql = "\n UPDATE `{$db->File}` files\n SET files.order = NULL\n WHERE files.item_id = ?\n "; $db->query($sql, $bind); // To avoid multiple updates, a single query is used. foreach ($list as &$file) { $file = $file->id; } // The array is made unique, because a leaf can be repeated. $list = implode(',', array_unique($list)); $sql = "\n UPDATE `{$db->File}` files\n SET files.order = FIND_IN_SET(files.id, '{$list}')\n WHERE files.id in ({$list})\n "; $db->query($sql); }