/**
  * testCase
  *
  * @return void
  */
 public function testCase()
 {
     $expected = ['siteId' => 'int', 'pageId' => 'int', 'name' => 'string', 'author' => 'string', 'createdDate' => 'string', 'lastPublished' => 'string', 'pageLayout' => 'string', 'siteLayoutOverride' => 'string', 'pageTitle' => 'string', 'description' => 'string', 'keywords' => 'string', 'pageType' => 'string'];
     $unit = new SitePageApiResponse();
     $unit->setSite(new Site());
     $unit->setCreatedDate(new \DateTime());
     $unit->setLastPublished(new \DateTime());
     $data = $unit->toArray();
     $this->assertEquals(count($expected), count($data));
     foreach ($expected as $key => $value) {
         $this->assertTrue(array_key_exists($key, $data), "Missing data key: {$key}");
     }
 }
 /**
  * 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']}");
 }
 /**
  * create
  *
  * @param mixed $data
  *
  * @return mixed|ApiJsonModel|\Zend\Stdlib\ResponseInterface
  */
 public function create($data)
 {
     $siteId = $this->getRequestSiteId();
     //ACCESS CHECK
     $sitePagesResource = $this->getSitePagesResourceId($siteId);
     if (!$this->isAllowed('pages', 'create') && !$this->isAllowed($sitePagesResource, 'create')) {
         $this->getResponse()->setStatusCode(Response::STATUS_CODE_401);
         return $this->getResponse();
     }
     $site = $this->getSite($siteId);
     if (empty($site)) {
         return new ApiJsonModel(null, 1, "Site was not found with id {$siteId}.");
     }
     // // //
     $inputFilter = new SitePageCreateInputFilter();
     $inputFilter->setData($data);
     if (!$inputFilter->isValid()) {
         return new ApiJsonModel([], 1, 'Some values are missing or invalid for page creation.', $inputFilter->getMessages());
     }
     $data = $inputFilter->getValues();
     if ($this->hasPage($site, $data['name'], $data['pageType'])) {
         return new ApiJsonModel(null, 1, 'Page already exists, duplicates cannot be created');
     }
     $data['author'] = $this->getCurrentAuthor();
     try {
         $page = $this->getPageRepo()->createPage($site, $data);
     } catch (\Exception $e) {
         return new ApiJsonModel(null, 1, $e->getMessage());
     }
     $apiResponse = new SitePageApiResponse();
     $apiResponse->populate($page->toArray());
     return new ApiJsonModel($apiResponse, 0, 'Success: Page created');
 }