Model for Companies. More...

Inheritance diagram for App\Models\Company:

Static Public Member Functions

static getSelectList ()
 
static getIdFromInput ($unescaped_input)
 
static getIdForCurrentUser ($unescaped_input)
 
static isCurrentUserHasAccess ($companyable)
 
static isCurrentUserAuthorized ()
 
static canManageUsersCompanies ()
 
static getIdForUser ($unescaped_input)
 
static scopeCompanyables ($query, $column= 'company_id')
 
static scopeCompanyableChildren (array $companyable_names, $query)
 
static getName ($companyable)
 

Protected Attributes

 $table = 'companies'
 
 $rules = ['name' => 'required|min:2|max:255|unique:companies,name']
 
 $injectUniqueIdentifier = true
 
 $fillable = ['name']
 

Detailed Description

Model for Companies.

Version
v1.8

Definition at line 12 of file Company.php.

Member Function Documentation

static App\Models\Company::canManageUsersCompanies ( )
static

Definition at line 115 of file Company.php.

116  {
117  return (!static::isFullMultipleCompanySupportEnabled() || Auth::user()->isSuperUser() ||
118  Auth::user()->company_id == null);
119  }
static App\Models\Company::getIdForCurrentUser (   $unescaped_input)
static

Definition at line 81 of file Company.php.

82  {
83  if (!static::isFullMultipleCompanySupportEnabled()) {
84  return static::getIdFromInput($unescaped_input);
85  } else {
86  $current_user = Auth::user();
87 
88  if ($current_user->company_id != null) {
89  return $current_user->company_id;
90  } else {
91  return static::getIdFromInput($unescaped_input);
92  }
93  }
94  }
static App\Models\Company::getIdForUser (   $unescaped_input)
static

Definition at line 121 of file Company.php.

122  {
123  if (!static::isFullMultipleCompanySupportEnabled() || Auth::user()->isSuperUser()) {
124  return static::getIdFromInput($unescaped_input);
125  } else {
126  return static::getIdForCurrentUser($unescaped_input);
127  }
128  }
static App\Models\Company::getIdFromInput (   $unescaped_input)
static

Definition at line 70 of file Company.php.

71  {
72  $escaped_input = e($unescaped_input);
73 
74  if ($escaped_input == '0') {
75  return null;
76  } else {
77  return $escaped_input;
78  }
79  }
static App\Models\Company::getName (   $companyable)
static

Definition at line 162 of file Company.php.

163  {
164  $company = $companyable->company;
165 
166  if (is_null($company)) {
167  return '';
168  } else {
169  return e($company->name);
170  }
171  }
static App\Models\Company::getSelectList ( )
static

Definition at line 64 of file Company.php.

65  {
66  $select_company = Lang::get('general.select_company');
67  return ['0' => $select_company] + DB::table('companies')->orderBy('name', 'ASC')->lists('name', 'id');
68  }
static App\Models\Company::isCurrentUserAuthorized ( )
static

Definition at line 110 of file Company.php.

111  {
112  return (!static::isFullMultipleCompanySupportEnabled() || Auth::user()->company_id == null);
113  }
static App\Models\Company::isCurrentUserHasAccess (   $companyable)
static

Definition at line 96 of file Company.php.

97  {
98  if (is_null($companyable)) {
99  return false;
100  } elseif (!static::isFullMultipleCompanySupportEnabled()) {
101  return true;
102  } else {
103  $current_user_company_id = Auth::user()->company_id;
104  $companyable_company_id = $companyable->company_id;
105 
106  return ($current_user_company_id == null || $current_user_company_id == $companyable_company_id);
107  }
108  }
static App\Models\Company::scopeCompanyableChildren ( array  $companyable_names,
  $query 
)
static

Definition at line 139 of file Company.php.

140  {
141  if (count($companyable_names) == 0) {
142  throw new Exception('No Companyable Children to scope');
143  } elseif (!static::isFullMultipleCompanySupportEnabled()) {
144  return $query;
145  } else {
146  $f = function ($q) {
147 
148  static::scopeCompanyablesDirectly($q);
149  };
150 
151  $q = $query->where(function ($q) use ($companyable_names, $f) {
152  $q2 = $q->whereHas($companyable_names[0], $f);
153 
154  for ($i = 1; $i < count($companyable_names); $i++) {
155  $q2 = $q2->orWhereHas($companyable_names[$i], $f);
156  }
157  });
158  return $q;
159  }
160  }
static App\Models\Company::scopeCompanyables (   $query,
  $column = 'company_id' 
)
static

Definition at line 130 of file Company.php.

131  {
132  if (!static::isFullMultipleCompanySupportEnabled()) {
133  return $query;
134  } else {
135  return static::scopeCompanyablesDirectly($query, $column);
136  }
137  }

Member Data Documentation

App\Models\Company::$fillable = ['name']
protected

Definition at line 35 of file Company.php.

App\Models\Company::$injectUniqueIdentifier = true
protected

Definition at line 26 of file Company.php.

App\Models\Company::$rules = ['name' => 'required|min:2|max:255|unique:companies,name']
protected

Definition at line 17 of file Company.php.

App\Models\Company::$table = 'companies'
protected

Definition at line 14 of file Company.php.


The documentation for this class was generated from the following file: