Backup of database 9 Nov 17
[yaffs-website] / web / modules / contrib / permissions_by_term / src / AccessStorageInterface.php
1 <?php
2
3 namespace Drupal\permissions_by_term;
4
5 use \Drupal\Core\Form\FormState;
6
7 /**
8  * Defines an interface for access storage classes.
9  */
10 interface AccessStorageInterface {
11
12   /**
13    * Checks if the submitted users are existing.
14    *
15    * If an user isn't existing, set an error message.
16    *
17    * @param \Drupal\Core\Form\FormState $form_state
18    */
19   public function checkIfUsersExists(FormState $form_state);
20
21   /**
22    * Gets user term permissions by tid.
23    *
24    * @param int $term_id
25    *
26    * @return mixed
27    *   Existing term permissions.
28    */
29   public function getExistingUserTermPermissionsByTid($term_id);
30
31   /**
32    * Gets role term permissions by tid.
33    *
34    * @param int $term_id
35    *
36    * @return mixed
37    *   Existing role term permissions.
38    */
39   public function getExistingRoleTermPermissionsByTid($term_id);
40
41   /**
42    * Gets single user id by user name.
43    *
44    * @param string $sUsername
45    *   An user name.
46    *
47    * @return int
48    *   User id.
49    */
50   public function getUserIdByName($sUsername);
51
52   /**
53    * Gets multiple user ids by user names.
54    *
55    * @param array $aUserNames
56    *   An array with user names.
57    *
58    * @return array
59    *   User ids.
60    */
61   public function getUserIdsByNames($aUserNames);
62
63   /**
64    * Gets the user names from users.
65    *
66    * Users which have granted access for a taxonomy term.
67    *
68    * @param int $term_id
69    *
70    * @return mixed
71    *   Gets user ids, which are allowed to access.
72    */
73   public function getAllowedUserIds($term_id);
74
75   /**
76    * Deletes term permissions by user id.
77    *
78    * @param array $aUserIdsAccessRemove
79    *   An array with user ids, which access will be removed.
80    * @param int $term_id
81    *   The term id to remove.
82    */
83   public function deleteTermPermissionsByUserIds($aUserIdsAccessRemove, $term_id);
84
85   /**
86    * Deletes term permissions by role ids.
87    *
88    * @param array $aRoleIdsAccessRemove
89    *   An array with role ids, that will be removed.
90    * @param int $term_id
91    *   The term id.
92    */
93   public function deleteTermPermissionsByRoleIds($aRoleIdsAccessRemove, $term_id);
94
95   /**
96    * Adds term permissions by user ids.
97    *
98    * @param array $aUserIdsGrantedAccess
99    *   The user ids which will get granted access.
100    * @param int $term_id
101    *
102    * @throws \Exception
103    */
104   public function addTermPermissionsByUserIds($aUserIdsGrantedAccess, $term_id);
105
106   /**
107    * Adds term permissions by role ids.
108    *
109    * @param array $aRoleIdsGrantedAccess
110    *   The role ids which will gain access.
111    * @param int $term_id
112    *
113    * @throws \Exception
114    */
115   public function addTermPermissionsByRoleIds($aRoleIdsGrantedAccess, $term_id);
116
117   /**
118    * Gets the term id by term name.
119    *
120    * @param string $sTermName
121    *   The term name.
122    *
123    * @return int
124    *   The term id.
125    */
126   public function getTermIdByName($sTermName);
127
128   /**
129    * Gets the taxonomy name by id.
130    *
131    * @param int $term_id
132    *   The taxonomy term id.
133    *
134    * @return string
135    *   Gets a term name by an id.
136    */
137   public function getTermNameById($term_id);
138
139   /**
140    * Saves term permissions by users.
141    *
142    * Opposite to save term permission by roles.
143    *
144    * @param \Drupal\Core\Form\FormState $form_state
145    * @param int $term_id
146    *
147    * @return array
148    *   Data for database queries.
149    */
150   public function saveTermPermissions(FormState $form_state, $term_id);
151
152   /**
153    * Prepares the data which has to be applied to the database.
154    *
155    * @param array $aExistingUserPermissions
156    *   The permissions for existing user.
157    * @param array $aSubmittedUserIdsGrantedAccess
158    *   The user ids which get access.
159    * @param array $aExistingRoleIdsGrantedAccess
160    *   The existing role ids.
161    * @param array $aSubmittedRolesGrantedAccess
162    *   The user roles which get access.
163    *
164    * @return array
165    *   User ID and role data.
166    */
167   public function getPreparedDataForDatabaseQueries($aExistingUserPermissions,
168                                                     $aSubmittedUserIdsGrantedAccess,
169                                                     $aExistingRoleIdsGrantedAccess,
170                                                     $aSubmittedRolesGrantedAccess);
171
172   /**
173    * The form value for allowed users as string to be shown to the user.
174    *
175    * @param \Drupal\user\Entity\User[] $aAllowedUsers
176    *   An array with the allowed users.
177    *
178    * @return null|string
179    *   Either null or the user name.
180    */
181   public function getUserFormValue($aAllowedUsers);
182
183 }