/** * Method to check whether the user can check out an item. * * @return boolean True if the item can be checked out, false otherwise. * * @since 12.1 * @throws LogicException * @throws RuntimeException */ public function canCheckout() { // Assert the object is loaded. $this->assertIsLoaded(); // Get the session id. $sessionId = $this->app->getSession()->getId(); // Check if the item is checked out at all. if (!empty($this->checked_out_session) && $this->checked_out_session != $sessionId) { // Build the query to check if the item is editable. $query = $this->db->getQuery(true); $query->select('a.content_id'); $query->from('#__content AS a'); $query->join('INNER', '#__session AS s ON s.session_id = a.checked_out_session'); $query->where('a.content_id = ' . (int) $this->content_id); // Get the checked out state. $this->db->setQuery($query); $checkedOut = (int) $this->db->loadResult(); // Check if the checked out session is still valid. if ($checkedOut) { return false; } } return true; }