| 1 |
<?php |
| 2 |
namespace FileBird\Controller; |
| 3 |
|
| 4 |
defined( 'ABSPATH' ) || exit; |
| 5 |
|
| 6 |
use FileBird\Model\Folder as FolderModel; |
| 7 |
|
| 8 |
class FolderUser extends Controller { |
| 9 |
protected static $instance = null; |
| 10 |
|
| 11 |
private $is_enabled; |
| 12 |
private $current_user_id; |
| 13 |
|
| 14 |
public function __construct() { |
| 15 |
$this->is_enabled = $this->isEnabled(); |
| 16 |
$this->current_user_id = get_current_user_id(); |
| 17 |
|
| 18 |
if ( $this->is_enabled ) { |
| 19 |
add_filter( 'fbv_data_before_inserting_folder', array( $this, 'filterDataBeforeInsertingFolder' ) ); |
| 20 |
add_filter( 'fbv_in_not_in_uncategorized_where', array( $this, 'filterUncategorizedWhere' ), 10, 2 ); |
| 21 |
add_filter( 'fbv_in_not_in_created_by', array( $this, 'fbv_in_not_in_created_by' ) ); |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
public function fbv_in_not_in_created_by() { |
| 26 |
return $this->current_user_id; |
| 27 |
} |
| 28 |
public function filterDataBeforeInsertingFolder( $data ) { |
| 29 |
$data['created_by'] = $this->current_user_id; |
| 30 |
return $data; |
| 31 |
} |
| 32 |
|
| 33 |
public function filterUncategorizedWhere( $where, $folder_table ) { |
| 34 |
return sprintf( '`folder_id` IN (SELECT `id` FROM %1$s WHERE `created_by` = %2$d)', $folder_table, $this->current_user_id ); |
| 35 |
} |
| 36 |
|
| 37 |
private function isEnabled() { |
| 38 |
return get_option( 'njt_fbv_folder_per_user', '0' ) === '1'; |
| 39 |
} |
| 40 |
|
| 41 |
} |
| 42 |
|