commit
0f93ac18ca
@ -1,52 +1,52 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Fuel\Core\Controller_Rest;
|
use Fuel\Core\Controller_Rest;
|
||||||
use Fuel\Core\FuelException;
|
use Fuel\Core\FuelException;
|
||||||
use Fuel\Core\Input;
|
use Fuel\Core\Input;
|
||||||
|
|
||||||
class Controller_Rest_Library extends Controller_Rest
|
class Controller_Rest_Library extends Controller_Rest
|
||||||
{
|
{
|
||||||
public function post_permission()
|
public function post_permission()
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$library_id = Input::post('library_id');
|
$library_id = Input::post('library_id');
|
||||||
$right_name = Input::post('right_name');
|
$right_name = Input::post('right_name');
|
||||||
$checked = Input::post('checked');
|
$checked = Input::post('checked');
|
||||||
$parameter = Input::post('parameter');
|
$parameter = Input::post('parameter');
|
||||||
|
|
||||||
if ($library_id === null || $right_name === null || $checked === null)
|
if ($library_id === null || $right_name === null || $checked === null)
|
||||||
throw new FuelException('Missing parameters');
|
throw new FuelException('Missing parameters');
|
||||||
|
|
||||||
$permission = Model_Permission::find_one_by('name', $right_name);
|
$permission = Model_Permission::find_one_by('name', $right_name);
|
||||||
|
|
||||||
$permission_id = $permission->id;
|
$permission_id = $permission->id;
|
||||||
|
|
||||||
$library_permission = Model_Library_Permission::find_one_by(function ($query) use ($library_id, $permission_id) {
|
$library_permission = Model_Library_Permission::find_one_by(function ($query) use ($library_id, $permission_id) {
|
||||||
$query
|
$query
|
||||||
->where('library_id', $library_id)
|
->where('library_id', $library_id)
|
||||||
->and_where('permission_id', $permission_id);
|
->and_where('permission_id', $permission_id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
if ($library_permission === null) {
|
if ($library_permission === null) {
|
||||||
$library_permission = new Model_Library_Permission();
|
$library_permission = new Model_Library_Permission();
|
||||||
$library_permission->library_id = $library_id;
|
$library_permission->library_id = $library_id;
|
||||||
$library_permission->permission_id = $permission_id;
|
$library_permission->permission_id = $permission_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($checked === 'false')
|
if ($checked === 'false')
|
||||||
$library_permission->disable = true;
|
$library_permission->disable = true;
|
||||||
else
|
else
|
||||||
$library_permission->disable = false;
|
$library_permission->disable = false;
|
||||||
|
|
||||||
if($parameter !== null)
|
if($parameter !== null)
|
||||||
$library_permission->value = $parameter;
|
$library_permission->value = $parameter;
|
||||||
|
|
||||||
$library_permission->save();
|
$library_permission->save();
|
||||||
|
|
||||||
return $this->response(['error' => false, 'message' => 'Permission modify successfully']);
|
return $this->response(['error' => false, 'message' => 'Permission modify successfully']);
|
||||||
} catch (Exception $exception) {
|
} catch (Exception $exception) {
|
||||||
return $this->response(['error' => true, 'message' => $exception->getMessage()]);
|
return $this->response(['error' => true, 'message' => $exception->getMessage()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Model_Library_Permission extends Model_Overwrite
|
class Model_Library_Permission extends Model_Overwrite
|
||||||
{
|
{
|
||||||
protected static $_table_name = 'library_permission';
|
protected static $_table_name = 'library_permission';
|
||||||
protected static $_primary_key = 'id';
|
protected static $_primary_key = 'id';
|
||||||
protected static $_properties = array(
|
protected static $_properties = array(
|
||||||
'id',
|
'id',
|
||||||
'permission_id',
|
'permission_id',
|
||||||
'library_id',
|
'library_id',
|
||||||
'value',
|
'value',
|
||||||
'disable'
|
'disable'
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue