Example #1
0
 public function save()
 {
     PHPWS_Core::initModClass('search', 'Search.php');
     if (!$this->id) {
         $new = true;
         $this->create_date = time();
     } else {
         $new = false;
     }
     $this->last_updated = time();
     // If this page has a parent and the order is not set
     // then increment
     if (!$this->page_order && $this->parent_page) {
         $page_order = $this->getLastPage();
         if (!PHPWS_Error::logIfError($page_order)) {
             $this->page_order = $page_order + 1;
         } else {
             $this->page_order = 1;
         }
     }
     $db = new PHPWS_DB('ps_page');
     if (PHPWS_Error::logIfError($db->saveObject($this))) {
         return false;
     }
     $this->saveKey();
     if ($new && Current_User::isRestricted('pagesmith')) {
         Current_User::giveItemPermission($this->_key);
     }
     $search = new Search($this->key_id);
     $search->resetKeywords();
     $search->addKeywords($this->title);
     PHPWS_Error::logIfError($search->save());
     foreach ($this->_sections as $section) {
         $section->pid = $this->id;
         PHPWS_Error::logIfError($section->save($this->key_id));
     }
     PHPWS_Cache::remove($this->cacheKey());
 }