ModelManagerInterface.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Model;
  11. use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
  12. use Sonata\AdminBundle\Datagrid\DatagridInterface;
  13. use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
  14. use Sonata\AdminBundle\Exception\ModelManagerException;
  15. /**
  16. * A model manager is a bridge between the model classes and the admin
  17. * functionality.
  18. */
  19. interface ModelManagerInterface
  20. {
  21. /**
  22. * Returns a new FieldDescription.
  23. *
  24. * @param string $class
  25. * @param string $name
  26. * @param array $options
  27. *
  28. * @return FieldDescriptionInterface
  29. */
  30. public function getNewFieldDescriptionInstance($class, $name, array $options = array());
  31. /**
  32. * @param mixed $object
  33. *
  34. * @throws ModelManagerException
  35. */
  36. public function create($object);
  37. /**
  38. * @param mixed $object
  39. *
  40. * @throws ModelManagerException
  41. */
  42. public function update($object);
  43. /**
  44. * @param mixed $object
  45. *
  46. * @throws ModelManagerException
  47. */
  48. public function delete($object);
  49. /**
  50. * @param string $class
  51. * @param array $criteria
  52. *
  53. * @return array all objects matching the criteria
  54. */
  55. public function findBy($class, array $criteria = array());
  56. /**
  57. * @param string $class
  58. * @param array $criteria
  59. *
  60. * @return object an object matching the criteria or null if none match
  61. */
  62. public function findOneBy($class, array $criteria = array());
  63. /**
  64. * @param string $class
  65. * @param mixed $id
  66. *
  67. * @return object the object with id or null if not found
  68. */
  69. public function find($class, $id);
  70. /**
  71. * @param string $class
  72. * @param ProxyQueryInterface $queryProxy
  73. *
  74. * @throws ModelManagerException
  75. */
  76. public function batchDelete($class, ProxyQueryInterface $queryProxy);
  77. /**
  78. * @param array $parentAssociationMapping
  79. * @param string $class
  80. */
  81. public function getParentFieldDescription($parentAssociationMapping, $class);
  82. /**
  83. * @param string $class
  84. * @param string $alias
  85. *
  86. * @return ProxyQueryInterface
  87. */
  88. public function createQuery($class, $alias = 'o');
  89. /**
  90. * Get the identifier for the model type of this class.
  91. *
  92. * @param string $class fully qualified class name
  93. *
  94. * @return string
  95. */
  96. public function getModelIdentifier($class);
  97. /**
  98. * Get the identifiers of this model class.
  99. *
  100. * This returns an array to handle cases like a primary key that is
  101. * composed of multiple columns. If you need a string representation,
  102. * use getNormalizedIdentifier resp. getUrlsafeIdentifier
  103. *
  104. * @param object $model
  105. *
  106. * @return array list of all identifiers of this model
  107. */
  108. public function getIdentifierValues($model);
  109. /**
  110. * Get a list of the field names models of the specified class use to store
  111. * the identifier.
  112. *
  113. * @param string $class fully qualified class name
  114. *
  115. * @return array
  116. */
  117. public function getIdentifierFieldNames($class);
  118. /**
  119. * Get the identifiers for this model class as a string.
  120. *
  121. * @param object $model
  122. *
  123. * @return string a string representation of the identifiers for this
  124. * instance
  125. */
  126. public function getNormalizedIdentifier($model);
  127. /**
  128. * Get the identifiers as a string that is safe to use in a url.
  129. *
  130. * This is similar to getNormalizedIdentifier but guarantees an id that can
  131. * be used in a URL.
  132. *
  133. * @param object $model
  134. *
  135. * @return string string representation of the id that is safe to use in a url
  136. */
  137. public function getUrlsafeIdentifier($model);
  138. /**
  139. * Create a new instance of the model of the specified class.
  140. *
  141. * @param string $class
  142. *
  143. * @return mixed
  144. */
  145. public function getModelInstance($class);
  146. /**
  147. * @param string $class
  148. *
  149. * @return array
  150. */
  151. public function getModelCollectionInstance($class);
  152. /**
  153. * Removes an element from the collection.
  154. *
  155. * @param mixed $collection
  156. * @param mixed $element
  157. */
  158. public function collectionRemoveElement(&$collection, &$element);
  159. /**
  160. * Add an element from the collection.
  161. *
  162. * @param mixed $collection
  163. * @param mixed $element
  164. *
  165. * @return mixed
  166. */
  167. public function collectionAddElement(&$collection, &$element);
  168. /**
  169. * Check if the element exists in the collection.
  170. *
  171. * @param mixed $collection
  172. * @param mixed $element
  173. *
  174. * @return bool
  175. */
  176. public function collectionHasElement(&$collection, &$element);
  177. /**
  178. * Clear the collection.
  179. *
  180. * @param mixed $collection
  181. *
  182. * @return mixed
  183. */
  184. public function collectionClear(&$collection);
  185. /**
  186. * Returns the parameters used in the columns header.
  187. *
  188. * @param FieldDescriptionInterface $fieldDescription
  189. * @param DatagridInterface $datagrid
  190. *
  191. * @return array
  192. */
  193. public function getSortParameters(FieldDescriptionInterface $fieldDescription, DatagridInterface $datagrid);
  194. /**
  195. * @param string $class
  196. *
  197. * @return array
  198. */
  199. public function getDefaultSortValues($class);
  200. /**
  201. * @param string $class
  202. * @param array $array
  203. */
  204. public function modelReverseTransform($class, array $array = array());
  205. /**
  206. * @param string $class
  207. * @param object $instance
  208. */
  209. public function modelTransform($class, $instance);
  210. /**
  211. * @param mixed $query
  212. */
  213. public function executeQuery($query);
  214. /**
  215. * @param DatagridInterface $datagrid
  216. * @param array $fields
  217. * @param null $firstResult
  218. * @param null $maxResult
  219. *
  220. * @return \Exporter\Source\SourceIteratorInterface
  221. */
  222. public function getDataSourceIterator(DatagridInterface $datagrid, array $fields, $firstResult = null, $maxResult = null);
  223. /**
  224. * @param string $class
  225. *
  226. * @return array
  227. */
  228. public function getExportFields($class);
  229. /**
  230. * @param DatagridInterface $datagrid
  231. * @param int $page
  232. *
  233. * @return mixed
  234. */
  235. public function getPaginationParameters(DatagridInterface $datagrid, $page);
  236. /**
  237. * @param string $class
  238. * @param ProxyQueryInterface $query
  239. * @param array $idx
  240. */
  241. public function addIdentifiersToQuery($class, ProxyQueryInterface $query, array $idx);
  242. }