/**
  * @param $id
  * @return string
  */
 private function pageName($id)
 {
     $page = $this->getPage($id);
     if ($page) {
         return '<a href="' . \Coanda::adminUrl('pages/view/' . $page->id) . '">' . $page->name . '</a>';
     }
     return '<em>* page not found *</em> (#' . $id . ')';
 }
 public function execute($version, $data, $pageRepository, $urlRepository)
 {
     // Create new signoff request...
     $manager = App::make('CoandaCMS\\ContentSignoff\\ContentSignoffManager');
     $request = $manager->createNewSignoffRequest($version, \Coanda::currentUserId());
     $this->sendNotifications($request);
     $handler_data = [];
     $handler_data = $this->reserveNewSlug($handler_data, $version, $urlRepository);
     $version->publish_handler_data = json_encode($handler_data);
     $version->status = 'pending';
     $version->save();
     return Redirect::to(Coanda::adminUrl('pages/view/' . $version->page_id . '?tab=versions'))->with('info_message', 'Your request for sign off has been sent. Until then your version will remain pending.');
 }
 /**
  * @param bool $page
  * @return array
  */
 public function availablePageTypes($page = false)
 {
     $page_types = $this->page_types;
     if ($page !== false) {
         $allowed_page_types = $page->pageType()->allowedSubPageTypes();
         if (count($allowed_page_types) > 0) {
             $page_types = [];
             foreach ($allowed_page_types as $allowed_page_type) {
                 if (isset($this->page_types[$allowed_page_type])) {
                     $page_types[$allowed_page_type] = $this->page_types[$allowed_page_type];
                 }
             }
         }
     }
     $user_permissions = \Coanda::currentUserPermissions();
     if (isset($user_permissions['everything']) && in_array('*', $user_permissions['everything'])) {
         return $page_types;
     }
     if (isset($user_permissions['pages'])) {
         if (in_array('*', $user_permissions['pages'])) {
             return $page_types;
         }
         if (in_array('create', $user_permissions['pages'])) {
             if (isset($user_permissions['pages']['page_types'])) {
                 $new_page_types = [];
                 foreach ($user_permissions['pages']['page_types'] as $permissioned_page_type) {
                     if (isset($page_types[$permissioned_page_type])) {
                         $new_page_types[$permissioned_page_type] = $page_types[$permissioned_page_type];
                     }
                 }
                 return $new_page_types;
             } else {
                 return $page_types;
             }
         }
     }
     return [];
 }
 /**
  * @param $version
  */
 private function publishVersion($version)
 {
     $url_repository = \App::make('CoandaCMS\\Coanda\\Urls\\Repositories\\UrlRepositoryInterface');
     $url_repository->delete('pendingversion', $version->id);
     $page_repository = \App::make('CoandaCMS\\Coanda\\Pages\\Repositories\\PageRepositoryInterface');
     $page_repository->publishVersion($version, \Coanda::currentUser()->id, \App::make('CoandaCMS\\Coanda\\Urls\\Repositories\\UrlRepositoryInterface'));
 }