public function testgetValues() { $app = $this->getApp(); $content = new Content($app, 'pages'); $content->setValue('title', 'Test Page'); $content->setValue('image', array('file' => 'image1.jpg', 'title' => 'Test image')); $values = $content->getValues(true); $this->assertEquals('Test Page', $values['title']); $this->assertEquals('{"file":"image1.jpg","title":"Test image"}', $values['image']); }
/** * Update a Bolt contenttype record. * * @param \Bolt\Content $content The content object to be updated * @param string $comment Add a comment to save with change. * * @throws \Bolt\Exception\StorageException * * @return bool */ private function updateContent(Bolt\Content $content, $comment = null) { $tablename = $this->getContenttypeTablename($content->contenttype); // Set the date the record was changed $content->setValue('datechanged', date('Y-m-d H:i:s')); // Test that the record exists in the database $oldContent = $this->findContent($tablename, $content['id']); if (empty($oldContent)) { throw new StorageException('Attempted to update a non-existent record'); } // Get the JSON database prepared values and make sure it's valid $fieldvalues = $this->getValidSaveData($content->getValues(true), $content->contenttype); // Do the actual update, and log it. $res = $this->app['db']->update($tablename, $fieldvalues, array('id' => $content['id'])); if ($res > 0) { $this->logUpdate($content->contenttype['slug'], $content['id'], $fieldvalues, $oldContent, $comment); return true; } }
/** * Insert a new contenttype record in the database. * * @param \Bolt\Content $content Record content to insert * @param string $comment Editor's comment * * @return boolean */ protected function insertContent(Content $content, $comment = null) { $tablename = $this->getContenttypeTablename($content->contenttype); // Set creation and update dates $content->setValue('datecreated', date('Y-m-d H:i:s')); $content->setValue('datechanged', date('Y-m-d H:i:s')); // id is set to autoincrement, so let the DB handle it unset($content->values['id']); // Get the JSON database prepared values and make sure it's valid $fieldvalues = $this->getValidSaveData($content->getValues(true), $content->contenttype); $this->app['db']->insert($tablename, $fieldvalues); $seq = null; if ($this->app['db']->getDatabasePlatform() instanceof PostgreSqlPlatform) { $seq = $tablename . '_id_seq'; } $id = $this->app['db']->lastInsertId($seq); if ($id > 0) { $content->setValue('id', $id); $this->logInsert($content->contenttype['slug'], $id, $fieldvalues, $comment); return true; } }