ModelManagerInterface.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <?php
  2. /*
  3. * This file is part of the Sonata 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\Admin\AdminInterface;
  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. function getNewFieldDescriptionInstance($class, $name, array $options = array());
  31. /**
  32. * @param mixed $object
  33. *
  34. * @return void
  35. */
  36. function create($object);
  37. /**
  38. * @param mixed $object
  39. *
  40. * @return void
  41. */
  42. function update($object);
  43. /**
  44. * @param object $object
  45. *
  46. * @return void
  47. */
  48. function delete($object);
  49. /**
  50. * @param string $class
  51. * @param array $criteria
  52. *
  53. * @return array all objects matching the criteria
  54. */
  55. 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. 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. function find($class, $id);
  70. /**
  71. * @param string $class
  72. * @param ProxyQueryInterface $queryProxy
  73. *
  74. * @return void
  75. */
  76. function batchDelete($class, ProxyQueryInterface $queryProxy);
  77. /**
  78. * @param array $parentAssociationMapping
  79. * @param string $class
  80. *
  81. * @return void
  82. */
  83. function getParentFieldDescription($parentAssociationMapping, $class);
  84. /**
  85. * @param string $class
  86. * @param string $alias
  87. *
  88. * @return ProxyQueryInterface
  89. */
  90. function createQuery($class, $alias = 'o');
  91. /**
  92. * Get the identifier for the model type of this class.
  93. *
  94. * @param string $class fully qualified class name
  95. *
  96. * @return string
  97. */
  98. function getModelIdentifier($class);
  99. /**
  100. * Get the identifiers of this model class.
  101. *
  102. * This returns an array to handle cases like a primary key that is
  103. * composed of multiple columns. If you need a string representation,
  104. * use getNormalizedIdentifier resp. getUrlsafeIdentifier
  105. *
  106. * @param object $model
  107. *
  108. * @return array list of all identifiers of this model
  109. */
  110. function getIdentifierValues($model);
  111. /**
  112. * Get a list of the field names models of the specified class use to store
  113. * the identifier.
  114. *
  115. * @param string $class fully qualified class name
  116. *
  117. * @return array
  118. */
  119. function getIdentifierFieldNames($class);
  120. /**
  121. * Get the identifiers for this model class as a string.
  122. *
  123. * @param object $model
  124. *
  125. * @return string a string representation of the identifiers for this
  126. * instance
  127. */
  128. function getNormalizedIdentifier($model);
  129. /**
  130. * Get the identifiers as a string that is save to use in an url.
  131. *
  132. * This is similar to getNormalizedIdentifier but guarantees an id that can
  133. * be used in an URL.
  134. *
  135. * @param object $model
  136. *
  137. * @return string string representation of the id that is save to use in an url
  138. */
  139. function getUrlsafeIdentifier($model);
  140. /**
  141. * Create a new instance of the model of the specified class.
  142. *
  143. * @param string $class
  144. *
  145. * @return mixed
  146. */
  147. function getModelInstance($class);
  148. /**
  149. * @param string $class
  150. *
  151. * @return array
  152. */
  153. function getModelCollectionInstance($class);
  154. /**
  155. * Removes an element from the collection
  156. *
  157. * @param mixed $collection
  158. * @param mixed $element
  159. *
  160. * @return void
  161. */
  162. function collectionRemoveElement(&$collection, &$element);
  163. /**
  164. * Add an element from the collection
  165. *
  166. * @param mixed $collection
  167. * @param mixed $element
  168. *
  169. * @return mixed
  170. */
  171. function collectionAddElement(&$collection, &$element);
  172. /**
  173. * Check if the element exists in the collection
  174. *
  175. * @param mixed $collection
  176. * @param mixed $element
  177. *
  178. * @return boolean
  179. */
  180. function collectionHasElement(&$collection, &$element);
  181. /**
  182. * Clear the collection
  183. *
  184. * @param mixed $collection
  185. *
  186. * @return mixed
  187. */
  188. function collectionClear(&$collection);
  189. /**
  190. * Returns the parameters used in the columns header
  191. *
  192. * @param FieldDescriptionInterface $fieldDescription
  193. * @param DatagridInterface $datagrid
  194. *
  195. * @return array
  196. */
  197. function getSortParameters(FieldDescriptionInterface $fieldDescription, DatagridInterface $datagrid);
  198. /**
  199. * @param string $class
  200. *
  201. * @return array
  202. */
  203. function getDefaultSortValues($class);
  204. /**
  205. * @param string $class
  206. * @param array $array
  207. *
  208. * @return void
  209. */
  210. function modelReverseTransform($class, array $array = array());
  211. /**
  212. * @param string $class
  213. * @param object $instance
  214. *
  215. * @return void
  216. */
  217. function modelTransform($class, $instance);
  218. /**
  219. * @param mixed $query
  220. *
  221. * @return void
  222. */
  223. function executeQuery($query);
  224. /**
  225. * @param DatagridInterface $datagrid
  226. * @param array $fields
  227. * @param null $firstResult
  228. * @param null $maxResult
  229. *
  230. * @return \Exporter\Source\SourceIteratorInterface
  231. */
  232. function getDataSourceIterator(DatagridInterface $datagrid, array $fields, $firstResult = null, $maxResult = null);
  233. /**
  234. * @param string $class
  235. *
  236. * @return array
  237. */
  238. function getExportFields($class);
  239. /**
  240. * @param DatagridInterface $datagrid
  241. * @param int $page
  242. *
  243. * @return mixed
  244. */
  245. function getPaginationParameters(DatagridInterface $datagrid, $page);
  246. /**
  247. * @param string $class
  248. * @param ProxyQueryInterface $query
  249. * @param array $idx
  250. *
  251. * @return void
  252. */
  253. function addIdentifiersToQuery($class, ProxyQueryInterface $query, array $idx);
  254. }