Exemplo n.º 1
0
 /**
  * Edit or create a node of the structure.
  *
  * @return void
  * @todo implement validators
  * @todo implement the advanced options (templates...)
  */
 public function editprocessAction()
 {
     $vNotEmpty = new Zend_Validate_NotEmpty();
     $r = $this->getRequest();
     $eid = 0;
     if ($vNotEmpty->isValid($r->label)) {
         $table = new Pagstructure();
         if ($r->ishome == '1') {
             $ishome = 1;
             $homeRowsTbl = new Pagstructure();
             $homeRow = $homeRowsTbl->fetchRow('ishome = 1 AND safinstances_id = ' . $this->safinstancesId);
             if (is_object($homeRow)) {
                 if (isset($homeRow->id) && $homeRow->id > 0 && $homeRow->id != $r->id) {
                     $homeRow->ishome = 1;
                 } else {
                     $homeRow->ishome = 0;
                 }
             }
         } else {
             $ishome = 0;
         }
         // Create a page
         if ($r->id <= 0 || !$r->id) {
             $oldnode = null;
             $data = array('label' => $r->label, 'htmltitle' => $r->htmltitle, 'url' => Sydney_Tools_Friendlyurls::getUrlLabel($r->url), 'parent_id' => $r->parent_id ? $r->parent_id : null, 'ishome' => $ishome, 'safinstances_id' => $this->safinstancesId, 'metakeywords' => '', 'metadesc' => '', 'iscachable' => '', 'cachetime' => '', 'redirecttoid' => '', 'usersgroups_id' => $r->usersgroups_id, 'shortdesc' => '', 'colorcode' => '', 'layout' => '');
             $eid = $table->insert($data);
             // GDE : 27/08/2010 Add trace of current action
             Sydney_Db_Trace::add('trace.event.create_page' . ' [' . $r->label . ']', 'adminpages', Sydney_Tools::getTableName($table), 'createpage', $eid);
         } elseif ($r->id > 0) {
             // edit an entry
             $nodeDB = new Pagstructure();
             $node = $nodeDB->fetchRow('id = ' . $r->id . ' AND safinstances_id = ' . $this->safinstancesId);
             // #120 - place on latest position in new node if parent change
             if ($node->parent_id != (int) $r->parent_id) {
                 // get last position
                 $node->pagorder = $nodeDB->getLatestPoitionInNode($r->parent_id);
             }
             /*
              * @change GDE - 05/2014 - Content Translation
              * Save translation of content (on native table for default language and on translation table for others)
              */
             $node->label = $this->view->nodeTranslate->translate($node->label, $r->label, $r->id);
             $node->htmltitle = $this->view->nodeTranslate->translate($node->htmltitle, $r->htmltitle, $r->id, 'htmltitle');
             $requestUrl = Sydney_Tools_Friendlyurls::getUrlLabel($r->url);
             $node->url = $this->view->nodeTranslate->translate($node->url, $requestUrl, $r->id, 'url');
             $node->parent_id = $r->parent_id ? $r->parent_id : null;
             $node->ishome = $ishome;
             $node->redirecttoid = $r->redirecttoid;
             if ($node->usersgroups_id != $r->usersgroups_id) {
                 $node->usersgroups_id = $r->usersgroups_id;
                 $nodeDB->updateAccessRights($node->id, $r->usersgroups_id, true);
             }
             $node->save();
             $eid = $r->id;
             // GDE : 27/08/2010 - Add trace of current action
             Sydney_Db_Trace::add('trace.event.update_page_properties' . ' [' . $r->label . ']', 'adminpages', Sydney_Tools::getTableName($nodeDB), 'editproperties', $eid);
         }
         // save the update of the homepage if everything went OK and we change the home page
         if ($r->ishome == '1' && is_object($homeRow) && $homeRow->id != $r->id) {
             $homeRow->save();
         }
     }
     if ($eid > 0) {
         // update menu
         $mns = new PagstructurePagmenus();
         $mns->delete('pagstructure_id = ' . $eid);
         if (is_array($r->menus)) {
             foreach ($r->menus as $mid) {
                 $crow = $mns->createRow();
                 $crow->pagstructure_id = $eid;
                 $crow->pagmenus_id = $mid;
                 $crow->save();
             }
         }
         PagstructureOp::cleanCache($this->safinstancesId);
         $this->redirect('/adminpages/pages/edit/id/' . $eid);
     }
 }