Skip to content

Commit

Permalink
Merge pull request #394 from RezaAb/master
Browse files Browse the repository at this point in the history
some changes for preparing next release
  • Loading branch information
AlirezaAlgo authored Jun 9, 2019
2 parents 3569fe7 + 67fbe33 commit 5682573
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 17 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
composer.phar
composer.lock
.DS_Store
/nbproject/private/
/nbproject/private/
/.vs
/.idea
4 changes: 2 additions & 2 deletions src/Serverfireteam/Panel/stubs/panelController.stub
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class DummyClass extends CrudController{
public function all($entity){
parent::all($entity);

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


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

parent::edit($entity);

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

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

Expand Down
32 changes: 32 additions & 0 deletions src/database/migrations/2019_06_04_092344_edit_admin_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class EditAdminTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('admins', function($table) {
$table->json('extradata');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('admins', function($table) {
$table->dropColumn('extradata');
});
}
}
113 changes: 104 additions & 9 deletions src/models/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,113 @@ public function getRememberToken(){
}

public function setRememberToken($value){
$this->remember_token = $value;
}
$this->remember_token = $value;
}

public function getReminderEmail(){
$email = Input::only('email');
return $email['email'];
}

public function getReminderEmail(){
$email = Input::only('email');
return $email['email'];
}

public function getRememberTokenName(){
return $this->remember_token_name;
}


/**
* To get all Admins that has $key and $value on extradata field
* @param $key
* @param $value
* @return mixed
*/
public function getAllExtraData($key, $value){
//defined by local scope
return Admin::getExtraData($key, $value)->get();
//return Admin::where('extradata->' + $key, $value)->get();
//JSON_CONTAINS() function accepts the JSON field being searched and another to compare against.
// It returns 1 when a match is found, e.g.
//return Admin::whereRaw('JSON_CONTAINS(extradata->"$.' + $key + '", \'["' + $value + '"]\')')->get();
}

public function getRememberTokenName(){
return $this->remember_token_name;
}
/**
* Get all the Admins who has $query in $key on extradata field
* @param $key
* @param $query
* @return mixed
*/
public function getSearchInExtraData($key, $query){
//defined by local scope
return Admin::searchInExtraData($key, $query)->get();
//return Admin::where('extradata->' + $key, 'like', '%'+ $query + '%')->get();
//JSON_SEARCH() function returns the path to the given match or NULL when there’s no match.
// 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.
//return Admin::whereRaw('JSON_SEARCH(extradata->"$.' + $key + '", "one", "%'+ $query + '%") IS NOT NULL')->get();
}

/**
* add or update admin's picture.
* @param $pic_base64_encoded
*/
public function updateAdminPicture($pic_base64_encoded){
//use forceFill() which will bypass the mass assignment check to perform update on any JSON path,
// if path is not there, it will be created and if it’s present it will be updated accordingly.
$this->forceFill(['extradata->picture' => $pic_base64_encoded]);

# Save the changes
$this->update();
}

/**
* find admin by primary key id
* @param $admin_id
* @return mixed
*/
public function findById($admin_id){
// Retrieve a model by its primary key...
$admin = Admin::find($admin_id);
// Retrieve the first model matching the query constraints...
//$admin = Admin::where('id', $admin_id)->first();
return $admin;
}

/**
* Scope a query to get admin by id.
* @param $query
* @param $admin_id
* @return mixed
*/
public function scopeFindById($query, $admin_id){
return $query->where('id', $admin_id);
}

/**
* Scope a query to get admin by a $key and $value in extradata.
* @param $query
* @param $key
* @param $value
* @return mixed
*/
public function scopeGetExtraData($query, $key, $value){
//JSON_CONTAINS() function accepts the JSON field being searched and another to compare against.
// It returns 1 when a match is found, e.g.
return $query->whereRaw('JSON_CONTAINS(extradata->"$.' + $key + '", \'["' + $value + '"]\')');
//return $query->where('extradata->' + $key, $value);
}

/**
* Scope a query to get admin by a $key and search in $value.
* @param $query
* @param $key
* @param $query_value
* @return mixed
*/
public function scopeSearchInExtraData($query, $key, $query_value){
//JSON_SEARCH() function returns the path to the given match or NULL when there’s no match.
// 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.
return $query->whereRaw('JSON_SEARCH(extradata->"$.' + $key + '", "one", "%'+ $query_value + '%") IS NOT NULL');
//return $query->where('extradata->' + $key, 'like', '%'+ $query_value + '%');
}


protected $fillable = array('first_name', 'last_name', 'email', 'password');
Expand Down
26 changes: 24 additions & 2 deletions src/models/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function getAllLinks($forceRefresh = false) // allCached(
public static function getUrls($forceRefresh = false) // returnUrls(
{
if (!isset(self::$cache['all_urls']) || $forceRefresh) {
$configs = Link::allCached($forceRefresh);
$configs = Link::getAllLinks($forceRefresh);
self::$cache['all_urls'] = $configs->pluck('url')->toArray();
}
return self::$cache['all_urls'];
Expand All @@ -33,11 +33,33 @@ public static function getMainUrls($forceRefresh = false)
}
return self::$cache['main_urls'];
}
public function addNewLink($url, $label, $visibility) // getAndSave(
public function addNewLink($url, $label, $visibility, $checkExistence = false) // getAndSave(
{
if ($checkExistence && $this->isLinkExist($url, $label))
{
return;
}
$this->url = $url;
$this->display = $label;
$this->show_menu = $visibility;
$this->save();
}

/**
* check given url and display label if they added before
* @param $url
* @param $label
* @return bool
*/
public function isLinkExist($url, $label)
{
//if you call exists() against a non existent record then it gives error: Call to a member function exists() on null
//Link::where('url', '=', $url)->exists()
$linkCount = Link::where('url', '=', $url)->where('display', '=', $label)->count(); //->first(); if ($link === null)
if ($linkCount <= 0) {
// link doesn't exist
return false;
}
return true;
}
}
2 changes: 1 addition & 1 deletion src/views/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</div>
<div class="row hide update">
<div class="alert alert-warning" role="alert">
<a href="http://laravelpanel.com/docs/master/update" class="alert-link"></a>
<a href="https://github.com/serverfireteam/panel/wiki/Update" class="alert-link"></a>
</div>
</div>

Expand Down
4 changes: 2 additions & 2 deletions src/views/mainTemplate.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

<div class="navbar-default sidebar " role="navigation">
<div class="sidebar-nav navbar-collapse collapse " id="bs-example-navbar-collapse-1">
<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>
<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>
<div class="user-info">{{Auth::guard('panel')->user()->first_name.' '.Auth::guard('panel')->user()->last_name}}</div>
<a class="visit-site" href="{{$app['url']->to('/')}}">{{ \Lang::get('panel::fields.visiteSite') }} </a>
<ul class="nav" id="side-menu">
Expand Down Expand Up @@ -71,7 +71,7 @@
</div>
<!-- /.navbar-static-side -->
</nav>
<div class="powered-by"><a href="http://laravelpanel.com">{{ \Lang::get('panel::fields.thankYouNote') }}</a></div>
<div class="powered-by"><a href="https://github.com/serverfireteam/panel">{{ \Lang::get('panel::fields.thankYouNote') }}</a></div>
<div id="page-wrapper">


Expand Down

0 comments on commit 5682573

Please sign in to comment.