BookOutlineStorageInterface.php 4.17 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
<?php

namespace Drupal\book;

/**
 * Defines a common interface for book outline storage classes.
 */
interface BookOutlineStorageInterface {

  /**
   * Gets books (the highest positioned book links).
   *
   * @return array
   *   An array of book IDs.
   */
  public function getBooks();

18 19 20 21 22 23 24 25
  /**
   * Checks if there are any books.
   *
   * @return bool
   *   TRUE if there are books, FALSE if not.
   */
  public function hasBooks();

26 27 28
  /**
   * Loads books.
   *
29 30 31 32 33 34 35 36
   * Each book entry consists of the following keys:
   *   - bid: The node ID of the main book.
   *   - nid: The node ID of the book entry itself.
   *   - pid: The parent node ID of the book.
   *   - has_children: A boolean to indicate whether the book has children.
   *   - weight: The weight of the book entry to order siblings.
   *   - depth: The depth in the menu hierarchy the entry is placed into.
   *
37 38
   * @param array $nids
   *   An array of node IDs.
39 40
   * @param bool $access
   *   Whether access checking should be taken into account.
41 42 43 44
   *
   * @return array
   *   Array of loaded book items.
   */
45
  public function loadMultiple($nids, $access = TRUE);
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169

  /**
   * Gets child relative depth.
   *
   * @param array $book_link
   *   The book link.
   *
   * @param int $max_depth
   *   The maximum supported depth of the book tree.
   *
   * @return int
   *   The depth of the searched book.
   */
  public function getChildRelativeDepth($book_link, $max_depth);

  /**
   * Deletes a book entry.
   *
   * @param int $nid
   *   Deletes a book entry.
   *
   * @return mixed
   *   Number of deleted book entries.
   */
  public function delete($nid);

  /**
   * Loads book's children using it's parent ID.
   *
   * @param int $pid
   *   The book's parent ID.
   *
   * @return array
   *   Array of loaded book items.
   */
  public function loadBookChildren($pid);

  /**
   * Builds tree data used for the menu tree.
   *
   * @param int $bid
   *   The ID of the book that we are building the tree for.
   * @param array $parameters
   *   An associative array of build parameters. For info about individual
   *   parameters see BookManager::bookTreeBuild().
   * @param int $min_depth
   *   The minimum depth of book links in the resulting tree.
   * @param int $max_depth
   *   The maximum supported depth of the book tree.
   *
   * @return array
   *   Array of loaded book links.
   */
  public function getBookMenuTree($bid, $parameters, $min_depth, $max_depth);

  /**
   * Inserts a book link.
   *
   * @param array $link
   *   The link array to be inserted in the database.
   * @param array $parents
   *   The array of parent ids for the link to be inserted.
   *
   * @return mixed
   *   The last insert ID of the query, if one exists.
   */
  public function insert($link, $parents);


  /**
   * Updates book reference for links that were moved between books.
   *
   * @param int $nid
   *   The nid of the book entry to be updated.
   * @param array $fields
   *   The array of fields to be updated.
   *
   * @return mixed
   *   The number of rows matched by the update query.
   */
  public function update($nid, $fields);

  /**
   * Update the book ID of the book link that it's being moved.
   *
   * @param int $bid
   *   The ID of the book whose children we move.
   * @param array $original
   *   The original parent of the book link.
   * @param array $expressions
   *   Array of expressions to be added to the query.
   * @param int $shift
   *   The difference in depth between the old and the new position of the
   *   element being moved.
   *
   * @return mixed
   *   The number of rows matched by the update query.
   */
  public function updateMovedChildren($bid, $original, $expressions, $shift);

  /**
   * Count the number of original link children.
   *
   * @param array $original
   *   The book link array.
   *
   * @return int
   *   Number of children.
   */
  public function countOriginalLinkChildren($original);

  /**
   * Get book subtree.
   *
   * @param array $link
   *   A fully loaded book link.
   * @param int $max_depth
   *   The maximum supported depth of the book tree.
   *
   * @return array
   *   Array of unordered subtree book items.
   */
  public function getBookSubtree($link, $max_depth);
}