/** * create * * @param mixed $data * * @return mixed|ApiJsonModel|\Zend\Stdlib\ResponseInterface */ public function create($data) { //ACCESS CHECK if (!$this->rcmIsAllowed('sites', 'admin')) { $this->getResponse()->setStatusCode(Response::STATUS_CODE_401); return $this->getResponse(); } $siteId = $this->getRequestSiteId(); $site = $this->getSite($siteId); if (empty($site)) { return new ApiJsonModel(null, 1, "Site was not found with id {$siteId}."); } // // // $inputFilter = new SitePageDuplicateInputFilter(); $inputFilter->setData($data); if (!$inputFilter->isValid()) { return new ApiJsonModel([], 1, 'Some values are missing or invalid for page duplication.', $inputFilter->getMessages()); } $data = $inputFilter->getValues(); $destinationSite = $this->getSite($data['destinationSiteId']); if (empty($destinationSite)) { return new ApiJsonModel(null, 1, "Destination site was not found with id {$data['destinationSiteId']}."); } $page = $this->getPage($site, $data['pageId']); $newPage = new Page(); $newPage->populate($data); if (empty($page)) { return new ApiJsonModel(null, 1, "Source page was not found with id {$data['pageId']}."); } if ($this->hasPage($destinationSite, $newPage->getName(), $newPage->getPageType())) { return new ApiJsonModel(null, 1, 'Page already exists, duplicates cannot be created'); } // force author to current user $newPage->setAuthor($this->getCurrentAuthor()); try { $newPage = $this->getPageRepo()->copyPage($destinationSite, $page, $newPage->toArray(), null, true); } catch (\Exception $e) { return new ApiJsonModel(null, 1, $e->getMessage()); } $apiResponse = new SitePageApiResponse(); $apiResponse->populate($newPage->toArray()); return new ApiJsonModel($apiResponse, 0, "Success: Duplicated page to site {$data['destinationSiteId']}"); }
public function testUtilities() { $data = []; $data['name'] = 'testname'; $data['pageTitle'] = 'TESTTITLE'; $data['pageType'] = 'n'; $data['description'] = 'TESTDESC'; $data['keywords'] = 'KEY,WORD'; $data['author'] = 'TESTAUTHOR'; $data['pageLayout'] = 'TESTPAGELAYOUT'; $data['siteLayoutOverride'] = 'TESTLAYOUTOVERRIDE'; $data['parent'] = null; $obj1 = new Page(); $obj1->populate($data); $this->assertEquals($data['name'], $obj1->getName()); $this->assertEquals($data['pageTitle'], $obj1->getPageTitle()); $this->assertEquals($data['pageType'], $obj1->getPageType()); $this->assertEquals($data['description'], $obj1->getDescription()); $this->assertEquals($data['keywords'], $obj1->getKeywords()); $this->assertEquals($data['author'], $obj1->getAuthor()); $this->assertEquals($data['pageLayout'], $obj1->getPageLayout()); $this->assertEquals($data['siteLayoutOverride'], $obj1->getSiteLayoutOverride()); $this->assertEquals($data['parent'], $obj1->getParent()); $data['parent'] = new Page(); $obj1->populate($data); $this->assertEquals($data['parent'], $obj1->getParent()); // $json = json_encode($obj1); $this->assertJson($json); $iterator = $obj1->getIterator(); $this->assertInstanceOf('\\ArrayIterator', $iterator); $array = $obj1->toArray([]); $this->assertEquals($data['name'], $array['name']); $this->assertEquals($data['pageTitle'], $array['pageTitle']); $this->assertEquals($data['pageType'], $array['pageType']); $this->assertEquals($data['description'], $array['description']); $this->assertEquals($data['keywords'], $array['keywords']); $this->assertEquals($data['author'], $array['author']); $this->assertEquals($data['pageLayout'], $array['pageLayout']); $this->assertEquals($data['siteLayoutOverride'], $array['siteLayoutOverride']); $this->assertEquals($data['parent'], $array['parent']); }
/** * updatePage * * @param PageEntity $page * @param array $pageData * @param bool $doFlush * * @return void */ public function updatePage(PageEntity $page, $pageData, $doFlush = true) { // Values cannot be changed unset($pageData['pageId']); unset($pageData['author']); unset($pageData['createdDate']); unset($pageData['lastPublished']); $page->populate($pageData); $this->getEntityManager()->persist($page); if ($doFlush) { $this->getEntityManager()->flush(); } }