edit-modules.php
290 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Edit modules section under the "permissions" tab. |
| 4 | * |
| 5 | * @package Hustle |
| 6 | * @since 4.1.0 |
| 7 | */ |
| 8 | |
| 9 | $modules_data = Hustle_Module_Collection::instance()->get_all_paginated(); |
| 10 | $filter = $modules_data['filter']; |
| 11 | $modules = $modules_data['modules']; |
| 12 | $modules_total = $modules_data['total']; |
| 13 | $entries_per_page = $modules_data['entries_per_page']; |
| 14 | $modules_ids = array(); |
| 15 | |
| 16 | ?> |
| 17 | <div class="sui-box-settings-row"> |
| 18 | |
| 19 | <div class="sui-box-settings-col-1"> |
| 20 | <span class="sui-settings-label"><?php esc_html_e( 'Edit Existing Modules', 'hustle' ); ?></span> |
| 21 | <span class="sui-description"><?php esc_html_e( 'Choose the user roles which can edit the existing modules.', 'hustle' ); ?></span> |
| 22 | </div> |
| 23 | |
| 24 | <div class="sui-box-settings-col-2"> |
| 25 | |
| 26 | <?php |
| 27 | // TABLE: Modules. |
| 28 | $filtered = ( ! empty( $filter['role'] ) && 'any' !== $filter['role'] ) || |
| 29 | ! empty( $filter['q'] ) || |
| 30 | ( 4 > count( $filter['types'] ) && ! empty( $filter['types'] ) ); |
| 31 | |
| 32 | if ( 0 === count( $modules ) && ! $filtered ) { |
| 33 | ?> |
| 34 | |
| 35 | <?php |
| 36 | $this->get_html_for_options( |
| 37 | array( |
| 38 | array( |
| 39 | 'type' => 'inline_notice', |
| 40 | 'icon' => 'info', |
| 41 | 'value' => esc_html__( "You haven't created any module yet.", 'hustle' ), |
| 42 | ), |
| 43 | ) |
| 44 | ); |
| 45 | ?> |
| 46 | |
| 47 | <?php |
| 48 | } else { |
| 49 | |
| 50 | // PAGINATION: Structure. |
| 51 | |
| 52 | $this->render( |
| 53 | 'admin/commons/pagination', |
| 54 | array( |
| 55 | 'total' => $modules_total, |
| 56 | 'entries_per_page' => $entries_per_page, |
| 57 | 'filterclass' => 'sui-pagination-open-filter', |
| 58 | 'filter' => $filter, |
| 59 | 'section' => 'permissions', |
| 60 | ) |
| 61 | ); |
| 62 | |
| 63 | // PAGINATION: Filter. |
| 64 | $values = array( |
| 65 | 'popup' => __( 'Pop-up', 'hustle' ), |
| 66 | 'slidein' => __( 'Slide-in', 'hustle' ), |
| 67 | 'embedded' => __( 'Embed', 'hustle' ), |
| 68 | 'social_sharing' => __( 'Share', 'hustle' ), |
| 69 | ); |
| 70 | ?> |
| 71 | |
| 72 | <form method="get" class="sui-pagination-filter"> |
| 73 | |
| 74 | <input type="hidden" name="page" value="hustle_settings" /> |
| 75 | <input type="hidden" name="section" value="permissions" /> |
| 76 | |
| 77 | <?php // FILTER: Module Type. ?> |
| 78 | <div class="sui-row"> |
| 79 | |
| 80 | <div class="sui-col-12"> |
| 81 | |
| 82 | <div class="sui-form-field"> |
| 83 | |
| 84 | <label class="sui-label"><?php esc_html_e( 'Module type', 'hustle' ); ?></label> |
| 85 | |
| 86 | <?php foreach ( $values as $value => $module ) { ?> |
| 87 | |
| 88 | <label class="sui-checkbox"> |
| 89 | <input type="checkbox" |
| 90 | name="filter[types][]" |
| 91 | value="<?php echo esc_attr( $value ); ?>" |
| 92 | <?php echo empty( $filter['types'] ) || in_array( $value, $filter['types'], true ) ? ' checked="checked"' : ''; ?> |
| 93 | /> |
| 94 | <span aria-hidden="true"></span> |
| 95 | <span><?php echo esc_html( $module ); ?></span> |
| 96 | </label> |
| 97 | |
| 98 | <?php } ?> |
| 99 | |
| 100 | </div> |
| 101 | |
| 102 | </div> |
| 103 | |
| 104 | </div> |
| 105 | |
| 106 | <?php // FILTER: Keyword. ?> |
| 107 | <div class="sui-row"> |
| 108 | |
| 109 | <div class="sui-col-12"> |
| 110 | |
| 111 | <div class="sui-form-field"> |
| 112 | |
| 113 | <label for="hustle-filter-keyword" class="sui-label"><?php esc_html_e( 'Module name has keyword', 'hustle' ); ?></label> |
| 114 | |
| 115 | <div class="sui-control-with-icon"> |
| 116 | |
| 117 | <input type="text" |
| 118 | name="filter[q]" |
| 119 | placeholder="<?php esc_html_e( 'E.g. Discount', 'hustle' ); ?>" |
| 120 | value="<?php echo esc_attr( isset( $filter['q'] ) ? esc_attr( $filter['q'] ) : '' ); ?>" |
| 121 | id="hustle-filter-keyword" |
| 122 | class="sui-form-control" /> |
| 123 | |
| 124 | <span class="sui-icon-magnifying-glass-search" aria-hidden="true"></span> |
| 125 | |
| 126 | </div> |
| 127 | |
| 128 | </div> |
| 129 | |
| 130 | </div> |
| 131 | |
| 132 | </div> |
| 133 | |
| 134 | <?php |
| 135 | // FILTER(S): Role and Sort. |
| 136 | ?> |
| 137 | <div class="sui-row"> |
| 138 | |
| 139 | <?php // FILTER: Role Assigned. ?> |
| 140 | <div class="sui-col-md-6"> |
| 141 | |
| 142 | <div class="sui-form-field"> |
| 143 | |
| 144 | <label class="sui-label"><?php esc_html_e( 'Use role assigned for editing', 'hustle' ); ?></label> |
| 145 | |
| 146 | <select name="filter[role]" id="hustle-select-filter-role"> |
| 147 | <option value="any"><?php esc_html_e( 'Any', 'hustle' ); ?></option> |
| 148 | <?php |
| 149 | foreach ( $roles as $value => $label ) { |
| 150 | if ( Opt_In_Utils::is_admin_role( $value ) ) { |
| 151 | continue; |
| 152 | } |
| 153 | printf( |
| 154 | '<option value="%s" %s>%s</option>', |
| 155 | esc_attr( $value ), |
| 156 | isset( $filter['role'] ) && $filter['role'] === $value ? 'selected="selected"' : '', |
| 157 | esc_html( $label ) |
| 158 | ); |
| 159 | } |
| 160 | ?> |
| 161 | </select> |
| 162 | |
| 163 | </div> |
| 164 | |
| 165 | </div> |
| 166 | |
| 167 | <?php // FILTER: Sort By. ?> |
| 168 | <div class="sui-col-md-6"> |
| 169 | |
| 170 | <div class="sui-form-field"> |
| 171 | |
| 172 | <label class="sui-label"><?php esc_html_e( 'Sort by', 'hustle' ); ?></label> |
| 173 | |
| 174 | <select name="filter[sort]" id="hustle-select-filter-sort"> |
| 175 | <?php |
| 176 | $values = array( |
| 177 | 'module_name' => __( 'Name', 'hustle' ), |
| 178 | 'module_id' => __( 'Id', 'hustle' ), |
| 179 | 'module_type' => __( 'Type', 'hustle' ), |
| 180 | ); |
| 181 | |
| 182 | foreach ( $values as $value => $label ) { |
| 183 | printf( |
| 184 | '<option value="%s" %s>%s</option>', |
| 185 | esc_attr( $value ), |
| 186 | isset( $filter['sort'] ) && $filter['sort'] === $value ? 'selected="selected"' : '', |
| 187 | esc_html( $label ) |
| 188 | ); |
| 189 | } |
| 190 | ?> |
| 191 | </select> |
| 192 | |
| 193 | </div> |
| 194 | |
| 195 | </div> |
| 196 | |
| 197 | </div> |
| 198 | |
| 199 | <?php // FILTER: Footer. ?> |
| 200 | <div class="sui-filter-footer"> |
| 201 | |
| 202 | <div class="sui-actions-right"> |
| 203 | |
| 204 | <input type="submit" |
| 205 | value="<?php esc_attr_e( 'Apply', 'hustle' ); ?>" |
| 206 | class="sui-button" /> |
| 207 | |
| 208 | </div> |
| 209 | |
| 210 | </div> |
| 211 | |
| 212 | </form> |
| 213 | |
| 214 | <?php |
| 215 | if ( 0 === count( $modules ) && $filtered ) { |
| 216 | |
| 217 | $this->get_html_for_options( |
| 218 | array( |
| 219 | array( |
| 220 | 'type' => 'inline_notice', |
| 221 | 'icon' => 'info', |
| 222 | 'value' => esc_html__( "You don't have any module corresponding to these filter parameters.", 'hustle' ), |
| 223 | ), |
| 224 | ) |
| 225 | ); |
| 226 | |
| 227 | } else { |
| 228 | ?> |
| 229 | <table class="sui-table"> |
| 230 | |
| 231 | <thead> |
| 232 | <tr> |
| 233 | <th><?php esc_html_e( 'Module', 'hustle' ); ?></th> |
| 234 | <th><?php esc_html_e( 'User Role', 'hustle' ); ?></th> |
| 235 | </tr> |
| 236 | </thead> |
| 237 | |
| 238 | <tbody> |
| 239 | |
| 240 | <?php |
| 241 | foreach ( $modules as $module ) : |
| 242 | $modules_ids[] = $module->module_id; |
| 243 | ?> |
| 244 | |
| 245 | <tr data-module-id="<?php echo esc_attr( $module->module_id ); ?>"> |
| 246 | <td class="sui-table-item-title"><span class="sui-icon-<?php echo esc_attr( $module->module_type ); ?>"></span> <?php echo esc_html( $module->module_name ); ?></td> |
| 247 | <td><select |
| 248 | form="<?php echo esc_attr( $form_id ); ?>" |
| 249 | class="sui-select-sm sui-select" |
| 250 | name="modules[<?php echo esc_attr( $module->module_id ); ?>][]" |
| 251 | multiple |
| 252 | > |
| 253 | <?php |
| 254 | $current = $module->get_edit_roles(); |
| 255 | foreach ( $roles as $value => $label ) { |
| 256 | $admin = Opt_In_Utils::is_admin_role( $value ); |
| 257 | printf( |
| 258 | '<option value="%s" %s %s>%s</option>', |
| 259 | esc_attr( $value ), |
| 260 | selected( in_array( $value, $current, true ) || $admin, true, false ), |
| 261 | disabled( $admin, true, false ), |
| 262 | esc_html( $label ) |
| 263 | ); |
| 264 | } |
| 265 | ?> |
| 266 | </td></select> |
| 267 | </tr> |
| 268 | |
| 269 | <?php endforeach; ?> |
| 270 | |
| 271 | <?php if ( ! empty( $modules_ids ) ) : ?> |
| 272 | <input |
| 273 | name="modules_ids" |
| 274 | type="hidden" |
| 275 | value="<?php echo esc_attr( join( ',', $modules_ids ) ); ?>" |
| 276 | form="<?php echo esc_attr( $form_id ); ?>" |
| 277 | > |
| 278 | <?php endif; ?> |
| 279 | |
| 280 | </tbody> |
| 281 | |
| 282 | </table> |
| 283 | <?php } ?> |
| 284 | |
| 285 | <?php } ?> |
| 286 | |
| 287 | </div> |
| 288 | |
| 289 | </div> |
| 290 |