public function create(RESTRequest $request) { $data = $request->getData(); if (empty($data)) { throw new RESTCommandException('HTTP POST data is empty'); } $allowed_to_update_fields = array_fill_keys(array('mac', 'login', 'password', 'status', 'additional_services_on', 'ls', 'end_date', 'account_balance'), true); $data = array_intersect_key($data, $allowed_to_update_fields); if (empty($data)) { throw new RESTCommandException('Insert data is empty'); } if (isset($data['end_date'])) { $data['expire_billing_date'] = $data['end_date']; unset($data['end_date']); } if (!empty($data['mac'])) { $mac = Middleware::normalizeMac($data['mac']); if (!$mac) { throw new RESTCommandException('Not valid mac address'); } $data['mac'] = $mac; } if (empty($data['mac']) && (empty($data['login']) || empty($data['password']))) { throw new RESTCommandException('Login and password required'); } try { $uid = Stb::create($data); } catch (Exception $e) { throw new RESTCommandException($e->getMessage()); } $stb_list = $this->manager->getByUids(array($uid)); $stb_list = $this->formatList($stb_list); if (count($stb_list) == 1) { return $stb_list[0]; } return $stb_list; }