/** * Returns a location (or array of locations) for an item (or array of items) * @param array|Item|int $item An item or item id, or an array of items or item ids * @param boolean $findOnlyOne Whether or not to return only one location if it exists for the item * @return array|Location A location or an array of locations **/ public function findLocationByItem($item, $findOnlyOne = false) { $db = get_db(); if ($item instanceof Item && !$item->exists()) { return array(); } else { if (is_array($item) && !count($item)) { return array(); } } $alias = $this->getTableAlias(); // Create a SELECT statement for the Location table $select = $db->select()->from(array($alias => $db->Location), "{$alias}.*"); // Create a WHERE condition that will pull down all the location info if (is_array($item)) { $itemIds = array(); foreach ($item as $it) { $itemIds[] = (int) ($it instanceof Item ? $it->id : $it); } $select->where("{$alias}.item_id IN (?)", $itemIds); } else { $itemId = (int) ($item instanceof Item ? $item->id : $item); $select->where("{$alias}.item_id = ?", $itemId); } // If only a single location is request, return the first one found. if ($findOnlyOne) { $location = $this->fetchObject($select); return $location; } // Get the locations. $locations = $this->fetchObjects($select); // Return an associative array of locations where the key is the item_id of the location // Note: Since each item can only have one location, this makes sense to associate a single location with a single item_id. // However, if in the future, an item can have multiple locations, then we cannot just associate a single location with a single item_id; // Instead, in the future, we would have to associate an array of locations with a single item_id. $indexedLocations = array(); foreach ($locations as $k => $loc) { $indexedLocations[$loc['item_id']] = $loc; } return $indexedLocations; }
/** * Determine whether an exhibit uses a particular item on any of its pages. * * @param Item $item * @return boolean */ public function hasItem(Item $item) { if (!$item->exists()) { throw new InvalidArgumentException("Item does not exist (is not persisted)."); } if (!$this->exists()) { throw new RuntimeException("Cannot call hasItem() on a new (non-persisted) exhibit."); } return $this->getTable()->exhibitHasItem($this->id, $item->id); }
/** * Returns a view of any duplicate harvested records for an item * * @param Item $item The item. */ protected function _expose_duplicates($item) { if (!$item->exists()) { return; } $items = get_db()->getTable('Item')->findBy(array('oaipmh_harvester_duplicate_items' => $item->id)); if (!count($items)) { return ''; } return get_view()->partial('index/_duplicates.php', array('items' => $items)); }
public function checkOverlap($user = null) { if ($user == null && $this->user == null) { throw new UserNotFound(); } if ($user == null) { $user = $this->user; } $item = new Item(); $item->where(array("start <=" => $this->start, "end >=" => $this->end))->get_by_related($user); if ($item->exists()) { throw new Item_Overlap_With_Other_Item(); } }