コード例 #1
0
ファイル: ContentTest.php プロジェクト: aaleksu/bolt_cm
 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']);
 }
コード例 #2
0
 public function testDefaultCode()
 {
     $entry = new Content($this->app, 'entries');
     $entry->setValue('title', 'Test');
     $entry->setValue('slug', 'test-default-code');
     $entry->setValue('ownerid', 1);
     $entry->setValue('status', 'published');
     $id = $this->app['storage']->saveContent($entry);
     $values = ['source' => '/test-default-code', 'contentId' => $id, 'contentType' => 'entries', 'code' => null];
     $redirect = new Redirect($values);
     $redirect->save();
     $request = Request::create('/test-default-code');
     $response = $this->app->handle($request);
     $default = $this->extension->config['default_status_code'];
     $default = empty($default) ? 302 : $default;
     $this->assertEquals($response->getStatusCode(), $default);
 }
コード例 #3
0
ファイル: StorageEventTest.php プロジェクト: aaleksu/bolt_cm
 public function testSetupWithRecord()
 {
     $app = $this->getApp();
     $content = new Content($app, 'pages');
     $content->setValue('id', 5);
     $event = new StorageEvent($content);
     $this->assertEquals(5, $event->getId());
     $this->assertEquals('pages', $event->getContentType());
 }
コード例 #4
0
ファイル: RecordModifier.php プロジェクト: xrash/bolt
 /**
  * Determine which templates will result in templatefields.
  *
  * @param array   $contenttype
  * @param Content $content
  *
  * @return array
  */
 private function getTempateFieldTemplates(array $contenttype, Content $content)
 {
     $templateFieldTemplates = [];
     $templateFieldsConfig = $this->app['config']->get('theme/templatefields');
     if ($templateFieldsConfig) {
         $templateFieldTemplates = array_keys($templateFieldsConfig);
         // Special case for default template
         $toRepair = [];
         foreach ($contenttype['fields'] as $name => $field) {
             if ($field['type'] === 'templateselect' && !empty($content->values[$name])) {
                 $toRepair[$name] = $content->values[$name];
                 $content->setValue($name, '');
             }
         }
         if ($content->hasTemplateFields()) {
             $templateFieldTemplates[] = '';
         }
         foreach ($toRepair as $name => $value) {
             $content->setValue($name, $value);
         }
     }
     return $templateFieldTemplates;
 }
コード例 #5
0
ファイル: Storage.php プロジェクト: realitygaps/site-v20
 /**
  * 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;
     }
 }
コード例 #6
0
ファイル: Storage.php プロジェクト: realitygaps/site-v20
 /**
  * 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;
     }
 }
コード例 #7
0
ファイル: Backend.php プロジェクト: wolbodo/pixelsite
 /**
  * Check whether the status is allowed.
  *
  * We act as if a status *transition* were requested and fallback to the old
  * status otherwise.
  *
  * @param Application $app
  * @param Content     $content
  * @param string      $contentTypeSlug
  * @param integer     $id
  * @param string      $oldStatus
  */
 private function setTransitionStatus(Application $app, Content $content, $contentTypeSlug, $id, $oldStatus)
 {
     $canTransition = $app['users']->isContentStatusTransitionAllowed($oldStatus, $content['status'], $contentTypeSlug, $id);
     if (!$canTransition) {
         $content->setValue('status', $oldStatus);
     }
 }
コード例 #8
0
 /**
  * Create the prototype context based on the parent.
  *
  * @param array $context
  * @param string $key
  *
  * @return array
  */
 public function getPrototypeContext(array $context, $key)
 {
     list($fields, $groups) = $this->wrapParseFieldsAndGroups($context['contenttype']['fields'][$key]['children']);
     foreach ($fields as $childKey => &$value) {
         list($realName, $realId) = $this->getRealNameAndId($key, $childKey);
         $value['real_name'] = $realName;
         $value['real_id'] = $realId;
     }
     // Do content.
     $content = new Content($this->app, '', array());
     foreach ($fields as $key => $options) {
         $content->setValue($key, $options['default']);
     }
     // Remove btn.
     list(, $realBtnId) = $this->getRealNameAndId($key, 'array_item_remove_btn');
     $childrenContext = array('contenttype' => array('fields' => $fields), 'content' => $content, 'allowed_status' => $context['allowed_status'], 'contentowner' => $context['contentowner'], 'fields' => $context['fields'], 'fieldtemplates' => $context['fieldtemplates'], 'can_upload' => $context['can_upload'], 'groups' => $groups ?: array('ungrouped' => array_keys($fields)), 'has' => array('incoming_relations' => false, 'relations' => false, 'tabs' => false, 'taxonomy' => false, 'templatefields' => false), 'array_options' => array('btn_remove_id' => $realBtnId));
     return $childrenContext;
 }