|
<?php |
|
/** |
|
* File for App\Models\User\Shared |
|
*/ |
|
|
|
namespace App\Models\User; |
|
|
|
/** |
|
* Helper methods for getting information about users |
|
* |
|
* Class Shared |
|
* @package App\Models\User |
|
*/ |
|
class Shared { |
|
/** |
|
* Used to find out if the currently logged in user is an admin |
|
* |
|
* @return bool |
|
*/ |
|
static public function isAdmin() { |
|
if (\Auth::check() && 'a' === \Auth::user()->privileges) { |
|
return true; |
|
} |
|
|
|
return false; |
|
} |
|
|
|
/** |
|
* Used to determine if an account has been associated with wepay yet or not |
|
* |
|
* @param $user |
|
* @return bool |
|
*/ |
|
static public function hasWepay($user) { |
|
if (empty($user->wepay_id) || 0 === $user->wepay_id) { |
|
return false; |
|
} |
|
|
|
return true; |
|
} |
|
|
|
/** |
|
* Get the pages available to the current user |
|
* |
|
* @param string $type |
|
* @return array|string |
|
*/ |
|
static public function getPages($type='array') { |
|
$pages = ('array' === $type) ? [] : ''; |
|
|
|
if (\Auth::check()) { |
|
|
|
// If the user is an admin, show all pages |
|
if (self::isAdmin()) { |
|
foreach (\Page::all() as $page) { |
|
// Do I want to use the pages? |
|
if ('array' === $type) { |
|
$pages[$page->id] = $page->title; |
|
|
|
// Or do I just want the ID for validation? |
|
} else { |
|
$pages .= ',' . $page->id; |
|
} |
|
} |
|
|
|
// As long as the user isn't an admin, show the pages added to their account |
|
} elseif (\Auth::user()->portals) { |
|
foreach (unserialize(\Auth::user()->portals) as $page) { |
|
$page = \Page::find($page); |
|
|
|
// Does the page even exist? |
|
if (NULL !== $page) { |
|
// Do I want to use the pages? |
|
if ('array' === $type) { |
|
$pages[$page->id] = $page->title; |
|
|
|
// Or do I just want the ID for validation? |
|
} else { |
|
$pages .= ',' . $page->id; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
|
|
return $pages; |
|
} |
|
|
|
/** |
|
* Get the favorites of the specified user (or if no user is specified the currently logged in user) |
|
* |
|
* @param null $user_id |
|
* @return array|mixed |
|
*/ |
|
static public function getFavorites($user_id=NULL) { |
|
if (NULL === $user_id && \Auth::check()) { |
|
$favorites = unserialize(\Auth::user()->favorites); |
|
|
|
return (0 != $favorites) ? $favorites : []; |
|
} else { |
|
$user = \User::find($user_id); |
|
if (NULL !== $user) { |
|
$favorites = unserialize($user->favorites); |
|
|
|
return (0 != $favorites) ? $favorites : []; |
|
} |
|
} |
|
|
|
return []; |
|
} |
|
} |