ModelManagerInterface.php 6.7 KB

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