コード例 #1
0
 public function assign()
 {
     $pr = new PageEditResponse();
     if ($this->request->request->get('destID') == $this->page->getCollectionID()) {
         throw new \Exception(t("You cannot assign this page to itself."));
     }
     $destPage = \Page::getByID($_POST['destID']);
     if (Section::isMultilingualSection($destPage)) {
         $ms = Section::getByID($destPage->getCollectionID());
     } else {
         $ms = Section::getBySectionOfSite($destPage);
     }
     if (is_object($ms)) {
         // we need to assign/relate the source ID too, if it doesn't exist
         if (!Section::isAssigned($this->page)) {
             Section::registerPage($this->page);
         }
         Section::relatePage($this->page, $destPage, $ms->getLocale());
         $ih = Core::make('multilingual/interface/flag');
         $icon = (string) $ih->getSectionFlagIcon($ms);
         $pr->setAdditionalDataAttribute('name', $destPage->getCollectionName());
         $pr->setAdditionalDataAttribute('link', $destPage->getCollectionLink());
         $pr->setAdditionalDataAttribute('icon', $icon);
         $pr->setMessage(t('Page assigned.'));
         $pr->outputJSON();
     } else {
         throw new \Exception(t("The destination page doesn't appear to be in a valid multilingual section."));
     }
 }