ModelManagerInterface.php 6.6 KB

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