コード例 #1
0
 public function testSaveRecords()
 {
     $this->repository->selectContentType('example01');
     $record = $this->repository->createRecord('New Record');
     $record->setProperty('source', 'a');
     $id = $this->repository->saveRecord($record);
     $this->assertEquals(1, $id);
     $record = $this->repository->createRecord('New Record');
     $record->setProperty('source', 'b');
     $id = $this->repository->saveRecord($record);
     $this->assertEquals(2, $id);
     $record = $this->repository->createRecord('Differing Name');
     $record->setProperty('source', 'c');
     $id = $this->repository->saveRecord($record);
     $this->assertEquals(3, $id);
     $records = $this->repository->getRecords('name = New Record');
     $this->assertCount(2, $records);
     $filter1 = new PropertyFilter('name = New Record');
     $filter2 = new PropertyFilter('name = Differing Name');
     $orFilter = new ORFilter([$filter1, $filter2]);
     $records = $this->repository->getRecords($orFilter);
     $this->assertCount(3, $records);
     $records = $this->repository->getRecords('source > b');
     $this->assertCount(1, $records);
     $filter1 = new PropertyFilter('source > a');
     $filter2 = new PropertyFilter('name = Differing Name');
     $andFilter = new ANDFilter([$filter1, $filter2]);
     $records = $this->repository->getRecords($andFilter);
     $this->assertCount(1, $records);
 }
コード例 #2
0
 public function testSliceFilteredRecords()
 {
     $this->repository->selectContentType('example01');
     $records = $this->repository->getRecords('source > 3', 'source', 1, 5);
     $this->assertCount(5, $records);
     $this->assertEquals([4, 5, 6, 7, 8], array_keys($records));
     $records = $this->repository->getRecords('source > 3', 'source', 2, 5);
     $this->assertCount(2, $records);
     $this->assertEquals([9, 10], array_keys($records));
 }
コード例 #3
0
 public function testNewConnection()
 {
     $this->repository->selectContentType('example01');
     $record = $this->repository->getRecord(1);
     $this->assertEquals(5, $record->getRevision());
     $this->assertEquals('example01', $record->getContentTypeName());
     $this->assertEquals(1, $record->getID());
     $this->assertEquals('New Record 1 - Revision 5', $record->getName());
     $this->assertEquals('Test 1', $record->getProperty('article'));
     $records = $this->repository->getRecords();
     $this->assertCount(5, $records);
     $this->assertEquals(5, $this->repository->countRecords());
 }
コード例 #4
0
 public function testGetRecords()
 {
     $repository = new Repository('phpunit', $this->connection);
     $repository->selectContentType('temp');
     $records = $repository->getRecords();
     $this->assertCount(608, $records);
 }
コード例 #5
0
 public function exportXLSX(Repository $repository, $contentTypeName, $workspace = 'default', $language = 'default', $viewName = 'exchange')
 {
     $repository->selectContentType($contentTypeName);
     // Select view and fallback if necessary
     $contentTypeDefinition = $repository->getContentTypeDefinition();
     $viewDefinition = $contentTypeDefinition->getExchangeViewDefinition($viewName);
     $viewName = $viewDefinition->getName();
     $this->writeln('Connecting repository');
     $this->writeln('');
     $repository->selectWorkspace($workspace);
     $repository->selectLanguage($language);
     $repository->selectView($viewName);
     /** @var Record[] $records */
     $records = $repository->getRecords('', '.id', 1);
     if ($records !== false) {
         // Create new PHPExcel object
         $objPHPExcel = new \PHPExcel();
         // use temp folder for processing of large files
         $cacheMethod = \PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
         $cacheSettings = array('memoryCacheSize' => '12MB');
         \PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
         // Set document properties
         $objPHPExcel->getProperties()->setCreator("AnyContent CMCK")->setLastModifiedBy("AnyContent CMCK")->setTitle("Full Export from content type " . $contentTypeDefinition->getTitle())->setSubject("AnyContent Export")->setDescription("");
         $worksheet = $objPHPExcel->setActiveSheetIndex(0);
         $worksheet->setTitle('Export');
         $worksheet->setCellValueByColumnAndRow(0, 1, '.id');
         $worksheet->getStyleByColumnAndRow(0, 1)->getFont()->setBold(false)->setItalic(true);
         $worksheet->setCellValueByColumnAndRow(1, 1, '.revision');
         $worksheet->getStyleByColumnAndRow(1, 1)->getFont()->setBold(false)->setItalic(true);
         $row = 1;
         $column = 2;
         foreach ($contentTypeDefinition->getProperties($viewName) as $property) {
             $worksheet->setCellValueByColumnAndRow($column, $row, $property);
             $worksheet->getStyleByColumnAndRow($column, $row)->getFont()->setBold(true);
             $worksheet->getColumnDimensionByColumn($column)->setWidth(20);
             $column++;
         }
         $row++;
         foreach ($records as $record) {
             $this->writeln('Processing record ' . $record->getID() . ' - ' . $record->getName());
             $worksheet->setCellValueByColumnAndRow(0, $row, $record->getID());
             $worksheet->setCellValueByColumnAndRow(1, $row, $record->getRevision());
             $column = 2;
             foreach ($contentTypeDefinition->getProperties($viewName) as $property) {
                 $worksheet->setCellValueByColumnAndRow($column, $row, $record->getProperty($property));
                 $column++;
             }
             $row++;
         }
         $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
         ob_start();
         $objWriter->save('php://output');
         $excelOutput = ob_get_clean();
         return $excelOutput;
     }
     return false;
 }
コード例 #6
0
 public function testSortRecords()
 {
     $this->repository->selectContentType('example01');
     $this->repository->sortRecords([10 => 0, 9 => 10, 8 => 10]);
     $records = $this->repository->getRecords();
     $this->assertEquals(10, $records[9]->getParent());
     $this->assertEquals(10, $records[8]->getParent());
     $this->assertEquals(0, $records[10]->getParent());
     $this->assertNull($records[1]->getParent());
     $this->assertNotNull($records[10]->getParent());
     $this->assertEquals(1, $records[9]->getPosition());
     $this->assertEquals(2, $records[8]->getPosition());
     $records = $this->repository->getSortedRecords(0);
     $this->assertEquals([10, 9, 8], array_keys($records));
     $this->assertEquals(2, $records[9]->getLevel());
     $this->assertEquals(2, $records[8]->getLevel());
     $this->assertEquals(1, $records[10]->getLevel());
     $records = $this->repository->getSortedRecords(10);
     $this->assertEquals([9, 8], array_keys($records));
 }
コード例 #7
0
 public function testReverseSortRecords()
 {
     $this->repository->selectContentType('example01');
     // 1
     // 2
     //  -- 4
     //     -- 8
     //     -- 5
     //  -- 6
     // 3
     //  -- 9
     // 7
     $this->repository->sortRecords([1 => 0, 2 => 0, 4 => 2, 8 => 4, 5 => 4, 6 => 2, 3 => 0, 9 => 3, 7 => 0]);
     $records = $this->repository->getRecords();
     $this->assertEquals(2, $records[6]->getParent());
     $records = $this->repository->getSortedRecords(4);
     $this->assertEquals([8, 5], array_keys($records));
     $records = $this->repository->getSortedRecords(4, true);
     $this->assertEquals([4, 8, 5], array_keys($records));
     $records = $this->repository->getSortedRecords(4, true, 0, 1);
     $this->assertEquals([2, 4], array_keys($records));
     $records = $this->repository->getSortedRecords(4, false, 0, 1);
     $this->assertEquals([2], array_keys($records));
     $records = $this->repository->getSortedRecords(5, true, 0, 1);
     $this->assertEquals([2, 4, 5], array_keys($records));
     $records = $this->repository->getSortedRecords(9, true, 0, 1);
     $this->assertEquals([3, 9], array_keys($records));
     $records = $this->repository->getSortedRecords(4, true, 1, 1);
     $this->assertEquals([2, 4, 8, 5], array_keys($records));
     $records = $this->repository->getSortedRecords(2, false, 1);
     $this->assertEquals([4, 6], array_keys($records));
     $records = MenuBuilder::getBreadcrumb($this->repository, 'example01', 8);
     $this->assertEquals([2, 4, 8], array_keys($records));
     $records = MenuBuilder::getExpandedMenu($this->repository, 'example01', 8);
     $this->assertEquals([1, 2, 4, 8, 5, 6, 3, 7], array_keys($records));
     $records = MenuBuilder::getExpandedMenu($this->repository, 'example01', 6);
     $this->assertEquals([1, 2, 4, 6, 3, 7], array_keys($records));
     $records = MenuBuilder::getExpandedMenu($this->repository, 'example01', 4);
     $this->assertEquals([1, 2, 4, 8, 5, 6, 3, 7], array_keys($records));
 }
コード例 #8
0
 public function testGetRecords()
 {
     $repository = new Repository('phpunit', $this->connection);
     $repository->selectContentType('example01');
     $records = $repository->getRecords();
     $this->assertCount(5, $records);
     $this->assertEquals(5, $repository->countRecords());
     $i = 0;
     foreach ($records as $id => $record) {
         $i++;
         $this->assertEquals($i, $id);
         $this->assertEquals('Test ' . $i, $record->getProperty('article'));
     }
     $repository->registerRecordClassForContentType('example01', 'AnyContent\\Client\\AlternateRecordClass');
     $records = $repository->getRecords();
     $i = 0;
     foreach ($records as $id => $record) {
         $i++;
         $this->assertInstanceOf('AnyContent\\Client\\AlternateRecordClass', $record);
         $this->assertEquals($i, $id);
         $this->assertEquals('New Record ' . $i, $record->getName());
         $this->assertEquals('Test ' . $i, $record->getProperty('article'));
     }
 }
コード例 #9
0
 public function testRecordCanAccessRepository()
 {
     $repository = new Repository('phpunit', $this->connection);
     $repository->selectContentType('example01');
     $definition = $repository->getContentTypeDefinition();
     $records = [];
     for ($i = 1; $i <= 5; $i++) {
         $record = new Record($definition, 'Test ' . $i);
         $records[] = $record;
     }
     $repository->saveRecords($records);
     $record = $repository->getRecord(1);
     $this->assertInstanceOf('AnyContent\\Client\\Repository', $record->getRepository());
     $records = $repository->getRecords();
     $record = array_shift($records);
     $this->assertInstanceOf('AnyContent\\Client\\Repository', $record->getRepository());
 }
コード例 #10
0
 /**
  * @param string|Filter $filter
  * @param int           $page
  * @param null          $count
  * @param string|Array  $order
  *
  * @return Record[]
  */
 public function getRecords($filter = '', $order = ['.id'], $page = 1, $count = null, $dataDimensions = null)
 {
     if ($dataDimensions == null) {
         $dataDimensions = $this->getCurrentDataDimensions();
     }
     $caching = false;
     if ($this->isContentQueryRecordsCaching() && ($filter != '' || $count != null)) {
         $caching = true;
     }
     if ($this->isAllContentRecordsCaching() && ($filter == null && $count == null)) {
         $caching = true;
     }
     if ($caching) {
         if (!is_array($order)) {
             $order = [$order];
         }
         $cacheKey = $this->createCacheKey('records-query', [$this->getCurrentContentTypeName(), $filter, $page, $count, join(',', $order)], $dataDimensions);
         $data = $this->getCacheProvider()->fetch($cacheKey);
         if ($data) {
             $data = json_decode($data, true);
             $recordFactory = $this->getRecordFactory();
             $records = $recordFactory->createRecordsFromJSONRecordsArray($this->getCurrentContentTypeDefinition(), $data);
             foreach ($records as $record) {
                 $record->setRepository($this);
             }
             return $records;
         }
         $records = parent::getRecords($filter, $order, $page, $count, $dataDimensions);
         $data = json_encode($records);
         $this->getCacheProvider()->save($cacheKey, $data, $this->contentQueryRecordsCaching);
         return $records;
     }
     return parent::getRecords($filter, $order, $page, $count, $dataDimensions);
 }
コード例 #11
0
 /**
  * @param string|Filter $filter
  * @param int           $page
  * @param null          $count
  * @param string|Array  $order
  *
  * @return Record[]
  */
 public function getRecords($filter = '', $page = 1, $count = null, $order = ['.id'])
 {
     if ($this->isContentQueryRecordsCaching()) {
         if ($filter != '' || $count != null) {
             if (!is_array($order)) {
                 $order = [$order];
             }
             $cacheKey = $this->createCacheKey('records-query', [$this->getCurrentContentTypeName(), $filter, $page, $count, join(',', $order)]);
             $data = $this->getCacheProvider()->fetch($cacheKey);
             if ($data) {
                 $data = json_decode($data, true);
                 $recordFactory = new RecordFactory(['validateProperties' => false]);
                 $records = $recordFactory->createRecordsFromJSONRecordsArray($this->getCurrentContentTypeDefinition(), $data);
                 return $records;
             }
             $records = parent::getRecords($filter, $page, $count, $order);
             $data = json_encode($records);
             $this->getCacheProvider()->save($cacheKey, $data, $this->contentQueryRecordsCaching);
             return $records;
         }
     }
     return parent::getRecords($filter, $page, $count, $order);
 }
 public function testGetFilteredRecords()
 {
     KVMLogger::instance()->debug(__METHOD__);
     $connection = $this->connection;
     if (!$connection) {
         $this->markTestSkipped('RestLike Basic Connection credentials missing.');
     }
     $repository = new Repository('pidtag', $connection);
     $connection->selectContentType('dtag_searchresult_product');
     $records = $repository->getRecords();
     $this->assertCount(149, $records);
     $records = $repository->getRecords('name *= apple');
     $this->assertCount(10, $records);
     $records = $repository->getRecords('name = banana');
     $this->assertCount(0, $records);
 }
コード例 #13
0
 /**
  * @return null
  */
 protected function getRecords(Repository $repository)
 {
     if (!$this->records) {
         $this->writeln('');
         $this->writeln('Start fetching current effective records');
         $this->writeln('');
         $this->records = $repository->getRecords();
         if ($this->records === false) {
             throw new \Exception('Error fetching current effective records.');
         }
         $this->writeln('Done fetching current effective records');
         $this->writeln('');
     }
     return $this->records;
 }