Schlaefer /
Saito
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | /** |
||||
| 6 | * Saito - The Threaded Web Forum |
||||
| 7 | * |
||||
| 8 | * @copyright Copyright (c) the Saito Project Developers |
||||
| 9 | * @link https://github.com/Schlaefer/Saito |
||||
| 10 | * @license http://opensource.org/licenses/MIT |
||||
| 11 | */ |
||||
| 12 | |||||
| 13 | namespace App\Controller\Component; |
||||
| 14 | |||||
| 15 | use App\Controller\AppController; |
||||
| 16 | use Cake\Controller\Component; |
||||
| 17 | use Saito\User\ForumsUserInterface; |
||||
| 18 | |||||
| 19 | class SlidetabsComponent extends Component |
||||
| 20 | { |
||||
| 21 | /** |
||||
| 22 | * S(l)idetabs used by the application |
||||
| 23 | * |
||||
| 24 | * @var array ['title' => '<cell class>'] |
||||
| 25 | */ |
||||
| 26 | private $_available = [ |
||||
| 27 | 'slidetab_recententries' => 'SlidetabRecentposts', |
||||
| 28 | 'slidetab_recentposts' => 'SlidetabUserposts', |
||||
| 29 | 'slidetab_userlist' => 'SlidetabUserlist', |
||||
| 30 | ]; |
||||
| 31 | |||||
| 32 | /** |
||||
| 33 | * Get all available slidetabs |
||||
| 34 | * |
||||
| 35 | * @return array |
||||
| 36 | */ |
||||
| 37 | public function getAvailable() |
||||
| 38 | { |
||||
| 39 | return array_keys($this->_available); |
||||
| 40 | } |
||||
| 41 | |||||
| 42 | /** |
||||
| 43 | * Show slidetabs |
||||
| 44 | * |
||||
| 45 | * Setup slidetab for rendering in view. |
||||
| 46 | * |
||||
| 47 | * @param string|array $slidetabs slidetabs to show |
||||
| 48 | * @return void |
||||
| 49 | */ |
||||
| 50 | public function show($slidetabs = 'all') |
||||
| 51 | { |
||||
| 52 | /** @var AppController */ |
||||
| 53 | $Controller = $this->getController(); |
||||
| 54 | $user = $Controller->CurrentUser; |
||||
| 55 | if (!$user->isLoggedIn()) { |
||||
| 56 | $tabs = []; |
||||
| 57 | } elseif ($slidetabs === 'all') { |
||||
| 58 | $tabs = $this->_getForUser($user); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 59 | } else { |
||||
| 60 | $tabs = $slidetabs; |
||||
| 61 | } |
||||
| 62 | $tabs = array_map( |
||||
| 63 | function ($v) { |
||||
| 64 | return $this->_available[$v]; |
||||
| 65 | }, |
||||
| 66 | $tabs |
||||
|
0 ignored issues
–
show
It seems like
$tabs can also be of type string; however, parameter $arr1 of array_map() does only seem to accept array, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 67 | ); |
||||
| 68 | $Controller->set('slidetabs', $tabs); |
||||
| 69 | } |
||||
| 70 | |||||
| 71 | /** |
||||
| 72 | * Get all slidetabs in correct order for user |
||||
| 73 | * |
||||
| 74 | * @param ForumsUserInterface $user user |
||||
| 75 | * @return array |
||||
| 76 | */ |
||||
| 77 | protected function _getForUser(ForumsUserInterface $user) |
||||
| 78 | { |
||||
| 79 | $slidetabs = $available = $this->getAvailable(); |
||||
| 80 | |||||
| 81 | $order = $user->get('slidetab_order'); |
||||
| 82 | if (!empty($order)) { |
||||
| 83 | $slidetabsUser = unserialize($order); |
||||
| 84 | // disabled missing tabs still set in user-prefs |
||||
| 85 | $slidetabsUser = array_intersect($slidetabsUser, $available); |
||||
| 86 | // add new tabs not set in user-prefs |
||||
| 87 | $slidetabs = array_merge($slidetabsUser, $available); |
||||
| 88 | $slidetabs = array_unique($slidetabs); |
||||
| 89 | } |
||||
| 90 | |||||
| 91 | return $slidetabs; |
||||
| 92 | } |
||||
| 93 | } |
||||
| 94 |