Completed
Push — master ( 2ce496...5c1ad5 )
by Sherif
06:14
created
src/Modules/V1/Core/Console/Commands/GenerateDoc.php 4 patches
Doc Comments   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      * Generate headers for the given route.
92 92
      * 
93 93
      * @param  array  &$route
94
-     * @param  object $reflectionClass
94
+     * @param  \ReflectionClass $reflectionClass
95 95
      * @param  string $method
96 96
      * @param  array  $skipLoginCheck
97 97
      * @return void
@@ -118,6 +118,7 @@  discard block
 block discarded – undo
118 118
      * 
119 119
      * @param  array  &$route
120 120
      * @param  object $reflectionMethod]
121
+     * @param \ReflectionMethod $reflectionMethod
121 122
      * @return void
122 123
      */
123 124
     protected function processDocBlock(&$route, $reflectionMethod)
@@ -140,7 +141,7 @@  discard block
 block discarded – undo
140 141
      * Generate post body for the given route.
141 142
      * 
142 143
      * @param  array  &$route
143
-     * @param  object $reflectionMethod
144
+     * @param  \ReflectionMethod $reflectionMethod
144 145
      * @param  array  $validationRules
145 146
      * @return void
146 147
      */
Please login to merge, or discard this patch.
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -6,223 +6,223 @@
 block discarded – undo
6 6
 
7 7
 class GenerateDoc extends Command
8 8
 {
9
-    /**
10
-     * The name and signature of the console command.
11
-     *
12
-     * @var string
13
-     */
14
-    protected $signature = 'doc:generate';
15
-
16
-    /**
17
-     * The console command description.
18
-     *
19
-     * @var string
20
-     */
21
-    protected $description = 'Generate api documentation';
22
-
23
-    /**
24
-     * Create a new command instance.
25
-     *
26
-     * @return void
27
-     */
28
-    public function __construct()
29
-    {
30
-        parent::__construct();
31
-    }
32
-
33
-    /**
34
-     * Execute the console command.
35
-     *
36
-     * @return mixed
37
-     */
38
-    public function handle()
39
-    {
40
-        $docData = [];
41
-        $routes  = $this->getRoutes();
42
-        foreach ($routes as $route) 
43
-        {
44
-            if ($route) 
45
-            {
46
-                $actoinArray      = explode('@', $route['action']);
47
-                $controller       = $actoinArray[0];
48
-                $method           = $actoinArray[1];
49
-                $route['name']    = $method !== 'index' ? $method : 'list';
9
+	/**
10
+	 * The name and signature of the console command.
11
+	 *
12
+	 * @var string
13
+	 */
14
+	protected $signature = 'doc:generate';
15
+
16
+	/**
17
+	 * The console command description.
18
+	 *
19
+	 * @var string
20
+	 */
21
+	protected $description = 'Generate api documentation';
22
+
23
+	/**
24
+	 * Create a new command instance.
25
+	 *
26
+	 * @return void
27
+	 */
28
+	public function __construct()
29
+	{
30
+		parent::__construct();
31
+	}
32
+
33
+	/**
34
+	 * Execute the console command.
35
+	 *
36
+	 * @return mixed
37
+	 */
38
+	public function handle()
39
+	{
40
+		$docData = [];
41
+		$routes  = $this->getRoutes();
42
+		foreach ($routes as $route) 
43
+		{
44
+			if ($route) 
45
+			{
46
+				$actoinArray      = explode('@', $route['action']);
47
+				$controller       = $actoinArray[0];
48
+				$method           = $actoinArray[1];
49
+				$route['name']    = $method !== 'index' ? $method : 'list';
50 50
                 
51
-                $reflectionClass  = new \ReflectionClass($controller);
52
-                $reflectionMethod = $reflectionClass->getMethod($method);
53
-                $classProperties  = $reflectionClass->getDefaultProperties();
54
-                $skipLoginCheck   = array_key_exists('skipLoginCheck', $classProperties) ? $classProperties['skipLoginCheck'] : false;
55
-                $validationRules  = array_key_exists('validationRules', $classProperties) ? $classProperties['validationRules'] : false;
56
-
57
-                $this->processDocBlock($route, $reflectionMethod);
58
-                $this->getHeaders($route, $reflectionClass, $method, $skipLoginCheck);
59
-                $this->getPostData($route, $reflectionMethod, $validationRules);
60
-
61
-                preg_match('/api\/v1\/([^#]+)\//iU', $route['uri'], $module);
62
-                preg_match('/api\/v1\/' . $module[1] . '\/([^#]+)\//iU', $route['uri'], $model);
63
-                $docData['modules'][$module[1]][$model[1]][] = $route;
64
-            }
65
-        }
66
-        $docData['errors'] = $this->getErrors();
67
-        \File::put(app_path('Modules/V1/Core/Resources/api.json'), json_encode($docData));
68
-    }
69
-
70
-    /**
71
-     * Get list of all registered routes.
72
-     * 
73
-     * @return collection
74
-     */
75
-    protected function getRoutes()
76
-    {
77
-        return collect(\Route::getRoutes())->map(function ($route) {
78
-            if (strpos($route->uri(), 'api/v') !== false) 
79
-            {
80
-                return [
81
-                    'method' => $route->methods()[0],
82
-                    'uri'    => $route->uri(),
83
-                    'action' => $route->getActionName()
84
-                ];
85
-            }
86
-            return false;
87
-        })->all();
88
-    }
89
-
90
-    /**
91
-     * Generate headers for the given route.
92
-     * 
93
-     * @param  array  &$route
94
-     * @param  object $reflectionClass
95
-     * @param  string $method
96
-     * @param  array  $skipLoginCheck
97
-     * @return void
98
-     */
99
-    protected function getHeaders(&$route, $reflectionClass, $method, $skipLoginCheck)
100
-    {
101
-        $route['headers'] = [
102
-        'Accept'         => 'application/json',
103
-        'Content-Type'   => 'application/json',
104
-        'locale'         => 'The language of the returned data: ar, en or all.',
105
-        'time-zone-diff' => 'Timezone difference between UTC and Local Time',
106
-        ];
107
-
108
-
109
-        if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) 
110
-        {
111
-            $route['headers']['Authrization'] = 'bearer {token}';
112
-        }
113
-    }
114
-
115
-    /**
116
-     * Generate description and params for the given route
117
-     * based on the docblock.
118
-     * 
119
-     * @param  array  &$route
120
-     * @param  object $reflectionMethod]
121
-     * @return void
122
-     */
123
-    protected function processDocBlock(&$route, $reflectionMethod)
124
-    {
125
-        $factory              = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
126
-        $docblock             = $factory->create($reflectionMethod->getDocComment());
127
-        $route['description'] = trim(preg_replace('/\s+/', ' ', $docblock->getSummary()));
128
-        $params               = $docblock->getTagsByName('param');
129
-        foreach ($params as $param) 
130
-        {
131
-            $name = $param->getVariableName();
132
-            if ($name !== 'request') 
133
-            {
134
-                $route['parametars'][$param->getVariableName()] = $param->getDescription()->render();
135
-            }
136
-        }
137
-    }
138
-
139
-    /**
140
-     * Generate post body for the given route.
141
-     * 
142
-     * @param  array  &$route
143
-     * @param  object $reflectionMethod
144
-     * @param  array  $validationRules
145
-     * @return void
146
-     */
147
-    protected function getPostData(&$route, $reflectionMethod, $validationRules)
148
-    {
149
-        if ($route['method'] == 'POST') 
150
-        {
151
-            $body = $this->getMethodBody($reflectionMethod);
152
-
153
-            preg_match('/\$this->validate\(\$request,([^#]+)\);/iU', $body, $match);
154
-            if (count($match)) 
155
-            {
156
-                if ($match[1] == '$this->validationRules')
157
-                {
158
-                    $route['body'] = $validationRules;
159
-                }
160
-                else
161
-                {
162
-                    $route['body'] = eval('return ' . $match[1] . ';');
163
-                }
164
-
165
-                foreach ($route['body'] as &$rule) 
166
-                {
167
-                    if(strpos($rule, 'unique'))
168
-                    {
169
-                        $rule = substr($rule, 0, strpos($rule, 'unique') + 6);
170
-                    }
171
-                    elseif(strpos($rule, 'exists'))
172
-                    {
173
-                        $rule = substr($rule, 0, strpos($rule, 'exists') - 1);
174
-                    }
175
-                }
176
-            }
177
-            else
178
-            {
179
-                $route['body'] = 'conditions';
180
-            }
181
-        }
182
-    }
183
-
184
-    /**
185
-     * Generate application errors.
186
-     * 
187
-     * @return array
188
-     */
189
-    protected function getErrors()
190
-    {
191
-        $errors          = [];
192
-        $reflectionClass = new \ReflectionClass('App\Modules\V1\Core\Utl\ErrorHandler');
193
-        foreach ($reflectionClass->getMethods() as $method) 
194
-        {
195
-            $methodName       = $method->getName();
196
-            $reflectionMethod = $reflectionClass->getMethod($methodName);
197
-            $body             = $this->getMethodBody($reflectionMethod);
198
-
199
-            preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match);
200
-
201
-            if (count($match)) 
202
-            {
203
-                $errors[$match[1]][] = $methodName;
204
-            }
205
-        }
206
-
207
-        return $errors;
208
-    }
209
-
210
-    /**
211
-     * Get the fiven method body code.
212
-     * 
213
-     * @param  object $reflectionMethod
214
-     * @return string
215
-     */
216
-    protected function getMethodBody($reflectionMethod)
217
-    {
218
-        $filename   = $reflectionMethod->getFileName();
219
-        $start_line = $reflectionMethod->getStartLine() - 1;
220
-        $end_line   = $reflectionMethod->getEndLine();
221
-        $length     = $end_line - $start_line;         
222
-        $source     = file($filename);
223
-        $body       = implode("", array_slice($source, $start_line, $length));
224
-        $body       = trim(preg_replace('/\s+/', '', $body));
225
-
226
-        return $body;
227
-    }
51
+				$reflectionClass  = new \ReflectionClass($controller);
52
+				$reflectionMethod = $reflectionClass->getMethod($method);
53
+				$classProperties  = $reflectionClass->getDefaultProperties();
54
+				$skipLoginCheck   = array_key_exists('skipLoginCheck', $classProperties) ? $classProperties['skipLoginCheck'] : false;
55
+				$validationRules  = array_key_exists('validationRules', $classProperties) ? $classProperties['validationRules'] : false;
56
+
57
+				$this->processDocBlock($route, $reflectionMethod);
58
+				$this->getHeaders($route, $reflectionClass, $method, $skipLoginCheck);
59
+				$this->getPostData($route, $reflectionMethod, $validationRules);
60
+
61
+				preg_match('/api\/v1\/([^#]+)\//iU', $route['uri'], $module);
62
+				preg_match('/api\/v1\/' . $module[1] . '\/([^#]+)\//iU', $route['uri'], $model);
63
+				$docData['modules'][$module[1]][$model[1]][] = $route;
64
+			}
65
+		}
66
+		$docData['errors'] = $this->getErrors();
67
+		\File::put(app_path('Modules/V1/Core/Resources/api.json'), json_encode($docData));
68
+	}
69
+
70
+	/**
71
+	 * Get list of all registered routes.
72
+	 * 
73
+	 * @return collection
74
+	 */
75
+	protected function getRoutes()
76
+	{
77
+		return collect(\Route::getRoutes())->map(function ($route) {
78
+			if (strpos($route->uri(), 'api/v') !== false) 
79
+			{
80
+				return [
81
+					'method' => $route->methods()[0],
82
+					'uri'    => $route->uri(),
83
+					'action' => $route->getActionName()
84
+				];
85
+			}
86
+			return false;
87
+		})->all();
88
+	}
89
+
90
+	/**
91
+	 * Generate headers for the given route.
92
+	 * 
93
+	 * @param  array  &$route
94
+	 * @param  object $reflectionClass
95
+	 * @param  string $method
96
+	 * @param  array  $skipLoginCheck
97
+	 * @return void
98
+	 */
99
+	protected function getHeaders(&$route, $reflectionClass, $method, $skipLoginCheck)
100
+	{
101
+		$route['headers'] = [
102
+		'Accept'         => 'application/json',
103
+		'Content-Type'   => 'application/json',
104
+		'locale'         => 'The language of the returned data: ar, en or all.',
105
+		'time-zone-diff' => 'Timezone difference between UTC and Local Time',
106
+		];
107
+
108
+
109
+		if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) 
110
+		{
111
+			$route['headers']['Authrization'] = 'bearer {token}';
112
+		}
113
+	}
114
+
115
+	/**
116
+	 * Generate description and params for the given route
117
+	 * based on the docblock.
118
+	 * 
119
+	 * @param  array  &$route
120
+	 * @param  object $reflectionMethod]
121
+	 * @return void
122
+	 */
123
+	protected function processDocBlock(&$route, $reflectionMethod)
124
+	{
125
+		$factory              = \phpDocumentor\Reflection\DocBlockFactory::createInstance();
126
+		$docblock             = $factory->create($reflectionMethod->getDocComment());
127
+		$route['description'] = trim(preg_replace('/\s+/', ' ', $docblock->getSummary()));
128
+		$params               = $docblock->getTagsByName('param');
129
+		foreach ($params as $param) 
130
+		{
131
+			$name = $param->getVariableName();
132
+			if ($name !== 'request') 
133
+			{
134
+				$route['parametars'][$param->getVariableName()] = $param->getDescription()->render();
135
+			}
136
+		}
137
+	}
138
+
139
+	/**
140
+	 * Generate post body for the given route.
141
+	 * 
142
+	 * @param  array  &$route
143
+	 * @param  object $reflectionMethod
144
+	 * @param  array  $validationRules
145
+	 * @return void
146
+	 */
147
+	protected function getPostData(&$route, $reflectionMethod, $validationRules)
148
+	{
149
+		if ($route['method'] == 'POST') 
150
+		{
151
+			$body = $this->getMethodBody($reflectionMethod);
152
+
153
+			preg_match('/\$this->validate\(\$request,([^#]+)\);/iU', $body, $match);
154
+			if (count($match)) 
155
+			{
156
+				if ($match[1] == '$this->validationRules')
157
+				{
158
+					$route['body'] = $validationRules;
159
+				}
160
+				else
161
+				{
162
+					$route['body'] = eval('return ' . $match[1] . ';');
163
+				}
164
+
165
+				foreach ($route['body'] as &$rule) 
166
+				{
167
+					if(strpos($rule, 'unique'))
168
+					{
169
+						$rule = substr($rule, 0, strpos($rule, 'unique') + 6);
170
+					}
171
+					elseif(strpos($rule, 'exists'))
172
+					{
173
+						$rule = substr($rule, 0, strpos($rule, 'exists') - 1);
174
+					}
175
+				}
176
+			}
177
+			else
178
+			{
179
+				$route['body'] = 'conditions';
180
+			}
181
+		}
182
+	}
183
+
184
+	/**
185
+	 * Generate application errors.
186
+	 * 
187
+	 * @return array
188
+	 */
189
+	protected function getErrors()
190
+	{
191
+		$errors          = [];
192
+		$reflectionClass = new \ReflectionClass('App\Modules\V1\Core\Utl\ErrorHandler');
193
+		foreach ($reflectionClass->getMethods() as $method) 
194
+		{
195
+			$methodName       = $method->getName();
196
+			$reflectionMethod = $reflectionClass->getMethod($methodName);
197
+			$body             = $this->getMethodBody($reflectionMethod);
198
+
199
+			preg_match('/\$error=\[\'status\'=>([^#]+)\,/iU', $body, $match);
200
+
201
+			if (count($match)) 
202
+			{
203
+				$errors[$match[1]][] = $methodName;
204
+			}
205
+		}
206
+
207
+		return $errors;
208
+	}
209
+
210
+	/**
211
+	 * Get the fiven method body code.
212
+	 * 
213
+	 * @param  object $reflectionMethod
214
+	 * @return string
215
+	 */
216
+	protected function getMethodBody($reflectionMethod)
217
+	{
218
+		$filename   = $reflectionMethod->getFileName();
219
+		$start_line = $reflectionMethod->getStartLine() - 1;
220
+		$end_line   = $reflectionMethod->getEndLine();
221
+		$length     = $end_line - $start_line;         
222
+		$source     = file($filename);
223
+		$body       = implode("", array_slice($source, $start_line, $length));
224
+		$body       = trim(preg_replace('/\s+/', '', $body));
225
+
226
+		return $body;
227
+	}
228 228
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
                 $this->getPostData($route, $reflectionMethod, $validationRules);
60 60
 
61 61
                 preg_match('/api\/v1\/([^#]+)\//iU', $route['uri'], $module);
62
-                preg_match('/api\/v1\/' . $module[1] . '\/([^#]+)\//iU', $route['uri'], $model);
62
+                preg_match('/api\/v1\/'.$module[1].'\/([^#]+)\//iU', $route['uri'], $model);
63 63
                 $docData['modules'][$module[1]][$model[1]][] = $route;
64 64
             }
65 65
         }
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
      */
75 75
     protected function getRoutes()
76 76
     {
77
-        return collect(\Route::getRoutes())->map(function ($route) {
77
+        return collect(\Route::getRoutes())->map(function($route) {
78 78
             if (strpos($route->uri(), 'api/v') !== false) 
79 79
             {
80 80
                 return [
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
         ];
107 107
 
108 108
 
109
-        if (! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) 
109
+        if ( ! $skipLoginCheck || ! in_array($method, $skipLoginCheck)) 
110 110
         {
111 111
             $route['headers']['Authrization'] = 'bearer {token}';
112 112
         }
@@ -159,16 +159,16 @@  discard block
 block discarded – undo
159 159
                 }
160 160
                 else
161 161
                 {
162
-                    $route['body'] = eval('return ' . $match[1] . ';');
162
+                    $route['body'] = eval('return '.$match[1].';');
163 163
                 }
164 164
 
165 165
                 foreach ($route['body'] as &$rule) 
166 166
                 {
167
-                    if(strpos($rule, 'unique'))
167
+                    if (strpos($rule, 'unique'))
168 168
                     {
169 169
                         $rule = substr($rule, 0, strpos($rule, 'unique') + 6);
170 170
                     }
171
-                    elseif(strpos($rule, 'exists'))
171
+                    elseif (strpos($rule, 'exists'))
172 172
                     {
173 173
                         $rule = substr($rule, 0, strpos($rule, 'exists') - 1);
174 174
                     }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -156,8 +156,7 @@  discard block
 block discarded – undo
156 156
                 if ($match[1] == '$this->validationRules')
157 157
                 {
158 158
                     $route['body'] = $validationRules;
159
-                }
160
-                else
159
+                } else
161 160
                 {
162 161
                     $route['body'] = eval('return ' . $match[1] . ';');
163 162
                 }
@@ -167,14 +166,12 @@  discard block
 block discarded – undo
167 166
                     if(strpos($rule, 'unique'))
168 167
                     {
169 168
                         $rule = substr($rule, 0, strpos($rule, 'unique') + 6);
170
-                    }
171
-                    elseif(strpos($rule, 'exists'))
169
+                    } elseif(strpos($rule, 'exists'))
172 170
                     {
173 171
                         $rule = substr($rule, 0, strpos($rule, 'exists') - 1);
174 172
                     }
175 173
                 }
176
-            }
177
-            else
174
+            } else
178 175
             {
179 176
                 $route['body'] = 'conditions';
180 177
             }
Please login to merge, or discard this patch.
src/Modules/V1/Core/Http/Controllers/BaseApiController.php 2 patches
Doc Comments   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -45,8 +45,8 @@  discard block
 block discarded – undo
45 45
      * Fetch all records with relations from storage.
46 46
      * 
47 47
      * @param  string  $sortBy The name of the column to sort by.
48
-     * @param  boolean $desc   Sort ascending or descinding (1: desc, 0: asc).
49
-     * @return \Illuminate\Http\Response
48
+     * @param  integer $desc   Sort ascending or descinding (1: desc, 0: asc).
49
+     * @return \Illuminate\Http\JsonResponse|null
50 50
      */
51 51
     public function index($sortBy = 'created_at', $desc = 1) 
52 52
     {
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      * Fetch the single object with relations from storage.
61 61
      * 
62 62
      * @param  integer $id Id of the requested model.
63
-     * @return \Illuminate\Http\Response
63
+     * @return \Illuminate\Http\JsonResponse|null
64 64
      */
65 65
     public function find($id) 
66 66
     {
@@ -77,8 +77,8 @@  discard block
 block discarded – undo
77 77
      * @param  string  $query   The search text.
78 78
      * @param  integer $perPage Number of rows per page default 15.
79 79
      * @param  string  $sortBy  The name of the column to sort by.
80
-     * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
81
-     * @return \Illuminate\Http\Response
80
+     * @param  integer $desc    Sort ascending or descinding (1: desc, 0: asc).
81
+     * @return \Illuminate\Http\JsonResponse|null
82 82
      */
83 83
     public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) 
84 84
     {
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
      * 
95 95
      * @param  \Illuminate\Http\Request  $request
96 96
      * @param  string  $sortBy The name of the column to sort by.
97
-     * @param  boolean $desc   Sort ascending or descinding (1: desc, 0: asc).
98
-     * @return \Illuminate\Http\Response
97
+     * @param  integer $desc   Sort ascending or descinding (1: desc, 0: asc).
98
+     * @return \Illuminate\Http\JsonResponse|null
99 99
      */
100 100
     public function findby(Request $request, $sortBy = 'created_at', $desc = 1) 
101 101
     {
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
      * condition.
111 111
      * 
112 112
      * @param  \Illuminate\Http\Request  $request
113
-     * @return \Illuminate\Http\Response
113
+     * @return \Illuminate\Http\JsonResponse|null
114 114
      */
115 115
     public function first(Request $request) 
116 116
     {
@@ -125,8 +125,8 @@  discard block
 block discarded – undo
125 125
      * 
126 126
      * @param  integer $perPage Number of rows per page default 15.
127 127
      * @param  string  $sortBy  The name of the column to sort by.
128
-     * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
129
-     * @return \Illuminate\Http\Response
128
+     * @param  integer $desc    Sort ascending or descinding (1: desc, 0: asc).
129
+     * @return \Illuminate\Http\JsonResponse|null
130 130
      */
131 131
     public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) 
132 132
     {
@@ -143,8 +143,8 @@  discard block
 block discarded – undo
143 143
      * @param  \Illuminate\Http\Request  $request
144 144
      * @param  integer $perPage Number of rows per page default 15.
145 145
      * @param  string  $sortBy  The name of the column to sort by.
146
-     * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
147
-     * @return \Illuminate\Http\Response
146
+     * @param  integer $desc    Sort ascending or descinding (1: desc, 0: asc).
147
+     * @return \Illuminate\Http\JsonResponse|null
148 148
      */
149 149
     public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
150 150
     {
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
      * Save the given model to storage.
159 159
      * 
160 160
      * @param  \Illuminate\Http\Request  $request
161
-     * @return \Illuminate\Http\Response
161
+     * @return \Illuminate\Http\JsonResponse|null
162 162
      */
163 163
     public function save(Request $request) 
164 164
     {
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      * Delete by the given id from storage.
192 192
      * 
193 193
      * @param  integer $id Id of the deleted model.
194
-     * @return \Illuminate\Http\Response
194
+     * @return \Illuminate\Http\JsonResponse|null
195 195
      */
196 196
     public function delete($id) 
197 197
     {
@@ -207,8 +207,8 @@  discard block
 block discarded – undo
207 207
      * @param  \Illuminate\Http\Request  $request
208 208
      * @param  integer $perPage Number of rows per page default 15.
209 209
      * @param  string  $sortBy  The name of the column to sort by.
210
-     * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
211
-     * @return \Illuminate\Http\Response
210
+     * @param  integer $desc    Sort ascending or descinding (1: desc, 0: asc).
211
+     * @return \Illuminate\Http\JsonResponse
212 212
      */
213 213
     public function deleted(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
214 214
     {
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
      * Restore the deleted model.
220 220
      * 
221 221
      * @param  integer $id Id of the restored model.
222
-     * @return \Illuminate\Http\Response
222
+     * @return \Illuminate\Http\JsonResponse|null
223 223
      */
224 224
     public function restore($id) 
225 225
     {
Please login to merge, or discard this patch.
Indentation   +267 added lines, -267 removed lines patch added patch discarded remove patch
@@ -6,297 +6,297 @@
 block discarded – undo
6 6
 
7 7
 class BaseApiController extends Controller
8 8
 {
9
-    /**
10
-     * The model implementation.
11
-     * 
12
-     * @var string
13
-     */
14
-    protected $model;
9
+	/**
10
+	 * The model implementation.
11
+	 * 
12
+	 * @var string
13
+	 */
14
+	protected $model;
15 15
 
16
-    /**
17
-     * The config implementation.
18
-     * 
19
-     * @var array
20
-     */
21
-    protected $config;
16
+	/**
17
+	 * The config implementation.
18
+	 * 
19
+	 * @var array
20
+	 */
21
+	protected $config;
22 22
 
23
-    /**
24
-     * The relations implementation.
25
-     * 
26
-     * @var array
27
-     */
28
-    protected $relations;
23
+	/**
24
+	 * The relations implementation.
25
+	 * 
26
+	 * @var array
27
+	 */
28
+	protected $relations;
29 29
 
30
-    public function __construct()
31
-    {        
32
-        $this->config              = \CoreConfig::getConfig();
33
-        $this->model               = property_exists($this, 'model') ? $this->model : false;
34
-        $this->validationRules     = property_exists($this, 'validationRules') ? $this->validationRules : false;
35
-        $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : [];
36
-        $this->skipLoginCheck      = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : [];
37
-        $route                     = explode('@',\Route::currentRouteAction())[1];
30
+	public function __construct()
31
+	{        
32
+		$this->config              = \CoreConfig::getConfig();
33
+		$this->model               = property_exists($this, 'model') ? $this->model : false;
34
+		$this->validationRules     = property_exists($this, 'validationRules') ? $this->validationRules : false;
35
+		$this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : [];
36
+		$this->skipLoginCheck      = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : [];
37
+		$route                     = explode('@',\Route::currentRouteAction())[1];
38 38
 
39
-        $this->checkPermission($route);
40
-        $this->setRelations($route);
41
-        $this->setSessions();
42
-    }
39
+		$this->checkPermission($route);
40
+		$this->setRelations($route);
41
+		$this->setSessions();
42
+	}
43 43
 
44
-    /**
45
-     * Fetch all records with relations from storage.
46
-     * 
47
-     * @param  string  $sortBy The name of the column to sort by.
48
-     * @param  boolean $desc   Sort ascending or descinding (1: desc, 0: asc).
49
-     * @return \Illuminate\Http\Response
50
-     */
51
-    public function index($sortBy = 'created_at', $desc = 1) 
52
-    {
53
-        if ($this->model)
54
-        {
55
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->all($this->relations, $sortBy, $desc), 200);
56
-        }
57
-    }
44
+	/**
45
+	 * Fetch all records with relations from storage.
46
+	 * 
47
+	 * @param  string  $sortBy The name of the column to sort by.
48
+	 * @param  boolean $desc   Sort ascending or descinding (1: desc, 0: asc).
49
+	 * @return \Illuminate\Http\Response
50
+	 */
51
+	public function index($sortBy = 'created_at', $desc = 1) 
52
+	{
53
+		if ($this->model)
54
+		{
55
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->all($this->relations, $sortBy, $desc), 200);
56
+		}
57
+	}
58 58
 
59
-    /**
60
-     * Fetch the single object with relations from storage.
61
-     * 
62
-     * @param  integer $id Id of the requested model.
63
-     * @return \Illuminate\Http\Response
64
-     */
65
-    public function find($id) 
66
-    {
67
-        if ($this->model) 
68
-        {
69
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find($id, $this->relations), 200);
70
-        }
71
-    }
59
+	/**
60
+	 * Fetch the single object with relations from storage.
61
+	 * 
62
+	 * @param  integer $id Id of the requested model.
63
+	 * @return \Illuminate\Http\Response
64
+	 */
65
+	public function find($id) 
66
+	{
67
+		if ($this->model) 
68
+		{
69
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find($id, $this->relations), 200);
70
+		}
71
+	}
72 72
 
73
-    /**
74
-     * Paginate all records with relations from storage
75
-     * that matche the given query.
76
-     * 
77
-     * @param  string  $query   The search text.
78
-     * @param  integer $perPage Number of rows per page default 15.
79
-     * @param  string  $sortBy  The name of the column to sort by.
80
-     * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
81
-     * @return \Illuminate\Http\Response
82
-     */
83
-    public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) 
84
-    {
85
-        if ($this->model) 
86
-        {
87
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->search($query, $perPage, $this->relations, $sortBy, $desc), 200);
88
-        }
89
-    }
73
+	/**
74
+	 * Paginate all records with relations from storage
75
+	 * that matche the given query.
76
+	 * 
77
+	 * @param  string  $query   The search text.
78
+	 * @param  integer $perPage Number of rows per page default 15.
79
+	 * @param  string  $sortBy  The name of the column to sort by.
80
+	 * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
81
+	 * @return \Illuminate\Http\Response
82
+	 */
83
+	public function search($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) 
84
+	{
85
+		if ($this->model) 
86
+		{
87
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->search($query, $perPage, $this->relations, $sortBy, $desc), 200);
88
+		}
89
+	}
90 90
 
91
-    /**
92
-     * Fetch records from the storage based on the given
93
-     * condition.
94
-     * 
95
-     * @param  \Illuminate\Http\Request  $request
96
-     * @param  string  $sortBy The name of the column to sort by.
97
-     * @param  boolean $desc   Sort ascending or descinding (1: desc, 0: asc).
98
-     * @return \Illuminate\Http\Response
99
-     */
100
-    public function findby(Request $request, $sortBy = 'created_at', $desc = 1) 
101
-    {
102
-        if ($this->model) 
103
-        {
104
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->findBy($request->all(), $this->relations, $sortBy, $desc), 200);
105
-        }
106
-    }
91
+	/**
92
+	 * Fetch records from the storage based on the given
93
+	 * condition.
94
+	 * 
95
+	 * @param  \Illuminate\Http\Request  $request
96
+	 * @param  string  $sortBy The name of the column to sort by.
97
+	 * @param  boolean $desc   Sort ascending or descinding (1: desc, 0: asc).
98
+	 * @return \Illuminate\Http\Response
99
+	 */
100
+	public function findby(Request $request, $sortBy = 'created_at', $desc = 1) 
101
+	{
102
+		if ($this->model) 
103
+		{
104
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->findBy($request->all(), $this->relations, $sortBy, $desc), 200);
105
+		}
106
+	}
107 107
 
108
-    /**
109
-     * Fetch the first record from the storage based on the given
110
-     * condition.
111
-     * 
112
-     * @param  \Illuminate\Http\Request  $request
113
-     * @return \Illuminate\Http\Response
114
-     */
115
-    public function first(Request $request) 
116
-    {
117
-        if ($this->model) 
118
-        {
119
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->first($request->all(), $this->relations), 200);
120
-        }
121
-    }
108
+	/**
109
+	 * Fetch the first record from the storage based on the given
110
+	 * condition.
111
+	 * 
112
+	 * @param  \Illuminate\Http\Request  $request
113
+	 * @return \Illuminate\Http\Response
114
+	 */
115
+	public function first(Request $request) 
116
+	{
117
+		if ($this->model) 
118
+		{
119
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->first($request->all(), $this->relations), 200);
120
+		}
121
+	}
122 122
 
123
-    /**
124
-     * Paginate all records with relations from storage.
125
-     * 
126
-     * @param  integer $perPage Number of rows per page default 15.
127
-     * @param  string  $sortBy  The name of the column to sort by.
128
-     * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
129
-     * @return \Illuminate\Http\Response
130
-     */
131
-    public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) 
132
-    {
133
-        if ($this->model) 
134
-        {
135
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginate($perPage, $this->relations, $sortBy, $desc), 200);
136
-        }
137
-    }
123
+	/**
124
+	 * Paginate all records with relations from storage.
125
+	 * 
126
+	 * @param  integer $perPage Number of rows per page default 15.
127
+	 * @param  string  $sortBy  The name of the column to sort by.
128
+	 * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
129
+	 * @return \Illuminate\Http\Response
130
+	 */
131
+	public function paginate($perPage = 15, $sortBy = 'created_at', $desc = 1) 
132
+	{
133
+		if ($this->model) 
134
+		{
135
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginate($perPage, $this->relations, $sortBy, $desc), 200);
136
+		}
137
+	}
138 138
 
139
-    /**
140
-     * Fetch all records with relations based on
141
-     * the given condition from storage in pages.
142
-     * 
143
-     * @param  \Illuminate\Http\Request  $request
144
-     * @param  integer $perPage Number of rows per page default 15.
145
-     * @param  string  $sortBy  The name of the column to sort by.
146
-     * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
147
-     * @return \Illuminate\Http\Response
148
-     */
149
-    public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
150
-    {
151
-        if ($this->model) 
152
-        {
153
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginateBy($request->all(), $perPage, $this->relations, $sortBy, $desc), 200);
154
-        }
155
-    }
139
+	/**
140
+	 * Fetch all records with relations based on
141
+	 * the given condition from storage in pages.
142
+	 * 
143
+	 * @param  \Illuminate\Http\Request  $request
144
+	 * @param  integer $perPage Number of rows per page default 15.
145
+	 * @param  string  $sortBy  The name of the column to sort by.
146
+	 * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
147
+	 * @return \Illuminate\Http\Response
148
+	 */
149
+	public function paginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
150
+	{
151
+		if ($this->model) 
152
+		{
153
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginateBy($request->all(), $perPage, $this->relations, $sortBy, $desc), 200);
154
+		}
155
+	}
156 156
 
157
-    /**
158
-     * Save the given model to storage.
159
-     * 
160
-     * @param  \Illuminate\Http\Request  $request
161
-     * @return \Illuminate\Http\Response
162
-     */
163
-    public function save(Request $request) 
164
-    {
165
-        foreach ($this->validationRules as &$rule) 
166
-        {
167
-            if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) 
168
-            {
169
-                $rule .= ',deleted_at,NULL';
170
-            }
157
+	/**
158
+	 * Save the given model to storage.
159
+	 * 
160
+	 * @param  \Illuminate\Http\Request  $request
161
+	 * @return \Illuminate\Http\Response
162
+	 */
163
+	public function save(Request $request) 
164
+	{
165
+		foreach ($this->validationRules as &$rule) 
166
+		{
167
+			if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) 
168
+			{
169
+				$rule .= ',deleted_at,NULL';
170
+			}
171 171
 
172
-            if ($request->has('id')) 
173
-            {
174
-                $rule = str_replace('{id}', $request->get('id'), $rule);
175
-            }
176
-            else
177
-            {
178
-                $rule = str_replace(',{id}', '', $rule);
179
-            }
180
-        }
172
+			if ($request->has('id')) 
173
+			{
174
+				$rule = str_replace('{id}', $request->get('id'), $rule);
175
+			}
176
+			else
177
+			{
178
+				$rule = str_replace(',{id}', '', $rule);
179
+			}
180
+		}
181 181
         
182
-        $this->validate($request, $this->validationRules);
182
+		$this->validate($request, $this->validationRules);
183 183
 
184
-        if ($this->model) 
185
-        {
186
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->save($request->all()), 200);
187
-        }
188
-    }
184
+		if ($this->model) 
185
+		{
186
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->save($request->all()), 200);
187
+		}
188
+	}
189 189
 
190
-    /**
191
-     * Delete by the given id from storage.
192
-     * 
193
-     * @param  integer $id Id of the deleted model.
194
-     * @return \Illuminate\Http\Response
195
-     */
196
-    public function delete($id) 
197
-    {
198
-        if ($this->model) 
199
-        {
200
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->delete($id), 200);
201
-        }
202
-    }
190
+	/**
191
+	 * Delete by the given id from storage.
192
+	 * 
193
+	 * @param  integer $id Id of the deleted model.
194
+	 * @return \Illuminate\Http\Response
195
+	 */
196
+	public function delete($id) 
197
+	{
198
+		if ($this->model) 
199
+		{
200
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->delete($id), 200);
201
+		}
202
+	}
203 203
 
204
-    /**
205
-     * Return the deleted models in pages based on the given conditions.
206
-     *
207
-     * @param  \Illuminate\Http\Request  $request
208
-     * @param  integer $perPage Number of rows per page default 15.
209
-     * @param  string  $sortBy  The name of the column to sort by.
210
-     * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
211
-     * @return \Illuminate\Http\Response
212
-     */
213
-    public function deleted(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
214
-    {
215
-        return \Response::json(call_user_func_array("\Core::{$this->model}", [])->deleted($request->all(), $perPage, $sortBy, $desc), 200);
216
-    }
204
+	/**
205
+	 * Return the deleted models in pages based on the given conditions.
206
+	 *
207
+	 * @param  \Illuminate\Http\Request  $request
208
+	 * @param  integer $perPage Number of rows per page default 15.
209
+	 * @param  string  $sortBy  The name of the column to sort by.
210
+	 * @param  boolean $desc    Sort ascending or descinding (1: desc, 0: asc).
211
+	 * @return \Illuminate\Http\Response
212
+	 */
213
+	public function deleted(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
214
+	{
215
+		return \Response::json(call_user_func_array("\Core::{$this->model}", [])->deleted($request->all(), $perPage, $sortBy, $desc), 200);
216
+	}
217 217
 
218
-    /**
219
-     * Restore the deleted model.
220
-     * 
221
-     * @param  integer $id Id of the restored model.
222
-     * @return \Illuminate\Http\Response
223
-     */
224
-    public function restore($id) 
225
-    {
226
-        if ($this->model) 
227
-        {
228
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->restore($id), 200);
229
-        }
230
-    }
218
+	/**
219
+	 * Restore the deleted model.
220
+	 * 
221
+	 * @param  integer $id Id of the restored model.
222
+	 * @return \Illuminate\Http\Response
223
+	 */
224
+	public function restore($id) 
225
+	{
226
+		if ($this->model) 
227
+		{
228
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->restore($id), 200);
229
+		}
230
+	}
231 231
 
232
-    /**
233
-     * Check if the logged in user can do the given permission.
234
-     * 
235
-     * @param  string $permission
236
-     * @return void
237
-     */
238
-    private function checkPermission($permission)
239
-    {
240
-        $permission = $permission !== 'index' ? $permission : 'list';
241
-        if ( ! in_array($permission, $this->skipLoginCheck)) 
242
-        {
243
-            $user = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id);
244
-            if ($user->blocked)
245
-            {
246
-                \ErrorHandler::userIsBlocked();
247
-            }
232
+	/**
233
+	 * Check if the logged in user can do the given permission.
234
+	 * 
235
+	 * @param  string $permission
236
+	 * @return void
237
+	 */
238
+	private function checkPermission($permission)
239
+	{
240
+		$permission = $permission !== 'index' ? $permission : 'list';
241
+		if ( ! in_array($permission, $this->skipLoginCheck)) 
242
+		{
243
+			$user = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id);
244
+			if ($user->blocked)
245
+			{
246
+				\ErrorHandler::userIsBlocked();
247
+			}
248 248
             
249
-            if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model))
250
-            {
251
-                \ErrorHandler::noPermissions();
252
-            }
253
-        }
254
-    }
249
+			if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model))
250
+			{
251
+				\ErrorHandler::noPermissions();
252
+			}
253
+		}
254
+	}
255 255
 
256
-    /**
257
-     * Set sessions based on the given headers in the request.
258
-     * 
259
-     * @return void
260
-     */
261
-    private function setSessions()
262
-    {
263
-        \Session::put('timeZoneDiff', \Request::header('time-zone-diff') ?: 0);
256
+	/**
257
+	 * Set sessions based on the given headers in the request.
258
+	 * 
259
+	 * @return void
260
+	 */
261
+	private function setSessions()
262
+	{
263
+		\Session::put('timeZoneDiff', \Request::header('time-zone-diff') ?: 0);
264 264
 
265
-        $locale = \Request::header('locale');
266
-        switch ($locale) 
267
-        {
268
-            case 'en':
269
-            \App::setLocale('en');
270
-            \Session::put('locale', 'en');
271
-            break;
265
+		$locale = \Request::header('locale');
266
+		switch ($locale) 
267
+		{
268
+			case 'en':
269
+			\App::setLocale('en');
270
+			\Session::put('locale', 'en');
271
+			break;
272 272
 
273
-            case 'ar':
274
-            \App::setLocale('ar');
275
-            \Session::put('locale', 'ar');
276
-            break;
273
+			case 'ar':
274
+			\App::setLocale('ar');
275
+			\Session::put('locale', 'ar');
276
+			break;
277 277
 
278
-            case 'all':
279
-            \App::setLocale('en');
280
-            \Session::put('locale', 'all');
281
-            break;
278
+			case 'all':
279
+			\App::setLocale('en');
280
+			\Session::put('locale', 'all');
281
+			break;
282 282
 
283
-            default:
284
-            \App::setLocale('en');
285
-            \Session::put('locale', 'en');
286
-            break;
287
-        }
288
-    }
283
+			default:
284
+			\App::setLocale('en');
285
+			\Session::put('locale', 'en');
286
+			break;
287
+		}
288
+	}
289 289
 
290
-    /**
291
-     * Set relation based on the called api.
292
-     * 
293
-     * @param  string $route
294
-     * @return void
295
-     */
296
-    private function setRelations($route)
297
-    {
298
-        $route           = $route !== 'index' ? $route : 'list';
299
-        $relations       = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false;
300
-        $this->relations = $relations && $relations[$route] ? $relations[$route] : [];
301
-    }
290
+	/**
291
+	 * Set relation based on the called api.
292
+	 * 
293
+	 * @param  string $route
294
+	 * @return void
295
+	 */
296
+	private function setRelations($route)
297
+	{
298
+		$route           = $route !== 'index' ? $route : 'list';
299
+		$relations       = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false;
300
+		$this->relations = $relations && $relations[$route] ? $relations[$route] : [];
301
+	}
302 302
 }
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Repositories/UserRepository.php 2 patches
Indentation   +351 added lines, -351 removed lines patch added patch discarded remove patch
@@ -4,362 +4,362 @@
 block discarded – undo
4 4
 
5 5
 class UserRepository extends AbstractRepository
6 6
 {
7
-    /**
8
-     * Return the model full namespace.
9
-     * 
10
-     * @return string
11
-     */
12
-    protected function getModel()
13
-    {
14
-        return 'App\Modules\V1\Acl\AclUser';
15
-    }
16
-
17
-    /**
18
-     * Return the logged in user account.
19
-     *
20
-     * @param  array   $relations
21
-     * @return boolean
22
-     */
23
-    public function account($relations = [])
24
-    {
25
-        $permissions = [];
26
-        $user        = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id, $relations);
27
-        foreach ($user->groups()->get() as $group)
28
-        {
29
-            $group->permissions->each(function ($permission) use (&$permissions){
30
-                $permissions[$permission->model][$permission->id] = $permission->name;
31
-            });
32
-        }
33
-        $user->permissions = $permissions;
34
-
35
-       return $user;
36
-    }
37
-
38
-    /**
39
-     * Check if the logged in user or the given user 
40
-     * has the given permissions on the given model.
41
-     * 
42
-     * @param  string  $nameOfPermission
43
-     * @param  string  $model            
44
-     * @param  boolean $user
45
-     * @return boolean
46
-     */
47
-    public function can($nameOfPermission, $model, $user = false )
48
-    {      
49
-        $user        = $user ?: \JWTAuth::parseToken()->authenticate();
50
-        $permissions = [];
51
-
52
-        if ( ! $user = $this->find($user->id, ['groups.permissions'])) 
53
-        {
54
-            \ErrorHandler::tokenExpired();
55
-        }
56
-
57
-        $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){
58
-            $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); 
59
-        });
7
+	/**
8
+	 * Return the model full namespace.
9
+	 * 
10
+	 * @return string
11
+	 */
12
+	protected function getModel()
13
+	{
14
+		return 'App\Modules\V1\Acl\AclUser';
15
+	}
16
+
17
+	/**
18
+	 * Return the logged in user account.
19
+	 *
20
+	 * @param  array   $relations
21
+	 * @return boolean
22
+	 */
23
+	public function account($relations = [])
24
+	{
25
+		$permissions = [];
26
+		$user        = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id, $relations);
27
+		foreach ($user->groups()->get() as $group)
28
+		{
29
+			$group->permissions->each(function ($permission) use (&$permissions){
30
+				$permissions[$permission->model][$permission->id] = $permission->name;
31
+			});
32
+		}
33
+		$user->permissions = $permissions;
34
+
35
+	   return $user;
36
+	}
37
+
38
+	/**
39
+	 * Check if the logged in user or the given user 
40
+	 * has the given permissions on the given model.
41
+	 * 
42
+	 * @param  string  $nameOfPermission
43
+	 * @param  string  $model            
44
+	 * @param  boolean $user
45
+	 * @return boolean
46
+	 */
47
+	public function can($nameOfPermission, $model, $user = false )
48
+	{      
49
+		$user        = $user ?: \JWTAuth::parseToken()->authenticate();
50
+		$permissions = [];
51
+
52
+		if ( ! $user = $this->find($user->id, ['groups.permissions'])) 
53
+		{
54
+			\ErrorHandler::tokenExpired();
55
+		}
56
+
57
+		$user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){
58
+			$permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); 
59
+		});
60 60
         
61
-        return in_array($nameOfPermission, $permissions);
62
-    }
63
-
64
-    /**
65
-     * Check if the logged in user has the given group.
66
-     * 
67
-     * @param  string  $groupName
68
-     * @return boolean
69
-     */
70
-    public function hasGroup($groupName)
71
-    {
72
-        $groups = $this->find(\JWTAuth::parseToken()->authenticate()->id)->groups;
73
-        return $groups->pluck('name')->search($groupName, true) === false ? false : true;
74
-    }
75
-
76
-    /**
77
-     * Assign the given group ids to the given user.
78
-     * 
79
-     * @param  integer $user_id    
80
-     * @param  array   $group_ids
81
-     * @return object
82
-     */
83
-    public function assignGroups($user_id, $group_ids)
84
-    {
85
-        \DB::transaction(function () use ($user_id, $group_ids) {
86
-            $user = $this->find($user_id);
87
-            $user->groups()->detach();
88
-            $user->groups()->attach($group_ids);
89
-        });
90
-
91
-        return $this->find($user_id);
92
-    }
93
-
94
-    /**
95
-     * Handle a login request to the application.
96
-     * 
97
-     * @param  array   $credentials    
98
-     * @param  boolean $adminLogin
99
-     * @return array
100
-     */
101
-    public function login($credentials, $adminLogin = false)
102
-    {
103
-        if ( ! $user = $this->first(['email' => $credentials['email']])) 
104
-        {
105
-            \ErrorHandler::loginFailed();
106
-        }
107
-        else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) 
108
-        {
109
-            \ErrorHandler::loginFailed();
110
-        }
111
-        else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) 
112
-        {
113
-            \ErrorHandler::loginFailed();
114
-        }
115
-        else if ($user->blocked)
116
-        {
117
-            \ErrorHandler::userIsBlocked();
118
-        }
119
-        else if ($token = \JWTAuth::attempt($credentials))
120
-        {
121
-            return ['token' => $token];
122
-        }
123
-        else
124
-        {
125
-            \ErrorHandler::loginFailed();
126
-        }
127
-    }
128
-
129
-    /**
130
-     * Handle a social login request of the none admin to the application.
131
-     * 
132
-     * @param  array   $credentials
133
-     * @return array
134
-     */
135
-    public function loginSocial($credentials)
136
-    {
137
-        $access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token'];
138
-        $user         = \Socialite::driver($credentials['type'])->userFromToken($access_token);
139
-
140
-        if ( ! $user->email)
141
-        {
142
-            \ErrorHandler::noSocialEmail();
143
-        }
144
-
145
-        if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
146
-        {
147
-            $data = ['email' => $user->email, 'password' => ''];
148
-            return $this->register($data);
149
-        }
150
-        else
151
-        {
152
-            if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
153
-            {
154
-                \ErrorHandler::userAlreadyRegistered();
155
-            }
156
-            return $this->login(['email' => $registeredUser->email, 'password' => ''], false);
157
-        }
158
-    }
61
+		return in_array($nameOfPermission, $permissions);
62
+	}
63
+
64
+	/**
65
+	 * Check if the logged in user has the given group.
66
+	 * 
67
+	 * @param  string  $groupName
68
+	 * @return boolean
69
+	 */
70
+	public function hasGroup($groupName)
71
+	{
72
+		$groups = $this->find(\JWTAuth::parseToken()->authenticate()->id)->groups;
73
+		return $groups->pluck('name')->search($groupName, true) === false ? false : true;
74
+	}
75
+
76
+	/**
77
+	 * Assign the given group ids to the given user.
78
+	 * 
79
+	 * @param  integer $user_id    
80
+	 * @param  array   $group_ids
81
+	 * @return object
82
+	 */
83
+	public function assignGroups($user_id, $group_ids)
84
+	{
85
+		\DB::transaction(function () use ($user_id, $group_ids) {
86
+			$user = $this->find($user_id);
87
+			$user->groups()->detach();
88
+			$user->groups()->attach($group_ids);
89
+		});
90
+
91
+		return $this->find($user_id);
92
+	}
93
+
94
+	/**
95
+	 * Handle a login request to the application.
96
+	 * 
97
+	 * @param  array   $credentials    
98
+	 * @param  boolean $adminLogin
99
+	 * @return array
100
+	 */
101
+	public function login($credentials, $adminLogin = false)
102
+	{
103
+		if ( ! $user = $this->first(['email' => $credentials['email']])) 
104
+		{
105
+			\ErrorHandler::loginFailed();
106
+		}
107
+		else if ($adminLogin && $user->groups->pluck('name')->search('Admin', true) === false) 
108
+		{
109
+			\ErrorHandler::loginFailed();
110
+		}
111
+		else if ( ! $adminLogin && $user->groups->pluck('name')->search('Admin', true) !== false) 
112
+		{
113
+			\ErrorHandler::loginFailed();
114
+		}
115
+		else if ($user->blocked)
116
+		{
117
+			\ErrorHandler::userIsBlocked();
118
+		}
119
+		else if ($token = \JWTAuth::attempt($credentials))
120
+		{
121
+			return ['token' => $token];
122
+		}
123
+		else
124
+		{
125
+			\ErrorHandler::loginFailed();
126
+		}
127
+	}
128
+
129
+	/**
130
+	 * Handle a social login request of the none admin to the application.
131
+	 * 
132
+	 * @param  array   $credentials
133
+	 * @return array
134
+	 */
135
+	public function loginSocial($credentials)
136
+	{
137
+		$access_token = $credentials['auth_code'] ? \Socialite::driver($credentials['type'])->getAccessToken($credentials['auth_code']) : $credentials['access_token'];
138
+		$user         = \Socialite::driver($credentials['type'])->userFromToken($access_token);
139
+
140
+		if ( ! $user->email)
141
+		{
142
+			\ErrorHandler::noSocialEmail();
143
+		}
144
+
145
+		if ( ! $registeredUser = $this->model->where('email', $user->email)->first()) 
146
+		{
147
+			$data = ['email' => $user->email, 'password' => ''];
148
+			return $this->register($data);
149
+		}
150
+		else
151
+		{
152
+			if ( ! \Auth::attempt(['email' => $registeredUser->email, 'password' => '']))
153
+			{
154
+				\ErrorHandler::userAlreadyRegistered();
155
+			}
156
+			return $this->login(['email' => $registeredUser->email, 'password' => ''], false);
157
+		}
158
+	}
159 159
     
160
-    /**
161
-     * Handle a registration request.
162
-     * 
163
-     * @param  array $credentials
164
-     * @return array
165
-     */
166
-    public function register($credentials)
167
-    {
168
-        return ['token' => \JWTAuth::fromUser($this->model->create($credentials))];
169
-    }
170
-
171
-    /**
172
-     * Logout the user.
173
-     * 
174
-     * @return boolean
175
-     */
176
-    public function logout()
177
-    {
178
-        return \JWTAuth::invalidate(\JWTAuth::getToken());
179
-    }
180
-
181
-    /**
182
-     * Block the user.
183
-     *
184
-     * @param  integer $user_id
185
-     * @return object
186
-     */
187
-    public function block($user_id)
188
-    {
189
-        if ( ! $user = $this->find($user_id)) 
190
-        {
191
-            \ErrorHandler::notFound('user');
192
-        }
193
-        if ( ! $this->hasGroup('Admin'))
194
-        {
195
-            \ErrorHandler::noPermissions();
196
-        }
197
-        else if (\JWTAuth::parseToken()->authenticate()->id == $user_id)
198
-        {
199
-            \ErrorHandler::noPermissions();
200
-        }
201
-        else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
202
-        {
203
-            \ErrorHandler::noPermissions();
204
-        }
205
-
206
-        $user->blocked = 1;
207
-        $user->save();
160
+	/**
161
+	 * Handle a registration request.
162
+	 * 
163
+	 * @param  array $credentials
164
+	 * @return array
165
+	 */
166
+	public function register($credentials)
167
+	{
168
+		return ['token' => \JWTAuth::fromUser($this->model->create($credentials))];
169
+	}
170
+
171
+	/**
172
+	 * Logout the user.
173
+	 * 
174
+	 * @return boolean
175
+	 */
176
+	public function logout()
177
+	{
178
+		return \JWTAuth::invalidate(\JWTAuth::getToken());
179
+	}
180
+
181
+	/**
182
+	 * Block the user.
183
+	 *
184
+	 * @param  integer $user_id
185
+	 * @return object
186
+	 */
187
+	public function block($user_id)
188
+	{
189
+		if ( ! $user = $this->find($user_id)) 
190
+		{
191
+			\ErrorHandler::notFound('user');
192
+		}
193
+		if ( ! $this->hasGroup('Admin'))
194
+		{
195
+			\ErrorHandler::noPermissions();
196
+		}
197
+		else if (\JWTAuth::parseToken()->authenticate()->id == $user_id)
198
+		{
199
+			\ErrorHandler::noPermissions();
200
+		}
201
+		else if ($user->groups->pluck('name')->search('Admin', true) !== false) 
202
+		{
203
+			\ErrorHandler::noPermissions();
204
+		}
205
+
206
+		$user->blocked = 1;
207
+		$user->save();
208 208
         
209
-        return $user;
210
-    }
211
-
212
-    /**
213
-     * Unblock the user.
214
-     *
215
-     * @param  integer $user_id
216
-     * @return object
217
-     */
218
-    public function unblock($user_id)
219
-    {
220
-        if ( ! $this->hasGroup('Admin'))
221
-        {
222
-            \ErrorHandler::noPermissions();
223
-        }
224
-
225
-        $user          = $this->find($user_id);
226
-        $user->blocked = 0;
227
-        $user->save();
228
-
229
-        return $user;
230
-    }
231
-
232
-    /**
233
-     * Send a reset link to the given user.
234
-     *
235
-     * @param  string  $email
236
-     * @return void
237
-     */
238
-    public function sendReset($email)
239
-    {
240
-        if ( ! $user = $this->model->where('email', $email)->first())
241
-        {
242
-            \ErrorHandler::notFound('email');
243
-        }
244
-
245
-        $url   = $this->config['resetLink'];
246
-        $token = \Password::getRepository()->create($user);
209
+		return $user;
210
+	}
211
+
212
+	/**
213
+	 * Unblock the user.
214
+	 *
215
+	 * @param  integer $user_id
216
+	 * @return object
217
+	 */
218
+	public function unblock($user_id)
219
+	{
220
+		if ( ! $this->hasGroup('Admin'))
221
+		{
222
+			\ErrorHandler::noPermissions();
223
+		}
224
+
225
+		$user          = $this->find($user_id);
226
+		$user->blocked = 0;
227
+		$user->save();
228
+
229
+		return $user;
230
+	}
231
+
232
+	/**
233
+	 * Send a reset link to the given user.
234
+	 *
235
+	 * @param  string  $email
236
+	 * @return void
237
+	 */
238
+	public function sendReset($email)
239
+	{
240
+		if ( ! $user = $this->model->where('email', $email)->first())
241
+		{
242
+			\ErrorHandler::notFound('email');
243
+		}
244
+
245
+		$url   = $this->config['resetLink'];
246
+		$token = \Password::getRepository()->create($user);
247 247
         
248
-        \Mail::send('Acl:resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) {
249
-            $m->to($user->email, $user->name)->subject('Your Password Reset Link');
250
-        });
251
-    }
252
-
253
-    /**
254
-     * Reset the given user's password.
255
-     *
256
-     * @param  array  $credentials
257
-     * @return array
258
-     */
259
-    public function resetPassword($credentials)
260
-    {
261
-        $token    = false;
262
-        $response = \Password::reset($credentials, function ($user, $password) use (&$token) {
263
-            $user->password = bcrypt($password);
264
-            $user->save();
265
-
266
-            $token = \JWTAuth::fromUser($user);
267
-        });
268
-
269
-        switch ($response) {
270
-            case \Password::PASSWORD_RESET:
271
-                return ['token' => $token];
248
+		\Mail::send('Acl:resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) {
249
+			$m->to($user->email, $user->name)->subject('Your Password Reset Link');
250
+		});
251
+	}
252
+
253
+	/**
254
+	 * Reset the given user's password.
255
+	 *
256
+	 * @param  array  $credentials
257
+	 * @return array
258
+	 */
259
+	public function resetPassword($credentials)
260
+	{
261
+		$token    = false;
262
+		$response = \Password::reset($credentials, function ($user, $password) use (&$token) {
263
+			$user->password = bcrypt($password);
264
+			$user->save();
265
+
266
+			$token = \JWTAuth::fromUser($user);
267
+		});
268
+
269
+		switch ($response) {
270
+			case \Password::PASSWORD_RESET:
271
+				return ['token' => $token];
272 272
                 
273
-            case \Password::INVALID_TOKEN:
274
-                \ErrorHandler::invalidResetToken('token');
275
-
276
-            case \Password::INVALID_PASSWORD:
277
-                \ErrorHandler::invalidResetPassword('email');
278
-
279
-            case \Password::INVALID_USER:
280
-                \ErrorHandler::notFound('user');
281
-
282
-            default:
283
-                \ErrorHandler::generalError();
284
-        }
285
-    }
286
-
287
-    /**
288
-     * Change the logged in user password.
289
-     *
290
-     * @param  array  $credentials
291
-     * @return void
292
-     */
293
-    public function changePassword($credentials)
294
-    {
295
-        $user = $this->find(\JWTAuth::parseToken()->authenticate()->id);
296
-        if ( ! \Hash::check($credentials['old_password'], $user->password)) 
297
-        {
298
-            \ErrorHandler::invalidOldPassword();
299
-        }
300
-
301
-        $user->password = $credentials['password'];
302
-        $user->save();
303
-    }
304
-
305
-    /**
306
-     * Refresh the expired login token.
307
-     *
308
-     * @return array
309
-     */
310
-    public function refreshtoken()
311
-    {
312
-        $token = \JWTAuth::parseToken()->refresh();
313
-
314
-        return ['token' => $token];
315
-    }
316
-
317
-    /**
318
-     * Paginate all users in the given group based on the given conditions.
319
-     * 
320
-     * @param  string  $groupName
321
-     * @param  array   $relations
322
-     * @param  integer $perPage
323
-     * @param  string  $sortBy
324
-     * @param  boolean $desc
325
-     * @return \Illuminate\Http\Response
326
-     */
327
-    public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
328
-    {   
329
-        unset($conditions['page']);
330
-        $conditions = $this->constructConditions($conditions, $this->model);
331
-        $sort       = $desc ? 'desc' : 'asc';
332
-        $model      = call_user_func_array("{$this->getModel()}::with", array($relations));
333
-
334
-        $model->whereHas('groups', function($q) use ($groupName){
335
-            $q->where('name', $groupName);
336
-        });
273
+			case \Password::INVALID_TOKEN:
274
+				\ErrorHandler::invalidResetToken('token');
275
+
276
+			case \Password::INVALID_PASSWORD:
277
+				\ErrorHandler::invalidResetPassword('email');
278
+
279
+			case \Password::INVALID_USER:
280
+				\ErrorHandler::notFound('user');
281
+
282
+			default:
283
+				\ErrorHandler::generalError();
284
+		}
285
+	}
286
+
287
+	/**
288
+	 * Change the logged in user password.
289
+	 *
290
+	 * @param  array  $credentials
291
+	 * @return void
292
+	 */
293
+	public function changePassword($credentials)
294
+	{
295
+		$user = $this->find(\JWTAuth::parseToken()->authenticate()->id);
296
+		if ( ! \Hash::check($credentials['old_password'], $user->password)) 
297
+		{
298
+			\ErrorHandler::invalidOldPassword();
299
+		}
300
+
301
+		$user->password = $credentials['password'];
302
+		$user->save();
303
+	}
304
+
305
+	/**
306
+	 * Refresh the expired login token.
307
+	 *
308
+	 * @return array
309
+	 */
310
+	public function refreshtoken()
311
+	{
312
+		$token = \JWTAuth::parseToken()->refresh();
313
+
314
+		return ['token' => $token];
315
+	}
316
+
317
+	/**
318
+	 * Paginate all users in the given group based on the given conditions.
319
+	 * 
320
+	 * @param  string  $groupName
321
+	 * @param  array   $relations
322
+	 * @param  integer $perPage
323
+	 * @param  string  $sortBy
324
+	 * @param  boolean $desc
325
+	 * @return \Illuminate\Http\Response
326
+	 */
327
+	public function group($conditions, $groupName, $relations, $perPage, $sortBy, $desc)
328
+	{   
329
+		unset($conditions['page']);
330
+		$conditions = $this->constructConditions($conditions, $this->model);
331
+		$sort       = $desc ? 'desc' : 'asc';
332
+		$model      = call_user_func_array("{$this->getModel()}::with", array($relations));
333
+
334
+		$model->whereHas('groups', function($q) use ($groupName){
335
+			$q->where('name', $groupName);
336
+		});
337 337
 
338 338
         
339
-        if (count($conditions['conditionValues']))
340
-        {
341
-            $model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
342
-        }
343
-
344
-        if ($perPage) 
345
-        {
346
-            return $model->orderBy($sortBy, $sort)->paginate($perPage);
347
-        }
348
-
349
-        return $model->orderBy($sortBy, $sort)->get();
350
-    }
351
-
352
-    /**
353
-     * Save the given data to the logged in user.
354
-     *
355
-     * @param  array $credentials
356
-     * @return object
357
-     */
358
-    public function saveProfile($credentials) 
359
-    {
360
-        $user = \JWTAuth::parseToken()->authenticate();
361
-        $user->save($credentials);
362
-
363
-        return $user;
364
-    }
339
+		if (count($conditions['conditionValues']))
340
+		{
341
+			$model->whereRaw($conditions['conditionString'], $conditions['conditionValues']);
342
+		}
343
+
344
+		if ($perPage) 
345
+		{
346
+			return $model->orderBy($sortBy, $sort)->paginate($perPage);
347
+		}
348
+
349
+		return $model->orderBy($sortBy, $sort)->get();
350
+	}
351
+
352
+	/**
353
+	 * Save the given data to the logged in user.
354
+	 *
355
+	 * @param  array $credentials
356
+	 * @return object
357
+	 */
358
+	public function saveProfile($credentials) 
359
+	{
360
+		$user = \JWTAuth::parseToken()->authenticate();
361
+		$user->save($credentials);
362
+
363
+		return $user;
364
+	}
365 365
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
         $user        = \Core::users()->find(\JWTAuth::parseToken()->authenticate()->id, $relations);
27 27
         foreach ($user->groups()->get() as $group)
28 28
         {
29
-            $group->permissions->each(function ($permission) use (&$permissions){
29
+            $group->permissions->each(function($permission) use (&$permissions){
30 30
                 $permissions[$permission->model][$permission->id] = $permission->name;
31 31
             });
32 32
         }
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      * @param  boolean $user
45 45
      * @return boolean
46 46
      */
47
-    public function can($nameOfPermission, $model, $user = false )
47
+    public function can($nameOfPermission, $model, $user = false)
48 48
     {      
49 49
         $user        = $user ?: \JWTAuth::parseToken()->authenticate();
50 50
         $permissions = [];
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
             \ErrorHandler::tokenExpired();
55 55
         }
56 56
 
57
-        $user->groups->pluck('permissions')->each(function ($permission) use (&$permissions, $model){
57
+        $user->groups->pluck('permissions')->each(function($permission) use (&$permissions, $model){
58 58
             $permissions = array_merge($permissions, $permission->where('model', $model)->pluck('name')->toArray()); 
59 59
         });
60 60
         
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
      */
83 83
     public function assignGroups($user_id, $group_ids)
84 84
     {
85
-        \DB::transaction(function () use ($user_id, $group_ids) {
85
+        \DB::transaction(function() use ($user_id, $group_ids) {
86 86
             $user = $this->find($user_id);
87 87
             $user->groups()->detach();
88 88
             $user->groups()->attach($group_ids);
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
         $url   = $this->config['resetLink'];
246 246
         $token = \Password::getRepository()->create($user);
247 247
         
248
-        \Mail::send('Acl:resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function ($m) use ($user) {
248
+        \Mail::send('Acl:resetpassword', ['user' => $user, 'url' => $url, 'token' => $token], function($m) use ($user) {
249 249
             $m->to($user->email, $user->name)->subject('Your Password Reset Link');
250 250
         });
251 251
     }
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
     public function resetPassword($credentials)
260 260
     {
261 261
         $token    = false;
262
-        $response = \Password::reset($credentials, function ($user, $password) use (&$token) {
262
+        $response = \Password::reset($credentials, function($user, $password) use (&$token) {
263 263
             $user->password = bcrypt($password);
264 264
             $user->save();
265 265
 
Please login to merge, or discard this patch.
src/Modules/V1/Acl/Http/Controllers/UsersController.php 1 patch
Indentation   +219 added lines, -219 removed lines patch added patch discarded remove patch
@@ -7,250 +7,250 @@
 block discarded – undo
7 7
 
8 8
 class UsersController extends BaseApiController
9 9
 {
10
-    /**
11
-     * The name of the model that is used by the base api controller 
12
-     * to preform actions like (add, edit ... etc).
13
-     * @var string
14
-     */
15
-    protected $model               = 'users';
10
+	/**
11
+	 * The name of the model that is used by the base api controller 
12
+	 * to preform actions like (add, edit ... etc).
13
+	 * @var string
14
+	 */
15
+	protected $model               = 'users';
16 16
 
17
-    /**
18
-     * List of all route actions that the base api controller
19
-     * will skip permissions check for them.
20
-     * @var array
21
-     */
22
-    protected $skipPermissionCheck = ['account', 'logout', 'sendreset', 'changePassword'];
17
+	/**
18
+	 * List of all route actions that the base api controller
19
+	 * will skip permissions check for them.
20
+	 * @var array
21
+	 */
22
+	protected $skipPermissionCheck = ['account', 'logout', 'sendreset', 'changePassword'];
23 23
 
24
-    /**
25
-     * List of all route actions that the base api controller
26
-     * will skip login check for them.
27
-     * @var array
28
-     */
29
-    protected $skipLoginCheck      = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken'];
24
+	/**
25
+	 * List of all route actions that the base api controller
26
+	 * will skip login check for them.
27
+	 * @var array
28
+	 */
29
+	protected $skipLoginCheck      = ['login', 'loginSocial', 'register', 'sendreset', 'resetpassword', 'refreshtoken'];
30 30
 
31
-    /**
32
-     * The validations rules used by the base api controller
33
-     * to check before add.
34
-     * @var array
35
-     */
36
-    protected $validationRules     = [
37
-        'name'     => 'nullable|string|unique:users,name,{id},id,name,NOT_NULL', 
38
-        'email'    => 'required|email|unique:users,email,{id},id,email,NOT_NULL', 
39
-        'password' => 'nullable|min:6'
40
-    ];
31
+	/**
32
+	 * The validations rules used by the base api controller
33
+	 * to check before add.
34
+	 * @var array
35
+	 */
36
+	protected $validationRules     = [
37
+		'name'     => 'nullable|string|unique:users,name,{id},id,name,NOT_NULL', 
38
+		'email'    => 'required|email|unique:users,email,{id},id,email,NOT_NULL', 
39
+		'password' => 'nullable|min:6'
40
+	];
41 41
 
42
-    /**
43
-     * Return the logged in user account.
44
-     * 
45
-     * @return \Illuminate\Http\Response
46
-     */
47
-    public function account()
48
-    {
49
-        return \Response::json(\Core::users()->account($this->relations), 200);
50
-    }
42
+	/**
43
+	 * Return the logged in user account.
44
+	 * 
45
+	 * @return \Illuminate\Http\Response
46
+	 */
47
+	public function account()
48
+	{
49
+		return \Response::json(\Core::users()->account($this->relations), 200);
50
+	}
51 51
 
52
-    /**
53
-     * Block the user.
54
-     *
55
-     * @param  integer  $id Id of the user.
56
-     * @return \Illuminate\Http\Response
57
-     */
58
-    public function block($id)
59
-    {
60
-        return \Response::json(\Core::users()->block($id), 200);
61
-    }
52
+	/**
53
+	 * Block the user.
54
+	 *
55
+	 * @param  integer  $id Id of the user.
56
+	 * @return \Illuminate\Http\Response
57
+	 */
58
+	public function block($id)
59
+	{
60
+		return \Response::json(\Core::users()->block($id), 200);
61
+	}
62 62
 
63
-    /**
64
-     * Unblock the user.
65
-     *
66
-     * @param  integer  $id Id of the user.
67
-     * @return \Illuminate\Http\Response
68
-     */
69
-    public function unblock($id)
70
-    {
71
-        return \Response::json(\Core::users()->unblock($id), 200);
72
-    }
63
+	/**
64
+	 * Unblock the user.
65
+	 *
66
+	 * @param  integer  $id Id of the user.
67
+	 * @return \Illuminate\Http\Response
68
+	 */
69
+	public function unblock($id)
70
+	{
71
+		return \Response::json(\Core::users()->unblock($id), 200);
72
+	}
73 73
 
74
-    /**
75
-     * Logout the user.
76
-     * 
77
-     * @return \Illuminate\Http\Response
78
-     */
79
-    public function logout()
80
-    {
81
-        return \Response::json(\Core::users()->logout(), 200);
82
-    }
74
+	/**
75
+	 * Logout the user.
76
+	 * 
77
+	 * @return \Illuminate\Http\Response
78
+	 */
79
+	public function logout()
80
+	{
81
+		return \Response::json(\Core::users()->logout(), 200);
82
+	}
83 83
 
84
-    /**
85
-     * Handle a registration request.
86
-     *
87
-     * @param  \Illuminate\Http\Request  $request
88
-     * @return \Illuminate\Http\Response
89
-     */
90
-    public function register(Request $request)
91
-    {
92
-        $this->validate($request, [
93
-            'name'     => 'nullable|string|unique:users,name,{id},id,name,NOT_NULL', 
94
-            'email'    => 'required|email|unique:users,email,{id},id,email,NOT_NULL', 
95
-            'password' => 'required|min:6'
96
-            ]);
84
+	/**
85
+	 * Handle a registration request.
86
+	 *
87
+	 * @param  \Illuminate\Http\Request  $request
88
+	 * @return \Illuminate\Http\Response
89
+	 */
90
+	public function register(Request $request)
91
+	{
92
+		$this->validate($request, [
93
+			'name'     => 'nullable|string|unique:users,name,{id},id,name,NOT_NULL', 
94
+			'email'    => 'required|email|unique:users,email,{id},id,email,NOT_NULL', 
95
+			'password' => 'required|min:6'
96
+			]);
97 97
 
98
-        return \Response::json(\Core::users()->register($request->only('email', 'password')), 200);
99
-    }
98
+		return \Response::json(\Core::users()->register($request->only('email', 'password')), 200);
99
+	}
100 100
 
101
-    /**
102
-     * Handle a login request of the none admin to the application.
103
-     *
104
-     * @param  \Illuminate\Http\Request  $request
105
-     * @return \Illuminate\Http\Response
106
-     */
107
-    public function login(Request $request)
108
-    {
109
-        $this->validate($request, [
110
-            'email'    => 'required|email', 
111
-            'password' => 'required|min:6',
112
-            'admin'    => 'boolean'
113
-            ]);
101
+	/**
102
+	 * Handle a login request of the none admin to the application.
103
+	 *
104
+	 * @param  \Illuminate\Http\Request  $request
105
+	 * @return \Illuminate\Http\Response
106
+	 */
107
+	public function login(Request $request)
108
+	{
109
+		$this->validate($request, [
110
+			'email'    => 'required|email', 
111
+			'password' => 'required|min:6',
112
+			'admin'    => 'boolean'
113
+			]);
114 114
 
115
-        return \Response::json(\Core::users()->login($request->only('email', 'password'), $request->get('admin')), 200);
116
-    }
115
+		return \Response::json(\Core::users()->login($request->only('email', 'password'), $request->get('admin')), 200);
116
+	}
117 117
 
118
-    /**
119
-     * Handle a social login request of the none admin to the application.
120
-     *
121
-     * @param  \Illuminate\Http\Request  $request
122
-     * @return \Illuminate\Http\Response
123
-     */
124
-    public function loginSocial(Request $request)
125
-    {
126
-        $this->validate($request, [
127
-            'auth_code'    => 'required_without:access_token',
128
-            'access_token' => 'required_without:auth_code',
129
-            'type'         => 'required|in:facebook,google'
130
-            ]);
118
+	/**
119
+	 * Handle a social login request of the none admin to the application.
120
+	 *
121
+	 * @param  \Illuminate\Http\Request  $request
122
+	 * @return \Illuminate\Http\Response
123
+	 */
124
+	public function loginSocial(Request $request)
125
+	{
126
+		$this->validate($request, [
127
+			'auth_code'    => 'required_without:access_token',
128
+			'access_token' => 'required_without:auth_code',
129
+			'type'         => 'required|in:facebook,google'
130
+			]);
131 131
 
132
-        return \Response::json(\Core::users()->loginSocial($request->only('auth_code', 'access_token', 'type')), 200);
133
-    }
132
+		return \Response::json(\Core::users()->loginSocial($request->only('auth_code', 'access_token', 'type')), 200);
133
+	}
134 134
 
135
-    /**
136
-     * Assign the given groups to the given user.
137
-     *
138
-     * @param  \Illuminate\Http\Request  $request
139
-     * @return \Illuminate\Http\Response
140
-     */
141
-    public function assigngroups(Request $request)
142
-    {
143
-        $this->validate($request, [
144
-            'group_ids' => 'required|exists:groups,id', 
145
-            'user_id'   => 'required|exists:users,id'
146
-            ]);
135
+	/**
136
+	 * Assign the given groups to the given user.
137
+	 *
138
+	 * @param  \Illuminate\Http\Request  $request
139
+	 * @return \Illuminate\Http\Response
140
+	 */
141
+	public function assigngroups(Request $request)
142
+	{
143
+		$this->validate($request, [
144
+			'group_ids' => 'required|exists:groups,id', 
145
+			'user_id'   => 'required|exists:users,id'
146
+			]);
147 147
 
148
-        return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
149
-    }
148
+		return \Response::json(\Core::users()->assignGroups($request->get('user_id'), $request->get('group_ids')), 200);
149
+	}
150 150
 
151
-    /**
152
-     * Send a reset link to the given user.
153
-     *
154
-     * @param  \Illuminate\Http\Request  $request
155
-     * @return \Illuminate\Http\Response
156
-     */
157
-    public function sendreset(Request $request)
158
-    {
159
-        $this->validate($request, ['email' => 'required|email']);
151
+	/**
152
+	 * Send a reset link to the given user.
153
+	 *
154
+	 * @param  \Illuminate\Http\Request  $request
155
+	 * @return \Illuminate\Http\Response
156
+	 */
157
+	public function sendreset(Request $request)
158
+	{
159
+		$this->validate($request, ['email' => 'required|email']);
160 160
 
161
-        return \Response::json(\Core::users()->sendReset($request->only('email')), 200);
162
-    }
161
+		return \Response::json(\Core::users()->sendReset($request->only('email')), 200);
162
+	}
163 163
 
164
-    /**
165
-     * Reset the given user's password.
166
-     *
167
-     * @param  \Illuminate\Http\Request  $request
168
-     * @return \Illuminate\Http\Response
169
-     */
170
-    public function resetpassword(Request $request)
171
-    {
172
-        $this->validate($request, [
173
-            'token'                 => 'required',
174
-            'email'                 => 'required|email',
175
-            'password'              => 'required|confirmed|min:6',
176
-            'password_confirmation' => 'required',
177
-        ]);
164
+	/**
165
+	 * Reset the given user's password.
166
+	 *
167
+	 * @param  \Illuminate\Http\Request  $request
168
+	 * @return \Illuminate\Http\Response
169
+	 */
170
+	public function resetpassword(Request $request)
171
+	{
172
+		$this->validate($request, [
173
+			'token'                 => 'required',
174
+			'email'                 => 'required|email',
175
+			'password'              => 'required|confirmed|min:6',
176
+			'password_confirmation' => 'required',
177
+		]);
178 178
 
179
-        return \Response::json(\Core::users()->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200);
180
-    }
179
+		return \Response::json(\Core::users()->resetPassword($request->only('email', 'password', 'password_confirmation', 'token')), 200);
180
+	}
181 181
 
182
-    /**
183
-     * Change the logged in user password.
184
-     *
185
-     * @param  \Illuminate\Http\Request  $request
186
-     * @return \Illuminate\Http\Response
187
-     */
188
-    public function changePassword(Request $request)
189
-    {
190
-        $this->validate($request, [
191
-            'old_password'          => 'required',
192
-            'password'              => 'required|confirmed|min:6',
193
-            'password_confirmation' => 'required',
194
-        ]);
182
+	/**
183
+	 * Change the logged in user password.
184
+	 *
185
+	 * @param  \Illuminate\Http\Request  $request
186
+	 * @return \Illuminate\Http\Response
187
+	 */
188
+	public function changePassword(Request $request)
189
+	{
190
+		$this->validate($request, [
191
+			'old_password'          => 'required',
192
+			'password'              => 'required|confirmed|min:6',
193
+			'password_confirmation' => 'required',
194
+		]);
195 195
 
196
-        return \Response::json(\Core::users()->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200);
197
-    }
196
+		return \Response::json(\Core::users()->changePassword($request->only('old_password', 'password', 'password_confirmation')), 200);
197
+	}
198 198
 
199
-    /**
200
-     * Refresh the expired login token.
201
-     *
202
-     * @return \Illuminate\Http\Response
203
-     */
204
-    public function refreshtoken()
205
-    {
206
-        return \Response::json(\Core::users()->refreshtoken(), 200);
207
-    }
199
+	/**
200
+	 * Refresh the expired login token.
201
+	 *
202
+	 * @return \Illuminate\Http\Response
203
+	 */
204
+	public function refreshtoken()
205
+	{
206
+		return \Response::json(\Core::users()->refreshtoken(), 200);
207
+	}
208 208
 
209
-    /**
210
-     * Paginate all users with inthe given group.
211
-     * 
212
-     * @param  \Illuminate\Http\Request  $request
213
-     * @param  string $groupName The name of the requested group.
214
-     * @param  integer $perPage  Number of rows per page default 15.
215
-     * @param  string  $sortBy   The name of the column to sort by.
216
-     * @param  boolean $desc     Sort ascending or descinding (1: desc, 0: asc).
217
-     * @return \Illuminate\Http\Response
218
-     */
219
-    public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1)
220
-    {
221
-        return \Response::json(\Core::users()->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc), 200);
222
-    }
209
+	/**
210
+	 * Paginate all users with inthe given group.
211
+	 * 
212
+	 * @param  \Illuminate\Http\Request  $request
213
+	 * @param  string $groupName The name of the requested group.
214
+	 * @param  integer $perPage  Number of rows per page default 15.
215
+	 * @param  string  $sortBy   The name of the column to sort by.
216
+	 * @param  boolean $desc     Sort ascending or descinding (1: desc, 0: asc).
217
+	 * @return \Illuminate\Http\Response
218
+	 */
219
+	public function group(Request $request, $groupName, $perPage = false, $sortBy = 'created_at', $desc = 1)
220
+	{
221
+		return \Response::json(\Core::users()->group($request->all(), $groupName, $this->relations, $perPage, $sortBy, $desc), 200);
222
+	}
223 223
 
224
-    /**
225
-     * Save the given data to the logged in user.
226
-     *
227
-     * @param  \Illuminate\Http\Request  $request
228
-     * @return \Illuminate\Http\Response
229
-     */
230
-    public function saveProfile(Request $request) 
231
-    {
232
-        foreach ($this->validationRules as &$rule) 
233
-        {
234
-            if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) 
235
-            {
236
-                $rule .= ',deleted_at,NULL';
237
-            }
224
+	/**
225
+	 * Save the given data to the logged in user.
226
+	 *
227
+	 * @param  \Illuminate\Http\Request  $request
228
+	 * @return \Illuminate\Http\Response
229
+	 */
230
+	public function saveProfile(Request $request) 
231
+	{
232
+		foreach ($this->validationRules as &$rule) 
233
+		{
234
+			if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) 
235
+			{
236
+				$rule .= ',deleted_at,NULL';
237
+			}
238 238
 
239
-            if ($request->has('id')) 
240
-            {
241
-                $rule = str_replace('{id}', $request->get('id'), $rule);
242
-            }
243
-            else
244
-            {
245
-                $rule = str_replace(',{id}', '', $rule);
246
-            }
247
-        }
239
+			if ($request->has('id')) 
240
+			{
241
+				$rule = str_replace('{id}', $request->get('id'), $rule);
242
+			}
243
+			else
244
+			{
245
+				$rule = str_replace(',{id}', '', $rule);
246
+			}
247
+		}
248 248
 
249
-        $this->validate($request, $this->validationRules);
249
+		$this->validate($request, $this->validationRules);
250 250
 
251
-        if ($this->model)
252
-        {
253
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->saveProfile($request->all()), 200);
254
-        }
255
-    }
251
+		if ($this->model)
252
+		{
253
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->saveProfile($request->all()), 200);
254
+		}
255
+	}
256 256
 }
Please login to merge, or discard this patch.
Modules/V1/Notifications/Repositories/PushNotificationDeviceRepository.php 1 patch
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -4,75 +4,75 @@
 block discarded – undo
4 4
 
5 5
 class PushNotificationDeviceRepository extends AbstractRepository
6 6
 {
7
-      /**
8
-      * Return the model full namespace.
9
-      * 
10
-      * @return string
11
-      */
12
-      protected function getModel()
13
-      {
14
-          return 'App\Modules\V1\Notifications\PushNotificationDevice';
15
-      }
7
+	  /**
8
+	   * Return the model full namespace.
9
+	   * 
10
+	   * @return string
11
+	   */
12
+	  protected function getModel()
13
+	  {
14
+		  return 'App\Modules\V1\Notifications\PushNotificationDevice';
15
+	  }
16 16
 
17
-    /**
18
-     * Broadcast the message to the given users devices.
19
-     *
20
-     * @param  array  $users_ids
21
-     * @param  string $messageText
22
-     * @return void
23
-     */
24
-    public function broadcast($users_ids, $messageText)
25
-    {
26
-        $devicesArray = [];
27
-        $devices      = $this->model->whereIn('user_id', $users_ids)->get();
28
-        foreach ($devices as $device) 
29
-        {
30
-            $devicesArray[$device->device_type][] = \PushNotification::Device($device->device_token);
31
-        }
17
+	/**
18
+	 * Broadcast the message to the given users devices.
19
+	 *
20
+	 * @param  array  $users_ids
21
+	 * @param  string $messageText
22
+	 * @return void
23
+	 */
24
+	public function broadcast($users_ids, $messageText)
25
+	{
26
+		$devicesArray = [];
27
+		$devices      = $this->model->whereIn('user_id', $users_ids)->get();
28
+		foreach ($devices as $device) 
29
+		{
30
+			$devicesArray[$device->device_type][] = \PushNotification::Device($device->device_token);
31
+		}
32 32
         
33
-        if (array_key_exists('ios', $devicesArray)) 
34
-        {
35
-            $message = $this->constructMessage($messageText, [ 'badge' => 15, 'sound' => 'default', 'content-available' => 1 ]);
36
-            $iosDevices = \PushNotification::DeviceCollection($devicesArray['ios']);
37
-            $this->push('ios', $iosDevices, $message);
38
-        }
33
+		if (array_key_exists('ios', $devicesArray)) 
34
+		{
35
+			$message = $this->constructMessage($messageText, [ 'badge' => 15, 'sound' => 'default', 'content-available' => 1 ]);
36
+			$iosDevices = \PushNotification::DeviceCollection($devicesArray['ios']);
37
+			$this->push('ios', $iosDevices, $message);
38
+		}
39 39
 
40
-        if (array_key_exists('android', $devicesArray)) 
41
-        {
42
-            $message = $this->constructMessage($messageText);
43
-            $androidDevices = \PushNotification::DeviceCollection($devicesArray['android']);
44
-            $this->push('android', $androidDevices, $message);
45
-        }
46
-    }
40
+		if (array_key_exists('android', $devicesArray)) 
41
+		{
42
+			$message = $this->constructMessage($messageText);
43
+			$androidDevices = \PushNotification::DeviceCollection($devicesArray['android']);
44
+			$this->push('android', $androidDevices, $message);
45
+		}
46
+	}
47 47
 
48 48
 
49
-    /**
50
-     * Push the given message to the given devices.
51
-     *
52
-     * @param  string    $type
53
-     * @param  colletion $devices
54
-     * @param  string    $message
55
-     * @return object
56
-     */
57
-    public function push($type, $devices, $message)
58
-    {
59
-        $collection = \PushNotification::app($type)->to($devices)->send($message);
60
-        foreach ($collection->pushManager as $push) 
61
-        {
62
-            $response[] = $push->getAdapter()->getResponse();
63
-        }
64
-        dd($response);
65
-    }
49
+	/**
50
+	 * Push the given message to the given devices.
51
+	 *
52
+	 * @param  string    $type
53
+	 * @param  colletion $devices
54
+	 * @param  string    $message
55
+	 * @return object
56
+	 */
57
+	public function push($type, $devices, $message)
58
+	{
59
+		$collection = \PushNotification::app($type)->to($devices)->send($message);
60
+		foreach ($collection->pushManager as $push) 
61
+		{
62
+			$response[] = $push->getAdapter()->getResponse();
63
+		}
64
+		dd($response);
65
+	}
66 66
 
67
-    /**
68
-     * Construct the notification message.
69
-     *
70
-     * @param  string $messageText
71
-     * @param  array  $options
72
-     * @return object
73
-     */
74
-    protected function constructMessage($messageText, $options = [])
75
-    {
76
-        return \PushNotification::Message($messageText, $options);
77
-    }
67
+	/**
68
+	 * Construct the notification message.
69
+	 *
70
+	 * @param  string $messageText
71
+	 * @param  array  $options
72
+	 * @return object
73
+	 */
74
+	protected function constructMessage($messageText, $options = [])
75
+	{
76
+		return \PushNotification::Message($messageText, $options);
77
+	}
78 78
 }
Please login to merge, or discard this patch.
src/Modules/V1/Notifications/Http/Controllers/NotificationsController.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -8,30 +8,30 @@
 block discarded – undo
8 8
 class NotificationsController extends BaseApiController
9 9
 {
10 10
 	/**
11
-     * The name of the model that is used by the base api controller 
12
-     * to preform actions like (add, edit ... etc).
13
-     * @var string
14
-     */
15
-    protected $model            = 'notifications';
11
+	 * The name of the model that is used by the base api controller 
12
+	 * to preform actions like (add, edit ... etc).
13
+	 * @var string
14
+	 */
15
+	protected $model            = 'notifications';
16 16
 
17
-    /**
18
-     * Set the notification notified to true.
19
-     * 
20
-     * @param  integer  $id Id of the notification.
21
-     * @return \Illuminate\Http\Response
22
-     */
23
-    public function notified($id)
24
-    {
25
-        return \Response::json(\Core::notifications()->notified($id), 200);
26
-    }
17
+	/**
18
+	 * Set the notification notified to true.
19
+	 * 
20
+	 * @param  integer  $id Id of the notification.
21
+	 * @return \Illuminate\Http\Response
22
+	 */
23
+	public function notified($id)
24
+	{
25
+		return \Response::json(\Core::notifications()->notified($id), 200);
26
+	}
27 27
 
28
-    /**
29
-     * Set the notification notified to all.
30
-     * 
31
-     * @return \Illuminate\Http\Response
32
-     */
33
-    public function notifyall()
34
-    {
35
-        return \Response::json(\Core::notifications()->notifyAll(), 200);
36
-    }
28
+	/**
29
+	 * Set the notification notified to all.
30
+	 * 
31
+	 * @return \Illuminate\Http\Response
32
+	 */
33
+	public function notifyall()
34
+	{
35
+		return \Response::json(\Core::notifications()->notifyAll(), 200);
36
+	}
37 37
 }
Please login to merge, or discard this patch.
src/Modules/V1/Reporting/Http/Controllers/ReportsController.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -7,33 +7,33 @@
 block discarded – undo
7 7
 
8 8
 class ReportsController extends BaseApiController
9 9
 {
10
-    /**
11
-     * The name of the model that is used by the base api controller 
12
-     * to preform actions like (add, edit ... etc).
13
-     * @var string
14
-     */
15
-    protected $model               = 'reports';
10
+	/**
11
+	 * The name of the model that is used by the base api controller 
12
+	 * to preform actions like (add, edit ... etc).
13
+	 * @var string
14
+	 */
15
+	protected $model               = 'reports';
16 16
 
17
-    /**
18
-     * List of all route actions that the base api controller
19
-     * will skip permissions check for them.
20
-     * @var array
21
-     */
22
-    protected $skipPermissionCheck = ['getReport'];
17
+	/**
18
+	 * List of all route actions that the base api controller
19
+	 * will skip permissions check for them.
20
+	 * @var array
21
+	 */
22
+	protected $skipPermissionCheck = ['getReport'];
23 23
 
24
-    /**
25
-     * Render the given report name with the given conditions.
26
-     *
27
-     * @param  \Illuminate\Http\Request  $request
28
-     * @param  string  $reportName Name of the requested report
29
-     * @param  integer $perPage    Number of rows per page default all data.
30
-     * @return \Illuminate\Http\Response
31
-     */
32
-    public function getReport(Request $request, $reportName, $perPage = 0) 
33
-    {
34
-        if ($this->model) 
35
-        {
36
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->getReport($reportName, $request->all(), $perPage), 200);
37
-        }
38
-    }
24
+	/**
25
+	 * Render the given report name with the given conditions.
26
+	 *
27
+	 * @param  \Illuminate\Http\Request  $request
28
+	 * @param  string  $reportName Name of the requested report
29
+	 * @param  integer $perPage    Number of rows per page default all data.
30
+	 * @return \Illuminate\Http\Response
31
+	 */
32
+	public function getReport(Request $request, $reportName, $perPage = 0) 
33
+	{
34
+		if ($this->model) 
35
+		{
36
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->getReport($reportName, $request->all(), $perPage), 200);
37
+		}
38
+	}
39 39
 }
Please login to merge, or discard this patch.
src/Modules/V1/Core/Decorators/CachingDecorator.php 2 patches
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -2,96 +2,96 @@
 block discarded – undo
2 2
 
3 3
 class CachingDecorator
4 4
 {
5
-    /**
6
-     * The repo implementation.
7
-     * 
8
-     * @var string
9
-     */
10
-    protected $repo;
5
+	/**
6
+	 * The repo implementation.
7
+	 * 
8
+	 * @var string
9
+	 */
10
+	protected $repo;
11 11
 
12
-    /**
13
-     * The cache implementation.
14
-     * 
15
-     * @var object
16
-     */
17
-    protected $cache;
12
+	/**
13
+	 * The cache implementation.
14
+	 * 
15
+	 * @var object
16
+	 */
17
+	protected $cache;
18 18
 
19
-    /**
20
-     * The model implementation.
21
-     * 
22
-     * @var string
23
-     */
24
-    public $model;
19
+	/**
20
+	 * The model implementation.
21
+	 * 
22
+	 * @var string
23
+	 */
24
+	public $model;
25 25
 
26
-    /**
27
-     * The cacheConfig implementation.
28
-     * 
29
-     * @var array
30
-     */
31
-    public $cacheConfig;
26
+	/**
27
+	 * The cacheConfig implementation.
28
+	 * 
29
+	 * @var array
30
+	 */
31
+	public $cacheConfig;
32 32
     
33
-    /**
34
-     * Create new CachingDecorator instance.
35
-     */
36
-    public function __construct($repo, $cache)
37
-    {   
38
-        $this->repo  = $repo;
39
-        $this->cache = $cache;
40
-        $this->model = get_class($this->repo->model);
41
-    }
33
+	/**
34
+	 * Create new CachingDecorator instance.
35
+	 */
36
+	public function __construct($repo, $cache)
37
+	{   
38
+		$this->repo  = $repo;
39
+		$this->cache = $cache;
40
+		$this->model = get_class($this->repo->model);
41
+	}
42 42
 
43
-    /**
44
-     * Handle the cache mechanism for the called method
45
-     * based the configurations.
46
-     * 
47
-     * @param  string $name the called method name
48
-     * @param  array  $arguments the method arguments
49
-     * @return object
50
-     */
51
-    public function __call($name, $arguments)
52
-    {
53
-        $this->setCacheConfig($name);
43
+	/**
44
+	 * Handle the cache mechanism for the called method
45
+	 * based the configurations.
46
+	 * 
47
+	 * @param  string $name the called method name
48
+	 * @param  array  $arguments the method arguments
49
+	 * @return object
50
+	 */
51
+	public function __call($name, $arguments)
52
+	{
53
+		$this->setCacheConfig($name);
54 54
 
55
-        if ($this->cacheConfig && $this->cacheConfig == 'cache') 
56
-        {
57
-            $page     = \Request::get('page') ?? '1';
58
-            $cacheKey = $name . $page . serialize($arguments);
59
-            return $this->cache->tags([$this->model])->rememberForever($cacheKey, function() use ($arguments, $name) {
60
-                return call_user_func_array([$this->repo, $name], $arguments);
61
-            });
62
-        }
63
-        else if ($this->cacheConfig)
64
-        {
65
-            $this->cache->tags($this->cacheConfig)->flush();
66
-            return call_user_func_array([$this->repo, $name], $arguments);
67
-        }
55
+		if ($this->cacheConfig && $this->cacheConfig == 'cache') 
56
+		{
57
+			$page     = \Request::get('page') ?? '1';
58
+			$cacheKey = $name . $page . serialize($arguments);
59
+			return $this->cache->tags([$this->model])->rememberForever($cacheKey, function() use ($arguments, $name) {
60
+				return call_user_func_array([$this->repo, $name], $arguments);
61
+			});
62
+		}
63
+		else if ($this->cacheConfig)
64
+		{
65
+			$this->cache->tags($this->cacheConfig)->flush();
66
+			return call_user_func_array([$this->repo, $name], $arguments);
67
+		}
68 68
 
69
-        return call_user_func_array([$this->repo, $name], $arguments);
70
-    }
69
+		return call_user_func_array([$this->repo, $name], $arguments);
70
+	}
71 71
 
72
-    /**
73
-     * Set cache config based on the called method.
74
-     * 
75
-     * @param  string $name
76
-     * @return void
77
-     */
78
-    private function setCacheConfig($name)
79
-    {
80
-        $strArr            = explode('\\', get_class($this->repo));
81
-        $repoName          = end($strArr);
82
-        $configKey         = str_plural(strtolower(substr($repoName, 0, strpos($repoName, 'Repository'))));
72
+	/**
73
+	 * Set cache config based on the called method.
74
+	 * 
75
+	 * @param  string $name
76
+	 * @return void
77
+	 */
78
+	private function setCacheConfig($name)
79
+	{
80
+		$strArr            = explode('\\', get_class($this->repo));
81
+		$repoName          = end($strArr);
82
+		$configKey         = str_plural(strtolower(substr($repoName, 0, strpos($repoName, 'Repository'))));
83 83
         
84
-        $config            = \CoreConfig::getConfig();
85
-        $cacheConfig       = array_key_exists($configKey, $config['cacheConfig']) ? $config['cacheConfig'][$configKey] : false;
86
-        $this->cacheConfig = false;
84
+		$config            = \CoreConfig::getConfig();
85
+		$cacheConfig       = array_key_exists($configKey, $config['cacheConfig']) ? $config['cacheConfig'][$configKey] : false;
86
+		$this->cacheConfig = false;
87 87
 
88
-        if (in_array($name, $cacheConfig['cache']))
89
-        {
90
-            $this->cacheConfig = 'cache';
91
-        }
92
-        else if (in_array($name, $cacheConfig['clear']))
93
-        {
94
-            $this->cacheConfig = $cacheConfig['clear'][$name];
95
-        }
96
-    }
88
+		if (in_array($name, $cacheConfig['cache']))
89
+		{
90
+			$this->cacheConfig = 'cache';
91
+		}
92
+		else if (in_array($name, $cacheConfig['clear']))
93
+		{
94
+			$this->cacheConfig = $cacheConfig['clear'][$name];
95
+		}
96
+	}
97 97
 }
98 98
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -59,8 +59,7 @@  discard block
 block discarded – undo
59 59
             return $this->cache->tags([$this->model])->rememberForever($cacheKey, function() use ($arguments, $name) {
60 60
                 return call_user_func_array([$this->repo, $name], $arguments);
61 61
             });
62
-        }
63
-        else if ($this->cacheConfig)
62
+        } else if ($this->cacheConfig)
64 63
         {
65 64
             $this->cache->tags($this->cacheConfig)->flush();
66 65
             return call_user_func_array([$this->repo, $name], $arguments);
@@ -88,8 +87,7 @@  discard block
 block discarded – undo
88 87
         if (in_array($name, $cacheConfig['cache']))
89 88
         {
90 89
             $this->cacheConfig = 'cache';
91
-        }
92
-        else if (in_array($name, $cacheConfig['clear']))
90
+        } else if (in_array($name, $cacheConfig['clear']))
93 91
         {
94 92
             $this->cacheConfig = $cacheConfig['clear'][$name];
95 93
         }
Please login to merge, or discard this patch.
src/Modules/V1/Core/Http/Controllers/ApiDocumentController.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 {
9 9
 	public function index() 
10 10
 	{
11
-		$path       = str_replace($_SERVER['DOCUMENT_ROOT'], '',str_replace('\\', '/', __FILE__));
11
+		$path       = str_replace($_SERVER['DOCUMENT_ROOT'], '', str_replace('\\', '/', __FILE__));
12 12
 		$baseUrl    = str_replace('Http/Controllers/ApiDocumentController.php', '', $path);
13 13
 		$jsonDoc    = json_decode(file_get_contents(app_path('Modules/V1/Core/Resources/api.json')), true);
14 14
 		$modules    = $jsonDoc['modules'];
@@ -68,6 +68,6 @@  discard block
 block discarded – undo
68 68
 		$reflectionClass = new \ReflectionClass($controller);
69 69
 		$classProperties = $reflectionClass->getDefaultProperties();
70 70
 		
71
-		return \Response::json(call_user_func_array("\Core::{$classProperties['model']}", [])->$method(), 200);;
71
+		return \Response::json(call_user_func_array("\Core::{$classProperties['model']}", [])->$method(), 200); ;
72 72
 	}
73 73
 }
Please login to merge, or discard this patch.