Skip to content

Commit 5682573

Browse files
authored
Merge pull request #394 from RezaAb/master
some changes for preparing next release
2 parents 3569fe7 + 67fbe33 commit 5682573

File tree

7 files changed

+168
-17
lines changed

7 files changed

+168
-17
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@
22
composer.phar
33
composer.lock
44
.DS_Store
5-
/nbproject/private/
5+
/nbproject/private/
6+
/.vs
7+
/.idea

src/Serverfireteam/Panel/stubs/panelController.stub

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class DummyClass extends CrudController{
1313
public function all($entity){
1414
parent::all($entity);
1515

16-
/** Simple code of filter and grid part , List of all fields here : http://laravelpanel.com/docs/master/crud-fields
16+
/** Simple code of filter and grid part , List of all fields here : https://github.com/serverfireteam/panel/wiki/CRUD-Fields
1717

1818

1919
$this->filter = \DataFilter::source(new \App\Category);
@@ -36,7 +36,7 @@ class DummyClass extends CrudController{
3636

3737
parent::edit($entity);
3838

39-
/* Simple code of edit part , List of all fields here : http://laravelpanel.com/docs/master/crud-fields
39+
/* Simple code of edit part , List of all fields here : https://github.com/serverfireteam/panel/wiki/CRUD-Fields
4040

4141
$this->edit = \DataEdit::source(new \App\Category());
4242

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class EditAdminTable extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('admins', function($table) {
17+
$table->json('extradata');
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('admins', function($table) {
29+
$table->dropColumn('extradata');
30+
});
31+
}
32+
}

src/models/Admin.php

Lines changed: 104 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,113 @@ public function getRememberToken(){
4242
}
4343

4444
public function setRememberToken($value){
45-
$this->remember_token = $value;
46-
}
45+
$this->remember_token = $value;
46+
}
47+
48+
public function getReminderEmail(){
49+
$email = Input::only('email');
50+
return $email['email'];
51+
}
4752

48-
public function getReminderEmail(){
49-
$email = Input::only('email');
50-
return $email['email'];
51-
}
5253

54+
public function getRememberTokenName(){
55+
return $this->remember_token_name;
56+
}
57+
58+
59+
/**
60+
* To get all Admins that has $key and $value on extradata field
61+
* @param $key
62+
* @param $value
63+
* @return mixed
64+
*/
65+
public function getAllExtraData($key, $value){
66+
//defined by local scope
67+
return Admin::getExtraData($key, $value)->get();
68+
//return Admin::where('extradata->' + $key, $value)->get();
69+
//JSON_CONTAINS() function accepts the JSON field being searched and another to compare against.
70+
// It returns 1 when a match is found, e.g.
71+
//return Admin::whereRaw('JSON_CONTAINS(extradata->"$.' + $key + '", \'["' + $value + '"]\')')->get();
72+
}
5373

54-
public function getRememberTokenName(){
55-
return $this->remember_token_name;
56-
}
74+
/**
75+
* Get all the Admins who has $query in $key on extradata field
76+
* @param $key
77+
* @param $query
78+
* @return mixed
79+
*/
80+
public function getSearchInExtraData($key, $query){
81+
//defined by local scope
82+
return Admin::searchInExtraData($key, $query)->get();
83+
//return Admin::where('extradata->' + $key, 'like', '%'+ $query + '%')->get();
84+
//JSON_SEARCH() function returns the path to the given match or NULL when there’s no match.
85+
// It is passed the JSON document being searched, 'one' to find the first match or 'all' to find all matches, and a search string, e.g.
86+
//return Admin::whereRaw('JSON_SEARCH(extradata->"$.' + $key + '", "one", "%'+ $query + '%") IS NOT NULL')->get();
87+
}
88+
89+
/**
90+
* add or update admin's picture.
91+
* @param $pic_base64_encoded
92+
*/
93+
public function updateAdminPicture($pic_base64_encoded){
94+
//use forceFill() which will bypass the mass assignment check to perform update on any JSON path,
95+
// if path is not there, it will be created and if it’s present it will be updated accordingly.
96+
$this->forceFill(['extradata->picture' => $pic_base64_encoded]);
97+
98+
# Save the changes
99+
$this->update();
100+
}
101+
102+
/**
103+
* find admin by primary key id
104+
* @param $admin_id
105+
* @return mixed
106+
*/
107+
public function findById($admin_id){
108+
// Retrieve a model by its primary key...
109+
$admin = Admin::find($admin_id);
110+
// Retrieve the first model matching the query constraints...
111+
//$admin = Admin::where('id', $admin_id)->first();
112+
return $admin;
113+
}
114+
115+
/**
116+
* Scope a query to get admin by id.
117+
* @param $query
118+
* @param $admin_id
119+
* @return mixed
120+
*/
121+
public function scopeFindById($query, $admin_id){
122+
return $query->where('id', $admin_id);
123+
}
124+
125+
/**
126+
* Scope a query to get admin by a $key and $value in extradata.
127+
* @param $query
128+
* @param $key
129+
* @param $value
130+
* @return mixed
131+
*/
132+
public function scopeGetExtraData($query, $key, $value){
133+
//JSON_CONTAINS() function accepts the JSON field being searched and another to compare against.
134+
// It returns 1 when a match is found, e.g.
135+
return $query->whereRaw('JSON_CONTAINS(extradata->"$.' + $key + '", \'["' + $value + '"]\')');
136+
//return $query->where('extradata->' + $key, $value);
137+
}
138+
139+
/**
140+
* Scope a query to get admin by a $key and search in $value.
141+
* @param $query
142+
* @param $key
143+
* @param $query_value
144+
* @return mixed
145+
*/
146+
public function scopeSearchInExtraData($query, $key, $query_value){
147+
//JSON_SEARCH() function returns the path to the given match or NULL when there’s no match.
148+
// It is passed the JSON document being searched, 'one' to find the first match or 'all' to find all matches, and a search string, e.g.
149+
return $query->whereRaw('JSON_SEARCH(extradata->"$.' + $key + '", "one", "%'+ $query_value + '%") IS NOT NULL');
150+
//return $query->where('extradata->' + $key, 'like', '%'+ $query_value + '%');
151+
}
57152

58153

59154
protected $fillable = array('first_name', 'last_name', 'email', 'password');

src/models/Link.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static function getAllLinks($forceRefresh = false) // allCached(
2020
public static function getUrls($forceRefresh = false) // returnUrls(
2121
{
2222
if (!isset(self::$cache['all_urls']) || $forceRefresh) {
23-
$configs = Link::allCached($forceRefresh);
23+
$configs = Link::getAllLinks($forceRefresh);
2424
self::$cache['all_urls'] = $configs->pluck('url')->toArray();
2525
}
2626
return self::$cache['all_urls'];
@@ -33,11 +33,33 @@ public static function getMainUrls($forceRefresh = false)
3333
}
3434
return self::$cache['main_urls'];
3535
}
36-
public function addNewLink($url, $label, $visibility) // getAndSave(
36+
public function addNewLink($url, $label, $visibility, $checkExistence = false) // getAndSave(
3737
{
38+
if ($checkExistence && $this->isLinkExist($url, $label))
39+
{
40+
return;
41+
}
3842
$this->url = $url;
3943
$this->display = $label;
4044
$this->show_menu = $visibility;
4145
$this->save();
4246
}
47+
48+
/**
49+
* check given url and display label if they added before
50+
* @param $url
51+
* @param $label
52+
* @return bool
53+
*/
54+
public function isLinkExist($url, $label)
55+
{
56+
//if you call exists() against a non existent record then it gives error: Call to a member function exists() on null
57+
//Link::where('url', '=', $url)->exists()
58+
$linkCount = Link::where('url', '=', $url)->where('display', '=', $label)->count(); //->first(); if ($link === null)
59+
if ($linkCount <= 0) {
60+
// link doesn't exist
61+
return false;
62+
}
63+
return true;
64+
}
4365
}

src/views/dashboard.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
</div>
4343
<div class="row hide update">
4444
<div class="alert alert-warning" role="alert">
45-
<a href="http://laravelpanel.com/docs/master/update" class="alert-link"></a>
45+
<a href="https://github.com/serverfireteam/panel/wiki/Update" class="alert-link"></a>
4646
</div>
4747
</div>
4848

src/views/mainTemplate.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
<div class="navbar-default sidebar " role="navigation">
3939
<div class="sidebar-nav navbar-collapse collapse " id="bs-example-navbar-collapse-1">
40-
<div class="grav center"><img src="//www.gravatar.com/avatar/{{ md5( strtolower( trim( Auth::guard('panel')->user()->email ) ) )}}?d=mm&s=128" ><a href="https://www.gravatar.com"><span> {{ \Lang::get('panel::fields.change') }}</span></a></div>
40+
<div class="grav center"><img src="//www.gravatar.com/avatar/{{ md5( strtolower( trim( Auth::guard('panel')->user()->email ) ) )}}?d=mm&s=128" ><a href="{{url('panel/edit')}}"><span> {{ \Lang::get('panel::fields.change') }}</span></a></div>
4141
<div class="user-info">{{Auth::guard('panel')->user()->first_name.' '.Auth::guard('panel')->user()->last_name}}</div>
4242
<a class="visit-site" href="{{$app['url']->to('/')}}">{{ \Lang::get('panel::fields.visiteSite') }} </a>
4343
<ul class="nav" id="side-menu">
@@ -71,7 +71,7 @@
7171
</div>
7272
<!-- /.navbar-static-side -->
7373
</nav>
74-
<div class="powered-by"><a href="http://laravelpanel.com">{{ \Lang::get('panel::fields.thankYouNote') }}</a></div>
74+
<div class="powered-by"><a href="https://github.com/serverfireteam/panel">{{ \Lang::get('panel::fields.thankYouNote') }}</a></div>
7575
<div id="page-wrapper">
7676

7777

0 commit comments

Comments
 (0)