Completed
Push — master ( 5049fe...5fd7f0 )
by Sherif
02:43
created
src/Modules/V1/Core/Interfaces/RepositoryInterface.php 1 patch
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -3,127 +3,127 @@
 block discarded – undo
3 3
 interface RepositoryInterface
4 4
 {
5 5
 	/**
6
-     * Fetch all records with relations from the storage.
7
-     * 
8
-     * @param  array  $relations
9
-     * @param  array   $sortBy
10
-     * @param  array   $desc
11
-     * @param  array  $columns
12
-     * @return collection
13
-     */
6
+	 * Fetch all records with relations from the storage.
7
+	 * 
8
+	 * @param  array  $relations
9
+	 * @param  array   $sortBy
10
+	 * @param  array   $desc
11
+	 * @param  array  $columns
12
+	 * @return collection
13
+	 */
14 14
 	public function all($relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
15 15
  	
16
-    /**
17
-     * Fetch all records with relations from storage in pages 
18
-     * that matche the given query.
19
-     * 
20
-     * @param  string  $query
21
-     * @param  integer $perPage
22
-     * @param  array   $relations
23
-     * @param  array   $sortBy
24
-     * @param  array   $desc
25
-     * @param  array   $columns
26
-     * @return collection
27
-     */
28
-    public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
16
+	/**
17
+	 * Fetch all records with relations from storage in pages 
18
+	 * that matche the given query.
19
+	 * 
20
+	 * @param  string  $query
21
+	 * @param  integer $perPage
22
+	 * @param  array   $relations
23
+	 * @param  array   $sortBy
24
+	 * @param  array   $desc
25
+	 * @param  array   $columns
26
+	 * @return collection
27
+	 */
28
+	public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
29 29
 
30 30
 	/**
31
-     * Fetch all records with relations from storage in pages.
32
-     * 
33
-     * @param  integer $perPage
34
-     * @param  array   $relations
35
-     * @param  array   $sortBy
36
-     * @param  array   $desc
37
-     * @param  array   $columns
38
-     * @return collection
39
-     */
40
-    public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
31
+	 * Fetch all records with relations from storage in pages.
32
+	 * 
33
+	 * @param  integer $perPage
34
+	 * @param  array   $relations
35
+	 * @param  array   $sortBy
36
+	 * @param  array   $desc
37
+	 * @param  array   $columns
38
+	 * @return collection
39
+	 */
40
+	public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
41 41
  	
42 42
 	/**
43
-     * Fetch all records with relations based on
44
-     * the given condition from storage in pages.
45
-     * 
46
-     * @param  array   $conditions array of conditions
47
-     * @param  integer $perPage
48
-     * @param  array   $relations
49
-     * @param  array   $sortBy
50
-     * @param  array   $desc
51
-     * @param  array   $columns
52
-     * @return collection
53
-     */
54
-    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
43
+	 * Fetch all records with relations based on
44
+	 * the given condition from storage in pages.
45
+	 * 
46
+	 * @param  array   $conditions array of conditions
47
+	 * @param  integer $perPage
48
+	 * @param  array   $relations
49
+	 * @param  array   $sortBy
50
+	 * @param  array   $desc
51
+	 * @param  array   $columns
52
+	 * @return collection
53
+	 */
54
+	public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
55 55
 
56
-     /**
57
-     * Save the given model/models to the storage.
58
-     * 
59
-     * @param  array   $data
60
-     * @param  boolean $saveLog
61
-     * @return object
62
-     */
63
-    public function save(array $data, $saveLog = true);
56
+	 /**
57
+	  * Save the given model/models to the storage.
58
+	  * 
59
+	  * @param  array   $data
60
+	  * @param  boolean $saveLog
61
+	  * @return object
62
+	  */
63
+	public function save(array $data, $saveLog = true);
64 64
  	
65
-    /**
66
-     * Insert multiple records to the storage.
67
-     * 
68
-     * @param  array   $data
69
-     * @return array
70
-     */
71
-    public function saveMany(array $data);
65
+	/**
66
+	 * Insert multiple records to the storage.
67
+	 * 
68
+	 * @param  array   $data
69
+	 * @return array
70
+	 */
71
+	public function saveMany(array $data);
72 72
 
73 73
 	/**
74
-     * Update record in the storage based on the given
75
-     * condition.
76
-     * 
77
-     * @param  [type] $value condition value
78
-     * @param  array $data
79
-     * @param  string $attribute condition column name
80
-     * @return integer affected rows
81
-     */
82
-    public function update($value, array $data, $attribute = 'id');
74
+	 * Update record in the storage based on the given
75
+	 * condition.
76
+	 * 
77
+	 * @param  [type] $value condition value
78
+	 * @param  array $data
79
+	 * @param  string $attribute condition column name
80
+	 * @return integer affected rows
81
+	 */
82
+	public function update($value, array $data, $attribute = 'id');
83 83
  	
84 84
 	/**
85
-     * Delete record from the storage based on the given
86
-     * condition.
87
-     * 
88
-     * @param  [type] $value condition value
89
-     * @param  string $attribute condition column name
90
-     * @return integer affected rows
91
-     */
92
-    public function delete($value, $attribute = 'id');
85
+	 * Delete record from the storage based on the given
86
+	 * condition.
87
+	 * 
88
+	 * @param  [type] $value condition value
89
+	 * @param  string $attribute condition column name
90
+	 * @return integer affected rows
91
+	 */
92
+	public function delete($value, $attribute = 'id');
93 93
  	
94 94
 	/**
95
-     * Fetch records from the storage based on the given
96
-     * id.
97
-     * 
98
-     * @param  integer $id
99
-     * @param  array   $relations
100
-     * @param  array   $columns
101
-     * @return object
102
-     */
103
-    public function find($id, $relations = [], $columns = array('*'));
95
+	 * Fetch records from the storage based on the given
96
+	 * id.
97
+	 * 
98
+	 * @param  integer $id
99
+	 * @param  array   $relations
100
+	 * @param  array   $columns
101
+	 * @return object
102
+	 */
103
+	public function find($id, $relations = [], $columns = array('*'));
104 104
  	
105 105
 	/**
106
-     * Fetch records from the storage based on the given
107
-     * condition.
108
-     * 
109
-     * @param  array   $conditions array of conditions
110
-     * @param  array   $relations
111
-     * @param  array   $sortBy
112
-     * @param  array   $desc
113
-     * @param  array   $columns
114
-     * @return collection
115
-     */
116
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
106
+	 * Fetch records from the storage based on the given
107
+	 * condition.
108
+	 * 
109
+	 * @param  array   $conditions array of conditions
110
+	 * @param  array   $relations
111
+	 * @param  array   $sortBy
112
+	 * @param  array   $desc
113
+	 * @param  array   $columns
114
+	 * @return collection
115
+	 */
116
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 0, $columns = array('*'));
117 117
 
118
-    /**
119
-     * Fetch the first record fro the storage based on the given
120
-     * condition.
121
-     * 
122
-     * @param  array   $conditions array of conditions
123
-     * @param  [type]  $value condition value
124
-     * @param  array   $relations
125
-     * @param  array   $columns
126
-     * @return object
127
-     */
128
-    public function first($conditions, $relations = [], $columns = array('*'));
118
+	/**
119
+	 * Fetch the first record fro the storage based on the given
120
+	 * condition.
121
+	 * 
122
+	 * @param  array   $conditions array of conditions
123
+	 * @param  [type]  $value condition value
124
+	 * @param  array   $relations
125
+	 * @param  array   $columns
126
+	 * @return object
127
+	 */
128
+	public function first($conditions, $relations = [], $columns = array('*'));
129 129
 }
130 130
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Core/AbstractRepositories/AbstractRepository.php 1 patch
Indentation   +410 added lines, -410 removed lines patch added patch discarded remove patch
@@ -4,447 +4,447 @@
 block discarded – undo
4 4
 
5 5
 abstract class AbstractRepository implements RepositoryInterface
6 6
 {
7
-    /**
8
-     * The model implementation.
9
-     * 
10
-     * @var model
11
-     */
12
-    public $model;
7
+	/**
8
+	 * The model implementation.
9
+	 * 
10
+	 * @var model
11
+	 */
12
+	public $model;
13 13
     
14
-    /**
15
-     * The config implementation.
16
-     * 
17
-     * @var config
18
-     */
19
-    protected $config;
14
+	/**
15
+	 * The config implementation.
16
+	 * 
17
+	 * @var config
18
+	 */
19
+	protected $config;
20 20
     
21
-    /**
22
-     * Create new AbstractRepository instance.
23
-     */
24
-    public function __construct()
25
-    {   
26
-        $this->config = \CoreConfig::getConfig();
27
-        $this->model  = \App::make($this->getModel());
28
-    }
21
+	/**
22
+	 * Create new AbstractRepository instance.
23
+	 */
24
+	public function __construct()
25
+	{   
26
+		$this->config = \CoreConfig::getConfig();
27
+		$this->model  = \App::make($this->getModel());
28
+	}
29 29
 
30
-    /**
31
-     * Fetch all records with relations from the storage.
32
-     *
33
-     * @param  array   $relations
34
-     * @param  string  $sortBy
35
-     * @param  boolean $desc
36
-     * @param  array   $columns
37
-     * @return collection
38
-     */
30
+	/**
31
+	 * Fetch all records with relations from the storage.
32
+	 *
33
+	 * @param  array   $relations
34
+	 * @param  string  $sortBy
35
+	 * @param  boolean $desc
36
+	 * @param  array   $columns
37
+	 * @return collection
38
+	 */
39 39
 	public function all($relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
40 40
 	{
41
-        $sort = $desc ? 'desc' : 'asc';
42
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->get($columns);
41
+		$sort = $desc ? 'desc' : 'asc';
42
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->get($columns);
43 43
 	}
44 44
 
45
-    /**
46
-     * Fetch all records with relations from storage in pages 
47
-     * that matche the given query.
48
-     * 
49
-     * @param  string  $query
50
-     * @param  integer $perPage
51
-     * @param  array   $relations
52
-     * @param  string  $sortBy
53
-     * @param  boolean $desc
54
-     * @param  array   $columns
55
-     * @return collection
56
-     */
57
-    public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
58
-    {
59
-        $model            = call_user_func_array("{$this->getModel()}::with", array($relations));
60
-        $conditionColumns = $this->model->getFillable();
61
-        $sort             = $desc ? 'desc' : 'asc';
45
+	/**
46
+	 * Fetch all records with relations from storage in pages 
47
+	 * that matche the given query.
48
+	 * 
49
+	 * @param  string  $query
50
+	 * @param  integer $perPage
51
+	 * @param  array   $relations
52
+	 * @param  string  $sortBy
53
+	 * @param  boolean $desc
54
+	 * @param  array   $columns
55
+	 * @return collection
56
+	 */
57
+	public function search($query, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
58
+	{
59
+		$model            = call_user_func_array("{$this->getModel()}::with", array($relations));
60
+		$conditionColumns = $this->model->getFillable();
61
+		$sort             = $desc ? 'desc' : 'asc';
62 62
 
63
-        $model->where(function ($q) use ($query, $conditionColumns, $relations){
64
-            $q->where(\DB::raw('LOWER(CAST(' . array_shift($conditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
65
-            foreach ($conditionColumns as $column) 
66
-            {
67
-                $q->orWhere(\DB::raw('LOWER(CAST(' . $column . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
68
-            }
69
-            foreach ($relations as $relation) 
70
-            {
71
-                $relation = explode('.', $relation)[0];
72
-                if (\Core::$relation()) 
73
-                {
74
-                    $q->orWhereHas($relation, function ($subModel) use ($query, $relation){
63
+		$model->where(function ($q) use ($query, $conditionColumns, $relations){
64
+			$q->where(\DB::raw('LOWER(CAST(' . array_shift($conditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
65
+			foreach ($conditionColumns as $column) 
66
+			{
67
+				$q->orWhere(\DB::raw('LOWER(CAST(' . $column . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
68
+			}
69
+			foreach ($relations as $relation) 
70
+			{
71
+				$relation = explode('.', $relation)[0];
72
+				if (\Core::$relation()) 
73
+				{
74
+					$q->orWhereHas($relation, function ($subModel) use ($query, $relation){
75 75
 
76
-                        $subModel->where(function ($q) use ($query, $relation){
76
+						$subModel->where(function ($q) use ($query, $relation){
77 77
 
78
-                            $subConditionColumns = \Core::$relation()->model->getFillable();
79
-                            $q->where(\DB::raw('LOWER(CAST(' . array_shift($subConditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
80
-                            foreach ($subConditionColumns as $subConditionColumn)
81
-                            {
82
-                                $q->orWhere(\DB::raw('LOWER(CAST(' . $subConditionColumn . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
83
-                            } 
84
-                        });
78
+							$subConditionColumns = \Core::$relation()->model->getFillable();
79
+							$q->where(\DB::raw('LOWER(CAST(' . array_shift($subConditionColumns) . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
80
+							foreach ($subConditionColumns as $subConditionColumn)
81
+							{
82
+								$q->orWhere(\DB::raw('LOWER(CAST(' . $subConditionColumn . ' AS TEXT))'), 'LIKE', '%' . strtolower($query) . '%');
83
+							} 
84
+						});
85 85
 
86
-                    });
87
-                }
88
-            }
89
-        });
86
+					});
87
+				}
88
+			}
89
+		});
90 90
         
91
-        return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);
92
-    }
91
+		return $model->orderBy($sortBy, $sort)->paginate($perPage, $columns);
92
+	}
93 93
     
94
-    /**
95
-     * Fetch all records with relations from storage in pages.
96
-     * 
97
-     * @param  integer $perPage
98
-     * @param  array   $relations
99
-     * @param  string  $sortBy
100
-     * @param  boolean $desc
101
-     * @param  array   $columns
102
-     * @return collection
103
-     */
104
-    public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
105
-    {
106
-        $sort = $desc ? 'desc' : 'asc';
107
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->paginate($perPage, $columns);
108
-    }
94
+	/**
95
+	 * Fetch all records with relations from storage in pages.
96
+	 * 
97
+	 * @param  integer $perPage
98
+	 * @param  array   $relations
99
+	 * @param  string  $sortBy
100
+	 * @param  boolean $desc
101
+	 * @param  array   $columns
102
+	 * @return collection
103
+	 */
104
+	public function paginate($perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
105
+	{
106
+		$sort = $desc ? 'desc' : 'asc';
107
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->orderBy($sortBy, $sort)->paginate($perPage, $columns);
108
+	}
109 109
 
110
-    /**
111
-     * Fetch all records with relations based on
112
-     * the given condition from storage in pages.
113
-     * 
114
-     * @param  array   $conditions array of conditions
115
-     * @param  integer $perPage
116
-     * @param  array   $relations
117
-     * @param  string  $sortBy
118
-     * @param  boolean $desc
119
-     * @param  array   $columns
120
-     * @return collection
121
-     */
122
-    public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
123
-    {
124
-        unset($conditions['page']);
125
-        $conditions = $this->constructConditions($conditions);
126
-        $sort       = $desc ? 'desc' : 'asc';
127
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns);
128
-    }
110
+	/**
111
+	 * Fetch all records with relations based on
112
+	 * the given condition from storage in pages.
113
+	 * 
114
+	 * @param  array   $conditions array of conditions
115
+	 * @param  integer $perPage
116
+	 * @param  array   $relations
117
+	 * @param  string  $sortBy
118
+	 * @param  boolean $desc
119
+	 * @param  array   $columns
120
+	 * @return collection
121
+	 */
122
+	public function paginateBy($conditions, $perPage = 15, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
123
+	{
124
+		unset($conditions['page']);
125
+		$conditions = $this->constructConditions($conditions);
126
+		$sort       = $desc ? 'desc' : 'asc';
127
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->paginate($perPage, $columns);
128
+	}
129 129
     
130
-    /**
131
-     * Save the given model to the storage.
132
-     * 
133
-     * @param  array   $data
134
-     * @param  boolean $saveLog
135
-     * @return object
136
-     */
137
-    public function save(array $data, $saveLog = true)
138
-    {
139
-        $model      = false;
140
-        $modelClass = $this->model;
141
-        $relations  = [];
142
-        $with       = [];
130
+	/**
131
+	 * Save the given model to the storage.
132
+	 * 
133
+	 * @param  array   $data
134
+	 * @param  boolean $saveLog
135
+	 * @return object
136
+	 */
137
+	public function save(array $data, $saveLog = true)
138
+	{
139
+		$model      = false;
140
+		$modelClass = $this->model;
141
+		$relations  = [];
142
+		$with       = [];
143 143
 
144
-        \DB::transaction(function () use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) {
145
-            /**
146
-             * If the id is present in the data then select the model for updating,
147
-             * else create new model.
148
-             * @var array
149
-             */
150
-            $model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
151
-            if ( ! $model) 
152
-            {
153
-                \ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']);
154
-            }
144
+		\DB::transaction(function () use (&$model, &$relations, &$with, $data, $saveLog, $modelClass) {
145
+			/**
146
+			 * If the id is present in the data then select the model for updating,
147
+			 * else create new model.
148
+			 * @var array
149
+			 */
150
+			$model = array_key_exists('id', $data) ? $modelClass->lockForUpdate()->find($data['id']) : new $modelClass;
151
+			if ( ! $model) 
152
+			{
153
+				\ErrorHandler::notFound(class_basename($modelClass) . ' with id : ' . $data['id']);
154
+			}
155 155
 
156
-            /**
157
-             * Construct the model object with the given data,
158
-             * and if there is a relation add it to relations array,
159
-             * then save the model.
160
-             */
161
-            foreach ($data as $key => $value) 
162
-            {
163
-                $relation = camel_case($key);
164
-                if (method_exists($model, $relation))
165
-                {
166
-                    $with[] = $relation;
167
-                    if (class_basename($model->$relation) == 'Collection') 
168
-                    {   
169
-                        if ( ! $value || ! count($value)) 
170
-                        {
171
-                            $relations[$relation] = 'delete';
172
-                        }   
173
-                    }
174
-                    if (is_array($value)) 
175
-                    {
176
-                        foreach ($value as $attr => $val) 
177
-                        {
178
-                            $relationBaseModel = \Core::$relation()->model;
179
-                            if (class_basename($model->$relation) == 'Collection')
180
-                            {
181
-                                $relationModel = array_key_exists('id', $val) ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel;
182
-                                if ( ! $relationModel) 
183
-                                {
184
-                                    \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']);
185
-                                }
156
+			/**
157
+			 * Construct the model object with the given data,
158
+			 * and if there is a relation add it to relations array,
159
+			 * then save the model.
160
+			 */
161
+			foreach ($data as $key => $value) 
162
+			{
163
+				$relation = camel_case($key);
164
+				if (method_exists($model, $relation))
165
+				{
166
+					$with[] = $relation;
167
+					if (class_basename($model->$relation) == 'Collection') 
168
+					{   
169
+						if ( ! $value || ! count($value)) 
170
+						{
171
+							$relations[$relation] = 'delete';
172
+						}   
173
+					}
174
+					if (is_array($value)) 
175
+					{
176
+						foreach ($value as $attr => $val) 
177
+						{
178
+							$relationBaseModel = \Core::$relation()->model;
179
+							if (class_basename($model->$relation) == 'Collection')
180
+							{
181
+								$relationModel = array_key_exists('id', $val) ? $relationBaseModel->lockForUpdate()->find($val['id']) : new $relationBaseModel;
182
+								if ( ! $relationModel) 
183
+								{
184
+									\ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $val['id']);
185
+								}
186 186
 
187
-                                foreach ($val as $attr => $val) 
188
-                                {
189
-                                    if (gettype($val) !== 'object' && gettype($val) !== 'array' &&  array_search($attr, $relationModel->getFillable(), true) !== false)
190
-                                    {
191
-                                        $relationModel->$attr = $val;
192
-                                    }
193
-                                }
194
-                                $relations[$relation][] = $relationModel;
195
-                            }
196
-                            else
197
-                            {
198
-                                if (gettype($val) !== 'object' && gettype($val) !== 'array') 
199
-                                {
200
-                                    $relationModel = array_key_exists('id', $value) ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel;
201
-                                    if ( ! $relationModel) 
202
-                                    {
203
-                                        \ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']);
204
-                                    }
187
+								foreach ($val as $attr => $val) 
188
+								{
189
+									if (gettype($val) !== 'object' && gettype($val) !== 'array' &&  array_search($attr, $relationModel->getFillable(), true) !== false)
190
+									{
191
+										$relationModel->$attr = $val;
192
+									}
193
+								}
194
+								$relations[$relation][] = $relationModel;
195
+							}
196
+							else
197
+							{
198
+								if (gettype($val) !== 'object' && gettype($val) !== 'array') 
199
+								{
200
+									$relationModel = array_key_exists('id', $value) ? $relationBaseModel->lockForUpdate()->find($value['id']) : new $relationBaseModel;
201
+									if ( ! $relationModel) 
202
+									{
203
+										\ErrorHandler::notFound(class_basename($relationBaseModel) . ' with id : ' . $value['id']);
204
+									}
205 205
 
206
-                                    if (array_search($attr, $relationModel->getFillable(), true) !== false) 
207
-                                    {
208
-                                        $relationModel->$attr = $val;
209
-                                        $relations[$relation] = $relationModel;
210
-                                    }
211
-                                }
212
-                            }
213
-                        }
214
-                    }
215
-                }
216
-                else if (array_search($key, $model->getFillable(), true) !== false)
217
-                {
218
-                    $model->$key = $value;   
219
-                }
220
-            }
221
-            $model->save();
206
+									if (array_search($attr, $relationModel->getFillable(), true) !== false) 
207
+									{
208
+										$relationModel->$attr = $val;
209
+										$relations[$relation] = $relationModel;
210
+									}
211
+								}
212
+							}
213
+						}
214
+					}
215
+				}
216
+				else if (array_search($key, $model->getFillable(), true) !== false)
217
+				{
218
+					$model->$key = $value;   
219
+				}
220
+			}
221
+			$model->save();
222 222
             
223
-            foreach ($relations as $key => $value) 
224
-            {
225
-                if ($value == 'delete' && $model->$key()->count())
226
-                {
227
-                    $model->$key()->delete();
228
-                }
229
-                else if (gettype($value) == 'array') 
230
-                {
231
-                    $ids = [];
232
-                    foreach ($value as $val) 
233
-                    {
234
-                        switch (class_basename($model->$key())) 
235
-                        {
236
-                            case 'HasMany':
237
-                                $foreignKeyName       = explode('.', $model->$key()->getForeignKey())[1];
238
-                                $val->$foreignKeyName = $model->id;
239
-                                $val->save();
240
-                                $ids[] = $val->id;
241
-                                break;
223
+			foreach ($relations as $key => $value) 
224
+			{
225
+				if ($value == 'delete' && $model->$key()->count())
226
+				{
227
+					$model->$key()->delete();
228
+				}
229
+				else if (gettype($value) == 'array') 
230
+				{
231
+					$ids = [];
232
+					foreach ($value as $val) 
233
+					{
234
+						switch (class_basename($model->$key())) 
235
+						{
236
+							case 'HasMany':
237
+								$foreignKeyName       = explode('.', $model->$key()->getForeignKey())[1];
238
+								$val->$foreignKeyName = $model->id;
239
+								$val->save();
240
+								$ids[] = $val->id;
241
+								break;
242 242
 
243
-                            case 'BelongsToMany':
244
-                                $val->save();
245
-                                $ids[] = $val->id;
246
-                                break;
247
-                        }
248
-                    }
249
-                    switch (class_basename($model->$key())) 
250
-                    {
251
-                        case 'HasMany':
252
-                            $model->$key()->whereNotIn('id', $ids)->delete();
253
-                            break;
243
+							case 'BelongsToMany':
244
+								$val->save();
245
+								$ids[] = $val->id;
246
+								break;
247
+						}
248
+					}
249
+					switch (class_basename($model->$key())) 
250
+					{
251
+						case 'HasMany':
252
+							$model->$key()->whereNotIn('id', $ids)->delete();
253
+							break;
254 254
 
255
-                        case 'BelongsToMany':
256
-                            $model->$key()->detach();
257
-                            $model->$key()->attach($ids);
258
-                            break;
259
-                    }
260
-                }
261
-                else
262
-                {
263
-                    switch (class_basename($model->$key())) 
264
-                    {
265
-                        case 'BelongsTo':
266
-                            $value->save();
267
-                            $model->$key()->associate($value);
268
-                            $model->save();
269
-                            break;
270
-                    }
271
-                }
272
-            }
273
-            $saveLog ? \Logging::saveLog(array_key_exists('id', $data) ? 'update' : 'create', class_basename($modelClass), $this->getModel(), $model->id, $model) : false;
274
-        });
255
+						case 'BelongsToMany':
256
+							$model->$key()->detach();
257
+							$model->$key()->attach($ids);
258
+							break;
259
+					}
260
+				}
261
+				else
262
+				{
263
+					switch (class_basename($model->$key())) 
264
+					{
265
+						case 'BelongsTo':
266
+							$value->save();
267
+							$model->$key()->associate($value);
268
+							$model->save();
269
+							break;
270
+					}
271
+				}
272
+			}
273
+			$saveLog ? \Logging::saveLog(array_key_exists('id', $data) ? 'update' : 'create', class_basename($modelClass), $this->getModel(), $model->id, $model) : false;
274
+		});
275 275
         
276
-        $this->afterSave($model, $relations);
276
+		$this->afterSave($model, $relations);
277 277
 
278
-        return $this->find($model->id, $with);
279
-    }
278
+		return $this->find($model->id, $with);
279
+	}
280 280
 
281
-    /**
282
-     * Save the given models to the storage.
283
-     * 
284
-     * @param  array   $data
285
-     * @return array
286
-     */
287
-    public function saveMany(array $data)
288
-    {
289
-        $result = [];
290
-        \DB::transaction(function () use (&$result, $data) {
291
-            foreach ($data as $key => $value) 
292
-            {
293
-                $result[] = $this->save($value);
294
-            }
295
-        });
296
-        return $result;
297
-    }
281
+	/**
282
+	 * Save the given models to the storage.
283
+	 * 
284
+	 * @param  array   $data
285
+	 * @return array
286
+	 */
287
+	public function saveMany(array $data)
288
+	{
289
+		$result = [];
290
+		\DB::transaction(function () use (&$result, $data) {
291
+			foreach ($data as $key => $value) 
292
+			{
293
+				$result[] = $this->save($value);
294
+			}
295
+		});
296
+		return $result;
297
+	}
298 298
     
299
-    /**
300
-     * Update record in the storage based on the given
301
-     * condition.
302
-     * 
303
-     * @param  var $value condition value
304
-     * @param  array $data
305
-     * @param  string $attribute condition column name
306
-     * @return void
307
-     */
308
-    public function update($value, array $data, $attribute = 'id', $saveLog = true)
309
-    {
310
-        if ($attribute == 'id') 
311
-        {
312
-            $model = $this->model->lockForUpdate()->find($value);
313
-            $model ? $model->update($data) : 0;
314
-            $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $value, $model) : false;
315
-        }
316
-    	call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){
317
-            $model->update($data);
318
-            $saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
319
-        });
320
-    }
299
+	/**
300
+	 * Update record in the storage based on the given
301
+	 * condition.
302
+	 * 
303
+	 * @param  var $value condition value
304
+	 * @param  array $data
305
+	 * @param  string $attribute condition column name
306
+	 * @return void
307
+	 */
308
+	public function update($value, array $data, $attribute = 'id', $saveLog = true)
309
+	{
310
+		if ($attribute == 'id') 
311
+		{
312
+			$model = $this->model->lockForUpdate()->find($value);
313
+			$model ? $model->update($data) : 0;
314
+			$saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $value, $model) : false;
315
+		}
316
+		call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model) use ($data, $saveLog){
317
+			$model->update($data);
318
+			$saveLog ? \Logging::saveLog('update', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
319
+		});
320
+	}
321 321
     
322
-    /**
323
-     * Delete record from the storage based on the given
324
-     * condition.
325
-     * 
326
-     * @param  var $value condition value
327
-     * @param  string $attribute condition column name
328
-     * @return void
329
-     */
330
-    public function delete($value, $attribute = 'id', $saveLog = true)
331
-    {
332
-    	if ($attribute == 'id') 
333
-    	{
334
-            \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
335
-                $model = $this->model->lockForUpdate()->find($value);
336
-                $model->delete();
337
-                $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false;
338
-            });
339
-    	}
340
-        else
341
-        {
342
-            \DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
343
-                call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){
344
-                    $model->delete();
345
-                    $saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
346
-                });
347
-            });   
348
-        }
349
-    }
322
+	/**
323
+	 * Delete record from the storage based on the given
324
+	 * condition.
325
+	 * 
326
+	 * @param  var $value condition value
327
+	 * @param  string $attribute condition column name
328
+	 * @return void
329
+	 */
330
+	public function delete($value, $attribute = 'id', $saveLog = true)
331
+	{
332
+		if ($attribute == 'id') 
333
+		{
334
+			\DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
335
+				$model = $this->model->lockForUpdate()->find($value);
336
+				$model->delete();
337
+				$saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $value, $model) : false;
338
+			});
339
+		}
340
+		else
341
+		{
342
+			\DB::transaction(function () use ($value, $attribute, &$result, $saveLog) {
343
+				call_user_func_array("{$this->getModel()}::where", array($attribute, '=', $value))->lockForUpdate()->get()->each(function ($model){
344
+					$model->delete();
345
+					$saveLog ? \Logging::saveLog('delete', class_basename($this->model), $this->getModel(), $model->id, $model) : false;
346
+				});
347
+			});   
348
+		}
349
+	}
350 350
     
351
-    /**
352
-     * Fetch records from the storage based on the given
353
-     * id.
354
-     * 
355
-     * @param  integer $id
356
-     * @param  array   $relations
357
-     * @param  array   $columns
358
-     * @return object
359
-     */
360
-    public function find($id, $relations = [], $columns = array('*'))
361
-    {
362
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns);
363
-    }
351
+	/**
352
+	 * Fetch records from the storage based on the given
353
+	 * id.
354
+	 * 
355
+	 * @param  integer $id
356
+	 * @param  array   $relations
357
+	 * @param  array   $columns
358
+	 * @return object
359
+	 */
360
+	public function find($id, $relations = [], $columns = array('*'))
361
+	{
362
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns);
363
+	}
364 364
     
365
-    /**
366
-     * Fetch records from the storage based on the given
367
-     * condition.
368
-     * 
369
-     * @param  array   $conditions array of conditions
370
-     * @param  array   $relations
371
-     * @param  string  $sortBy
372
-     * @param  boolean $desc
373
-     * @param  array   $columns
374
-     * @return collection
375
-     */
376
-    public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
377
-    {
378
-        $conditions = $this->constructConditions($conditions);
379
-        $sort       = $desc ? 'desc' : 'asc';
380
-        return call_user_func_array("{$this->getModel()}::with",  array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
381
-    }
365
+	/**
366
+	 * Fetch records from the storage based on the given
367
+	 * condition.
368
+	 * 
369
+	 * @param  array   $conditions array of conditions
370
+	 * @param  array   $relations
371
+	 * @param  string  $sortBy
372
+	 * @param  boolean $desc
373
+	 * @param  array   $columns
374
+	 * @return collection
375
+	 */
376
+	public function findBy($conditions, $relations = [], $sortBy = 'created_at', $desc = 1, $columns = array('*'))
377
+	{
378
+		$conditions = $this->constructConditions($conditions);
379
+		$sort       = $desc ? 'desc' : 'asc';
380
+		return call_user_func_array("{$this->getModel()}::with",  array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->orderBy($sortBy, $sort)->get($columns);
381
+	}
382 382
 
383
-    /**
384
-     * Fetch the first record from the storage based on the given
385
-     * condition.
386
-     *
387
-     * @param  array   $conditions array of conditions
388
-     * @param  array   $relations
389
-     * @param  array   $columns
390
-     * @return object
391
-     */
392
-    public function first($conditions, $relations = [], $columns = array('*'))
393
-    {
394
-        $conditions = $this->constructConditions($conditions);
395
-        return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns);  
396
-    }
383
+	/**
384
+	 * Fetch the first record from the storage based on the given
385
+	 * condition.
386
+	 *
387
+	 * @param  array   $conditions array of conditions
388
+	 * @param  array   $relations
389
+	 * @param  array   $columns
390
+	 * @return object
391
+	 */
392
+	public function first($conditions, $relations = [], $columns = array('*'))
393
+	{
394
+		$conditions = $this->constructConditions($conditions);
395
+		return call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns);  
396
+	}
397 397
 
398
-    /**
399
-     * Build the conditions recursively for the retrieving methods.
400
-     * @param  array $conditions
401
-     * @return array
402
-     */
403
-    protected function constructConditions($conditions)
404
-    {   
405
-        $conditionString = '';
406
-        $conditionValues = [];
407
-        foreach ($conditions as $key => $value) 
408
-        {
409
-            if ($key == 'and') 
410
-            {
411
-                $conditionString  .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} ';
412
-                $conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
413
-            }
414
-            else if ($key == 'or')
415
-            {
416
-                $conditionString  .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} ';
417
-                $conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
418
-            }
419
-            else
420
-            {
421
-                $conditionString  .= $key . '=? {op} ';
422
-                $conditionValues[] = $value;
423
-            }
424
-        }
425
-        $conditionString = '(' . rtrim($conditionString, '{op} ') . ')';
426
-        return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues];
427
-    }
398
+	/**
399
+	 * Build the conditions recursively for the retrieving methods.
400
+	 * @param  array $conditions
401
+	 * @return array
402
+	 */
403
+	protected function constructConditions($conditions)
404
+	{   
405
+		$conditionString = '';
406
+		$conditionValues = [];
407
+		foreach ($conditions as $key => $value) 
408
+		{
409
+			if ($key == 'and') 
410
+			{
411
+				$conditionString  .= str_replace('{op}', 'and', $this->constructConditions($value)['conditionString']) . ' {op} ';
412
+				$conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
413
+			}
414
+			else if ($key == 'or')
415
+			{
416
+				$conditionString  .= str_replace('{op}', 'or', $this->constructConditions($value)['conditionString']) . ' {op} ';
417
+				$conditionValues   = array_merge($conditionValues, $this->constructConditions($value)['conditionValues']);
418
+			}
419
+			else
420
+			{
421
+				$conditionString  .= $key . '=? {op} ';
422
+				$conditionValues[] = $value;
423
+			}
424
+		}
425
+		$conditionString = '(' . rtrim($conditionString, '{op} ') . ')';
426
+		return ['conditionString' => $conditionString, 'conditionValues' => $conditionValues];
427
+	}
428 428
 
429
-    /**
430
-     * Abstract method that is called in after
431
-     * the save method finish.
432
-     * 
433
-     * @param  object  $model
434
-     * @param  array   $relations
435
-     * @return void
436
-     */
437
-    protected function afterSave($model, $relations)
438
-    {
439
-        return false;
440
-    }
429
+	/**
430
+	 * Abstract method that is called in after
431
+	 * the save method finish.
432
+	 * 
433
+	 * @param  object  $model
434
+	 * @param  array   $relations
435
+	 * @return void
436
+	 */
437
+	protected function afterSave($model, $relations)
438
+	{
439
+		return false;
440
+	}
441 441
 
442
-    /**
443
-     * Abstract method that return the necessary 
444
-     * information (full model namespace)
445
-     * needed to preform the previous actions.
446
-     * 
447
-     * @return string
448
-     */
449
-    abstract protected function getModel();
442
+	/**
443
+	 * Abstract method that return the necessary 
444
+	 * information (full model namespace)
445
+	 * needed to preform the previous actions.
446
+	 * 
447
+	 * @return string
448
+	 */
449
+	abstract protected function getModel();
450 450
 }
451 451
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Core/AbstractRepositories/AbstractRepositoryContainer.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -4,34 +4,34 @@
 block discarded – undo
4 4
 
5 5
 abstract class AbstractRepositoryContainer implements RepositoryContainerInterface
6 6
 {
7
-    /**
8
-     * Construct the repository class name based on
9
-     * the method name called, search in the 
10
-     * given namespaces for the class and 
11
-     * return an instance.
12
-     * 
13
-     * @param  string $name the called method name
14
-     * @param  array  $arguments the method arguments
15
-     * @return object
16
-     */
7
+	/**
8
+	 * Construct the repository class name based on
9
+	 * the method name called, search in the 
10
+	 * given namespaces for the class and 
11
+	 * return an instance.
12
+	 * 
13
+	 * @param  string $name the called method name
14
+	 * @param  array  $arguments the method arguments
15
+	 * @return object
16
+	 */
17 17
 	public function __call($name, $arguments)
18
-    {
19
-    	foreach ($this->getRepoNameSpace() as $repoNameSpace) 
20
-    	{
21
-            $class = rtrim($repoNameSpace, '\\') . '\\' . ucfirst(str_singular($name)) . 'Repository';
22
-    		if (class_exists($class)) 
23
-    		{
24
-        		return \App::make($class);
25
-    		}
26
-    	}
27
-    }
18
+	{
19
+		foreach ($this->getRepoNameSpace() as $repoNameSpace) 
20
+		{
21
+			$class = rtrim($repoNameSpace, '\\') . '\\' . ucfirst(str_singular($name)) . 'Repository';
22
+			if (class_exists($class)) 
23
+			{
24
+				return \App::make($class);
25
+			}
26
+		}
27
+	}
28 28
 
29
-     /**
30
-     * Abstract methods that return the necessary 
31
-     * information (repositories namespaces)
32
-     * needed to preform the previous actions.
33
-     * 
34
-     * @return array
35
-     */
36
-    abstract protected function getRepoNameSpace();
29
+	 /**
30
+	  * Abstract methods that return the necessary 
31
+	  * information (repositories namespaces)
32
+	  * needed to preform the previous actions.
33
+	  * 
34
+	  * @return array
35
+	  */
36
+	abstract protected function getRepoNameSpace();
37 37
 }
38 38
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/V1/Core/Http/Controllers/LogsController.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -8,9 +8,9 @@
 block discarded – undo
8 8
 class LogsController 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            = 'logs';
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            = 'logs';
16 16
 }
Please login to merge, or discard this patch.
src/Modules/V1/Core/Http/Controllers/SettingsController.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -8,20 +8,20 @@
 block discarded – undo
8 8
 
9 9
 class SettingsController extends BaseApiController
10 10
 {
11
-    /**
12
-     * The name of the model that is used by the base api controller 
13
-     * to preform actions like (add, edit ... etc).
14
-     * @var string
15
-     */
16
-    protected $model               = 'settings';
11
+	/**
12
+	 * The name of the model that is used by the base api controller 
13
+	 * to preform actions like (add, edit ... etc).
14
+	 * @var string
15
+	 */
16
+	protected $model               = 'settings';
17 17
 
18
-    /**
19
-     * The validations rules used by the base api controller
20
-     * to check before add.
21
-     * @var array
22
-     */
23
-    protected $validationRules  = [
24
-    'name'  => 'required|string|max:100',
25
-    'value' => 'required|string|max:100'
26
-    ];
18
+	/**
19
+	 * The validations rules used by the base api controller
20
+	 * to check before add.
21
+	 * @var array
22
+	 */
23
+	protected $validationRules  = [
24
+	'name'  => 'required|string|max:100',
25
+	'value' => 'required|string|max:100'
26
+	];
27 27
 }
Please login to merge, or discard this patch.
src/Modules/V1/Core/Http/Controllers/BaseApiController.php 1 patch
Indentation   +215 added lines, -215 removed lines patch added patch discarded remove patch
@@ -6,221 +6,221 @@
 block discarded – undo
6 6
 
7 7
 class BaseApiController extends Controller
8 8
 {
9
-    /**
10
-     * The model implementation.
11
-     * 
12
-     * @var model
13
-     */
14
-    protected $model;
15
-
16
-    /**
17
-     * The config implementation.
18
-     * 
19
-     * @var config
20
-     */
21
-    protected $config;
22
-
23
-    public function __construct()
24
-    {
25
-        \Session::set('timeZoneDiff', \Request::header('time-zone-diff') ?: 0);
9
+	/**
10
+	 * The model implementation.
11
+	 * 
12
+	 * @var model
13
+	 */
14
+	protected $model;
15
+
16
+	/**
17
+	 * The config implementation.
18
+	 * 
19
+	 * @var config
20
+	 */
21
+	protected $config;
22
+
23
+	public function __construct()
24
+	{
25
+		\Session::set('timeZoneDiff', \Request::header('time-zone-diff') ?: 0);
26 26
         
27
-        $this->config              = \CoreConfig::getConfig();
28
-        $this->model               = property_exists($this, 'model') ? $this->model : false;
29
-        $this->validationRules     = property_exists($this, 'validationRules') ? $this->validationRules : false;
30
-        $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : [];
31
-        $this->skipLoginCheck      = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : [];
32
-        $this->relations           = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false;
33
-        $route                     = explode('@',\Route::currentRouteAction())[1];
34
-        $this->checkPermission(explode('_', snake_case($route))[1]);
35
-    }
36
-
37
-    /**
38
-     * Fetch all records with relations from model repository.
39
-     * 
40
-     * @param  string  $sortBy
41
-     * @param  boolean $desc
42
-     * @return \Illuminate\Http\Response
43
-     */
44
-    public function getIndex() 
45
-    {
46
-        if ($this->model)
47
-        {
48
-            $relations = $this->relations && $this->relations['all'] ? $this->relations['all'] : [];
49
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->all($relations), 200);
50
-        }
51
-    }
52
-
53
-    /**
54
-     * Fetch the single object with relations from model repository.
55
-     * 
56
-     * @param  integer $id
57
-     * @return \Illuminate\Http\Response
58
-     */
59
-    public function getFind($id) 
60
-    {
61
-        if ($this->model) 
62
-        {
63
-            $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : [];
64
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find($id, $relations), 200);
65
-        }
66
-    }
67
-
68
-    /**
69
-     * Paginate all records with relations from model repository
70
-     * that matche the given query.
71
-     * 
72
-     * @param  string  $query
73
-     * @param  integer $perPage
74
-     * @param  string  $sortBy
75
-     * @param  boolean $desc
76
-     * @return \Illuminate\Http\Response
77
-     */
78
-    public function getSearch($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) 
79
-    {
80
-        if ($this->model) 
81
-        {
82
-            $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : [];
83
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->search($query, $perPage, $relations, $sortBy, $desc), 200);
84
-        }
85
-    }
86
-
87
-    /**
88
-     * Fetch records from the storage based on the given
89
-     * condition.
90
-     * 
91
-     * @param  \Illuminate\Http\Request  $request
92
-     * @param  string  $sortBy
93
-     * @param  boolean $desc
94
-     * @return \Illuminate\Http\Response
95
-     */
96
-    public function postFindby(Request $request, $sortBy = 'created_at', $desc = 1) 
97
-    {
98
-        if ($this->model) 
99
-        {
100
-            $relations = $this->relations && $this->relations['findBy'] ? $this->relations['findBy'] : [];
101
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->findBy($request->all(), $relations, $sortBy, $desc), 200);
102
-        }
103
-    }
104
-
105
-    /**
106
-     * Fetch the first record from the storage based on the given
107
-     * condition.
108
-     * 
109
-     * @param  \Illuminate\Http\Request  $request
110
-     * @return \Illuminate\Http\Response
111
-     */
112
-    public function postFirst(Request $request) 
113
-    {
114
-        if ($this->model) 
115
-        {
116
-            $relations = $this->relations && $this->relations['first'] ? $this->relations['first'] : [];
117
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->first($request->all(), $relations), 200);
118
-        }
119
-    }
120
-
121
-    /**
122
-     * Paginate all records with relations from model repository.
123
-     * 
124
-     * @param  integer $perPage
125
-     * @param  string  $sortBy
126
-     * @param  boolean $desc
127
-     * @return \Illuminate\Http\Response
128
-     */
129
-    public function getPaginate($perPage = 15, $sortBy = 'created_at', $desc = 1) 
130
-    {
131
-        if ($this->model) 
132
-        {
133
-            $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : [];
134
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginate($perPage, $relations, $sortBy, $desc), 200);
135
-        }
136
-    }
137
-
138
-    /**
139
-     * Fetch all records with relations based on
140
-     * the given condition from storage in pages.
141
-     * 
142
-     * @param  \Illuminate\Http\Request  $request
143
-     * @param  integer $perPage
144
-     * @param  string  $sortBy
145
-     * @param  boolean $desc
146
-     * @return \Illuminate\Http\Response
147
-     */
148
-    public function postPaginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
149
-    {
150
-        if ($this->model) 
151
-        {
152
-            $relations = $this->relations && $this->relations['paginateBy'] ? $this->relations['paginateBy'] : [];
153
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginateBy($request->all(), $perPage, $relations, $sortBy, $desc), 200);
154
-        }
155
-    }
156
-
157
-    /**
158
-     * Save the given model to repository.
159
-     * 
160
-     * @param  \Illuminate\Http\Request  $request
161
-     * @return \Illuminate\Http\Response
162
-     */
163
-    public function postSave(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
-
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
-        }
27
+		$this->config              = \CoreConfig::getConfig();
28
+		$this->model               = property_exists($this, 'model') ? $this->model : false;
29
+		$this->validationRules     = property_exists($this, 'validationRules') ? $this->validationRules : false;
30
+		$this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : [];
31
+		$this->skipLoginCheck      = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : [];
32
+		$this->relations           = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false;
33
+		$route                     = explode('@',\Route::currentRouteAction())[1];
34
+		$this->checkPermission(explode('_', snake_case($route))[1]);
35
+	}
36
+
37
+	/**
38
+	 * Fetch all records with relations from model repository.
39
+	 * 
40
+	 * @param  string  $sortBy
41
+	 * @param  boolean $desc
42
+	 * @return \Illuminate\Http\Response
43
+	 */
44
+	public function getIndex() 
45
+	{
46
+		if ($this->model)
47
+		{
48
+			$relations = $this->relations && $this->relations['all'] ? $this->relations['all'] : [];
49
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->all($relations), 200);
50
+		}
51
+	}
52
+
53
+	/**
54
+	 * Fetch the single object with relations from model repository.
55
+	 * 
56
+	 * @param  integer $id
57
+	 * @return \Illuminate\Http\Response
58
+	 */
59
+	public function getFind($id) 
60
+	{
61
+		if ($this->model) 
62
+		{
63
+			$relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : [];
64
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find($id, $relations), 200);
65
+		}
66
+	}
67
+
68
+	/**
69
+	 * Paginate all records with relations from model repository
70
+	 * that matche the given query.
71
+	 * 
72
+	 * @param  string  $query
73
+	 * @param  integer $perPage
74
+	 * @param  string  $sortBy
75
+	 * @param  boolean $desc
76
+	 * @return \Illuminate\Http\Response
77
+	 */
78
+	public function getSearch($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) 
79
+	{
80
+		if ($this->model) 
81
+		{
82
+			$relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : [];
83
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->search($query, $perPage, $relations, $sortBy, $desc), 200);
84
+		}
85
+	}
86
+
87
+	/**
88
+	 * Fetch records from the storage based on the given
89
+	 * condition.
90
+	 * 
91
+	 * @param  \Illuminate\Http\Request  $request
92
+	 * @param  string  $sortBy
93
+	 * @param  boolean $desc
94
+	 * @return \Illuminate\Http\Response
95
+	 */
96
+	public function postFindby(Request $request, $sortBy = 'created_at', $desc = 1) 
97
+	{
98
+		if ($this->model) 
99
+		{
100
+			$relations = $this->relations && $this->relations['findBy'] ? $this->relations['findBy'] : [];
101
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->findBy($request->all(), $relations, $sortBy, $desc), 200);
102
+		}
103
+	}
104
+
105
+	/**
106
+	 * Fetch the first record from the storage based on the given
107
+	 * condition.
108
+	 * 
109
+	 * @param  \Illuminate\Http\Request  $request
110
+	 * @return \Illuminate\Http\Response
111
+	 */
112
+	public function postFirst(Request $request) 
113
+	{
114
+		if ($this->model) 
115
+		{
116
+			$relations = $this->relations && $this->relations['first'] ? $this->relations['first'] : [];
117
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->first($request->all(), $relations), 200);
118
+		}
119
+	}
120
+
121
+	/**
122
+	 * Paginate all records with relations from model repository.
123
+	 * 
124
+	 * @param  integer $perPage
125
+	 * @param  string  $sortBy
126
+	 * @param  boolean $desc
127
+	 * @return \Illuminate\Http\Response
128
+	 */
129
+	public function getPaginate($perPage = 15, $sortBy = 'created_at', $desc = 1) 
130
+	{
131
+		if ($this->model) 
132
+		{
133
+			$relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : [];
134
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginate($perPage, $relations, $sortBy, $desc), 200);
135
+		}
136
+	}
137
+
138
+	/**
139
+	 * Fetch all records with relations based on
140
+	 * the given condition from storage in pages.
141
+	 * 
142
+	 * @param  \Illuminate\Http\Request  $request
143
+	 * @param  integer $perPage
144
+	 * @param  string  $sortBy
145
+	 * @param  boolean $desc
146
+	 * @return \Illuminate\Http\Response
147
+	 */
148
+	public function postPaginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
149
+	{
150
+		if ($this->model) 
151
+		{
152
+			$relations = $this->relations && $this->relations['paginateBy'] ? $this->relations['paginateBy'] : [];
153
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginateBy($request->all(), $perPage, $relations, $sortBy, $desc), 200);
154
+		}
155
+	}
156
+
157
+	/**
158
+	 * Save the given model to repository.
159
+	 * 
160
+	 * @param  \Illuminate\Http\Request  $request
161
+	 * @return \Illuminate\Http\Response
162
+	 */
163
+	public function postSave(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
+
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);
183
-
184
-        if ($this->model) 
185
-        {
186
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->save($request->all()), 200);
187
-        }
188
-    }
189
-
190
-    /**
191
-     * Delete by the given id from model repository.
192
-     * 
193
-     * @param  integer  $id
194
-     * @return \Illuminate\Http\Response
195
-     */
196
-    public function getDelete($id) 
197
-    {
198
-        if ($this->model) 
199
-        {
200
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->delete($id), 200);
201
-        }
202
-    }
203
-
204
-    /**
205
-     * Check if the logged in user can do the given permission.
206
-     * 
207
-     * @param  string $permission
208
-     * @return void
209
-     */
210
-    private function checkPermission($permission)
211
-    {
212
-        $permission = $permission !== 'index' ? $permission : 'list';
213
-        if ($permission == 'method') 
214
-        {
215
-            \ErrorHandler::notFound('method');
216
-        }
217
-        else if ( ! in_array($permission, $this->skipLoginCheck)) 
218
-        {
219
-            \JWTAuth::parseToken()->authenticate();
220
-            if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model))
221
-            {
222
-                \ErrorHandler::noPermissions();
223
-            }
224
-        }
225
-    }
182
+		$this->validate($request, $this->validationRules);
183
+
184
+		if ($this->model) 
185
+		{
186
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->save($request->all()), 200);
187
+		}
188
+	}
189
+
190
+	/**
191
+	 * Delete by the given id from model repository.
192
+	 * 
193
+	 * @param  integer  $id
194
+	 * @return \Illuminate\Http\Response
195
+	 */
196
+	public function getDelete($id) 
197
+	{
198
+		if ($this->model) 
199
+		{
200
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->delete($id), 200);
201
+		}
202
+	}
203
+
204
+	/**
205
+	 * Check if the logged in user can do the given permission.
206
+	 * 
207
+	 * @param  string $permission
208
+	 * @return void
209
+	 */
210
+	private function checkPermission($permission)
211
+	{
212
+		$permission = $permission !== 'index' ? $permission : 'list';
213
+		if ($permission == 'method') 
214
+		{
215
+			\ErrorHandler::notFound('method');
216
+		}
217
+		else if ( ! in_array($permission, $this->skipLoginCheck)) 
218
+		{
219
+			\JWTAuth::parseToken()->authenticate();
220
+			if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model))
221
+			{
222
+				\ErrorHandler::noPermissions();
223
+			}
224
+		}
225
+	}
226 226
 }
Please login to merge, or discard this patch.
V1/Reporting/Database/Migrations/2016_01_19_112603_sampel_report.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -22,15 +22,15 @@
 block discarded – undo
22 22
 			");
23 23
 		
24 24
 		DB::table('reports')->insert(
25
-        	[
26
-	        	[
25
+			[
26
+				[
27 27
 				'report_name' => 'admin_count',
28 28
 				'view_name'   => 'admin_count',
29 29
 				'created_at'  => \DB::raw('NOW()'),
30 30
 				'updated_at'  => \DB::raw('NOW()')
31
-	        	]
32
-        	]
33
-        );
31
+				]
32
+			]
33
+		);
34 34
 	}
35 35
 
36 36
 	/**
Please login to merge, or discard this patch.
src/Modules/V1/Reporting/Database/Migrations/2016_01_19_112350_reports.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
 			$table->string('view_name',100);
19 19
 			$table->softDeletes();
20 20
 			$table->timestamps();
21
-        });
21
+		});
22 22
 	}
23 23
 
24 24
 	/**
Please login to merge, or discard this patch.
Modules/V1/Reporting/Database/Migrations/2016_01_24_123631_initialize.php 1 patch
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -12,71 +12,71 @@
 block discarded – undo
12 12
 	 */
13 13
 	public function up()
14 14
 	{
15
-        /**
16
-         * Delete previous permissions.
17
-         */
15
+		/**
16
+		 * Delete previous permissions.
17
+		 */
18 18
 		DB::table('permissions')->whereIn('model', ['reports'])->delete();
19 19
 
20 20
 		/**
21
-         * Insert the permissions related to this module.
22
-         */
23
-        DB::table('permissions')->insert(
24
-        	[
25
-        		/**
26
-        		 * Reporting model permissions.
27
-        		 */
28
-	        	[
29
-	        	'name'       => 'find',
30
-	        	'model'      => 'reports',
31
-	        	'created_at' => \DB::raw('NOW()'),
32
-	        	'updated_at' => \DB::raw('NOW()')
33
-	        	],
34
-	        	[
35
-	        	'name'       => 'search',
36
-	        	'model'      => 'reports',
37
-	        	'created_at' => \DB::raw('NOW()'),
38
-	        	'updated_at' => \DB::raw('NOW()')
39
-	        	],
40
-	        	[
41
-	        	'name'       => 'list',
42
-	        	'model'      => 'reports',
43
-	        	'created_at' => \DB::raw('NOW()'),
44
-	        	'updated_at' => \DB::raw('NOW()')
45
-	        	],
46
-	        	[
47
-	        	'name'       => 'findby',
48
-	        	'model'      => 'reports',
49
-	        	'created_at' => \DB::raw('NOW()'),
50
-	        	'updated_at' => \DB::raw('NOW()')
51
-	        	],
52
-	        	[
53
-	        	'name'       => 'first',
54
-	        	'model'      => 'reports',
55
-	        	'created_at' => \DB::raw('NOW()'),
56
-	        	'updated_at' => \DB::raw('NOW()')
57
-	        	],
58
-	        	[
59
-	        	'name'       => 'paginate',
60
-	        	'model'      => 'reports',
61
-	        	'created_at' => \DB::raw('NOW()'),
62
-	        	'updated_at' => \DB::raw('NOW()')
63
-	        	],
64
-	        	[
65
-	        	'name'       => 'paginateby',
66
-	        	'model'      => 'reports',
67
-	        	'created_at' => \DB::raw('NOW()'),
68
-	        	'updated_at' => \DB::raw('NOW()')
69
-	        	],
70
-	        	[
71
-	        	'name'       => 'admin_count',
72
-	        	'model'      => 'reports',
73
-	        	'created_at' => \DB::raw('NOW()'),
74
-	        	'updated_at' => \DB::raw('NOW()')
75
-	        	]
76
-        	]
77
-        );
21
+		 * Insert the permissions related to this module.
22
+		 */
23
+		DB::table('permissions')->insert(
24
+			[
25
+				/**
26
+				 * Reporting model permissions.
27
+				 */
28
+				[
29
+				'name'       => 'find',
30
+				'model'      => 'reports',
31
+				'created_at' => \DB::raw('NOW()'),
32
+				'updated_at' => \DB::raw('NOW()')
33
+				],
34
+				[
35
+				'name'       => 'search',
36
+				'model'      => 'reports',
37
+				'created_at' => \DB::raw('NOW()'),
38
+				'updated_at' => \DB::raw('NOW()')
39
+				],
40
+				[
41
+				'name'       => 'list',
42
+				'model'      => 'reports',
43
+				'created_at' => \DB::raw('NOW()'),
44
+				'updated_at' => \DB::raw('NOW()')
45
+				],
46
+				[
47
+				'name'       => 'findby',
48
+				'model'      => 'reports',
49
+				'created_at' => \DB::raw('NOW()'),
50
+				'updated_at' => \DB::raw('NOW()')
51
+				],
52
+				[
53
+				'name'       => 'first',
54
+				'model'      => 'reports',
55
+				'created_at' => \DB::raw('NOW()'),
56
+				'updated_at' => \DB::raw('NOW()')
57
+				],
58
+				[
59
+				'name'       => 'paginate',
60
+				'model'      => 'reports',
61
+				'created_at' => \DB::raw('NOW()'),
62
+				'updated_at' => \DB::raw('NOW()')
63
+				],
64
+				[
65
+				'name'       => 'paginateby',
66
+				'model'      => 'reports',
67
+				'created_at' => \DB::raw('NOW()'),
68
+				'updated_at' => \DB::raw('NOW()')
69
+				],
70
+				[
71
+				'name'       => 'admin_count',
72
+				'model'      => 'reports',
73
+				'created_at' => \DB::raw('NOW()'),
74
+				'updated_at' => \DB::raw('NOW()')
75
+				]
76
+			]
77
+		);
78 78
 
79
-        /**
79
+		/**
80 80
 		 * Assign the permissions to the admin group.
81 81
 		 */
82 82
 		$permissionIds = DB::table('permissions')->whereIn('model', ['reports'])->select('id')->lists('id');
Please login to merge, or discard this patch.