public function publish(Batch $batch, BlockType $bt, Page $page, Area $area, BlockValue $value) { $records = $value->getRecords(); $inspector = \Core::make('import/value_inspector'); if (count($records) == 1) { $data = array(); foreach ($records[0]->getData() as $key => $value) { $result = $inspector->inspect($value); $data[$key] = $result->getReplacedValue(); } $b = $page->addBlock($bt, $area->getName(), $data); } elseif (count($records) > 1) { foreach ($records as $record) { if (strcasecmp($record->getTable(), $bt->getController()->getBlockTypeDatabaseTable()) == 0) { // This is the data record. $data = array(); foreach ($record->getData() as $key => $value) { $result = $inspector->inspect($value); $data[$key] = $result->getReplacedValue(); } $b = $page->addBlock($bt, $area->getName(), $data); } } // Now we import the OTHER records. foreach ($records as $record) { if (strcasecmp($record->getTable(), $bt->getController()->getBlockTypeDatabaseTable()) != 0) { $aar = new BlockRecord($record->getTable()); $aar->bID = $b->getBlockID(); foreach ($record->getData() as $key => $value) { $result = $inspector->inspect($value); $aar->{$key} = $result->getReplacedValue(); } $aar->Save(); } } } else { $b = $page->addBlock($bt, $area->getName(), array()); } return $b; }
/** * Automatically run when a block is deleted. This removes the special data from the block's specific database table. If a block needs to do more than this this method should be overridden. * * @return $void */ public function delete() { if ($this->bID > 0) { if ($this->btTable) { $ni = new BlockRecord($this->btTable); $ni->bID = $this->bID; $ni->Load('bID=' . $this->bID); $ni->delete(); } } }
protected function importAdditionalData($b, $blockNode) { if (isset($blockNode->data)) { foreach ($blockNode->data as $data) { if (strtoupper($data['table']) != strtoupper($this->getBlockTypeDatabaseTable())) { $table = (string) $data['table']; if (isset($data->record)) { foreach ($data->record as $record) { $aar = new \Concrete\Core\Legacy\BlockRecord($table); $aar->bID = $b->getBlockID(); foreach ($record->children() as $node) { $nodeName = $node->getName(); $aar->{$nodeName} = ContentImporter::getValue((string) $node); } $aar->Save(); } } } } } }
protected function importAdditionalData($b, $blockNode) { $inspector = \Core::make('import/value_inspector'); if (isset($blockNode->data)) { foreach ($blockNode->data as $data) { if (strtoupper($data['table']) != strtoupper($this->getBlockTypeDatabaseTable())) { $table = (string) $data['table']; if (isset($data->record)) { foreach ($data->record as $record) { $aar = new \Concrete\Core\Legacy\BlockRecord($table); $aar->bID = $b->getBlockID(); foreach ($record->children() as $node) { $nodeName = $node->getName(); $result = $inspector->inspect((string) $node); $aar->{$nodeName} = $result->getReplacedValue(); } $aar->Save(); } } } } } }