public function saveStatements($statements) { $versioned_statements = array(); $attachments_map = array(); foreach ($statements as $i => $st) { if (!$st instanceof Statement) { $st = new Statement($st); $statements[$i] = $st; } $versioned_statements[$i] = $st->asVersion($this->version); if ($st->hasAttachmentsWithContent()) { foreach ($st->getAttachments() as $attachment) { if (!isset($attachments_map[$attachment->getSha2()])) { $attachments_map[$attachment->getSha2()] = $attachment; } } } } $requestCfg = array('headers' => array('Content-Type' => 'application/json'), 'content' => json_encode($versioned_statements, JSON_UNESCAPED_SLASHES)); if (!empty($attachments_map)) { $this->_buildAttachmentContent($requestCfg, array_values($attachments_map)); } $response = $this->sendRequest('POST', 'statements', $requestCfg); if ($response->success) { $parsed_content = json_decode($response->content, true); foreach ($parsed_content as $i => $stId) { $statements[$i]->setId($stId); } $response->content = $statements; } return $response; }
public function saveStatements($statements) { $versioned_statements = array(); foreach ($statements as $i => $st) { if (!$st instanceof Statement) { $st = new Statement($st); $statements[$i] = $st; } $versioned_statements[$i] = $st->asVersion($this->version); } $requestCfg = array('headers' => array('Content-Type' => 'application/json'), 'content' => json_encode($versioned_statements, JSON_UNESCAPED_SLASHES)); $response = $this->sendRequest('POST', 'statements', $requestCfg); if ($response->success) { $parsed_content = json_decode($response->content, true); foreach ($parsed_content as $i => $stId) { $statements[$i]->setId($stId); } $response->content = $statements; } return $response; }