* Fix bugs of product api.
This commit is contained in:
@@ -18,9 +18,10 @@ class productsEntry extends entry
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function get()
|
||||
public function get($programID = 0)
|
||||
{
|
||||
$programID = $this->param('program', 0);
|
||||
if(!$programID) $programID = $this->param('program', 0);
|
||||
|
||||
if($programID)
|
||||
{
|
||||
$control = $this->loadController('program', 'product');
|
||||
@@ -67,16 +68,16 @@ class productsEntry extends entry
|
||||
*/
|
||||
public function post()
|
||||
{
|
||||
$fields = 'program,line,name,PO,QD,RD,type,desc,whitelist';
|
||||
$fields = 'program,code,line,name,PO,QD,RD,type,desc,whitelist';
|
||||
$this->batchSetPost($fields);
|
||||
|
||||
$this->setPost('acl', $this->request('acl', 'private'));
|
||||
$this->setPost('whitelist', $this->request('whitelist', array()));
|
||||
|
||||
$control = $this->loadController('product', 'create');
|
||||
$this->requireFields('name,program');
|
||||
$this->requireFields('name,code');
|
||||
|
||||
$control->create($this->request('program'));
|
||||
$control->create($this->request('program', 0));
|
||||
|
||||
$data = $this->getData();
|
||||
if(isset($data->result) and $data->result == 'fail') return $this->sendError(400, $data->message);
|
||||
|
||||
@@ -29,7 +29,7 @@ class ProgramsEntry extends Entry
|
||||
$result = array();
|
||||
foreach($programs as $program)
|
||||
{
|
||||
$result[] = $this->format($program, 'openedDate:time,lastEditedDate:time,closedDate:time,canceledDate:time');
|
||||
$result[] = $this->format($program, 'begin:date,end:date,realBegan:date,realEnd:date,openedDate:time,lastEditedDate:time,closedDate:time,canceledDate:time,deleted:bool');
|
||||
}
|
||||
return $this->send(200, array('programs' => $result));
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class userEntry extends Entry
|
||||
$user = $data->data->user;
|
||||
unset($user->password);
|
||||
|
||||
$this->send(200, $this->format($user, 'last:time,locked:time'));
|
||||
$this->send(200, $user);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,8 +46,10 @@ class userEntry extends Entry
|
||||
{
|
||||
$info = new stdclass();
|
||||
|
||||
$info->profile = $this->loadModel('user')->getById($this->app->user->account);
|
||||
unset($info->profile->password);
|
||||
$profile = $this->loadModel('user')->getById($this->app->user->account);
|
||||
unset($profile->password);
|
||||
|
||||
$info->profile = $this->format($profile, 'last:time,locked:time,birthday:date,join:date');
|
||||
|
||||
if(!$fields) return $this->send(200, $info);
|
||||
|
||||
|
||||
@@ -9,8 +9,9 @@ $routes['/tokens'] = 'tokens';
|
||||
$routes['/configurations'] = 'configs';
|
||||
$routes['/configurations/:name'] = 'config';
|
||||
|
||||
$routes['/products'] = 'products';
|
||||
$routes['/products/:id'] = 'product';
|
||||
$routes['/programs/:id/products'] = 'products';
|
||||
$routes['/products'] = 'products';
|
||||
$routes['/products/:id'] = 'product';
|
||||
|
||||
$routes['/productlines'] = 'productLines';
|
||||
$routes['/productlines/:id'] = 'productLine';
|
||||
|
||||
@@ -529,6 +529,9 @@ class baseEntry
|
||||
return gmdate("Y-m-d\TH:i:s\Z", strtotime($value));
|
||||
}
|
||||
return $value;
|
||||
case 'date':
|
||||
if(!$value or $value == '0000-00-00') return null;
|
||||
return $value;
|
||||
case 'bool':
|
||||
return boolval($value) ? true : false;
|
||||
default:
|
||||
|
||||
@@ -97,7 +97,15 @@ class program extends control
|
||||
*/
|
||||
public function product($programID = 0, $browseType = 'noclosed', $orderBy = 'order_desc', $recTotal = 0, $recPerPage = 15, $pageID = 1)
|
||||
{
|
||||
$programID = $this->program->saveState($programID, $this->program->getPairs());
|
||||
$programPairs = $this->program->getPairs();
|
||||
|
||||
if(defined('RUN_MODE') && RUN_MODE == 'api' && !isset($programPairs[$programID]))
|
||||
{
|
||||
return $this->send(array('status' => 'fail', 'code' => 404, 'message' => '404 Not found'));
|
||||
}
|
||||
|
||||
$programID = $this->program->saveState($programID, $programPairs);
|
||||
|
||||
setCookie("lastProgram", $programID, $this->config->cookieLife, $this->config->webRoot, '', false, true);
|
||||
|
||||
$this->program->setMenu($programID);
|
||||
|
||||
Reference in New Issue
Block a user