public function create($data = array())
 {
     parent::create($data);
     if ($this->newDoc) {
         $this->set('createdon', time());
         $this->set('createdby', $this->modx->getLoginUserID());
     }
     return $this;
 }
 public function save($fire_events = null, $clearCache = false)
 {
     if (!$this->checkUnique($this->table, 'uri')) {
         $this->log['UniqueUri'] = 'uri not unique <pre>' . print_r($this->get('uri'), true) . '</pre>';
         return false;
     }
     if ($this->get('uri') == '') {
         $this->log['EmptyUri'] = 'uri is empty';
         return false;
     }
     return parent::save($fire_events, $clearCache);
 }
Beispiel #3
0
 public function process()
 {
     $fields = $this->getContentFields();
     $owner = $this->getCFGDef('ownerField', 'aid');
     $result = false;
     if ($fields && !is_null($this->content)) {
         $clearCache = $this->getCFGDef('clearCache', false);
         switch ($this->mode) {
             case 'create':
                 if ($this->checkSubmitProtection() || $this->checkSubmitLimit()) {
                     return;
                 }
                 if ($this->owner) {
                     $fields[$owner] = $this->owner;
                 }
                 $result = $this->content->create($fields)->save(true, $clearCache);
                 $this->log('Create record', array('data' => $fields, 'result' => $result));
                 break;
             case 'edit':
                 $result = $this->content->fromArray($fields)->save(true, $clearCache);
                 $this->log('Update record', array('data' => $fields, 'result' => $result));
                 break;
             default:
                 break;
         }
         //чтобы не получился косяк, когда плагины обновят поля
         $this->content->close();
         $this->setFields($this->content->edit($this->id)->toArray());
         $this->log('Update form data', array('data' => $this->getFormData('fields')));
     }
     if (!$result) {
         $this->addMessage($this->lexicon->getMsg('edit.update_fail'));
     } else {
         if ($this->mode == 'create') {
             $url = '';
             $evtOut = $this->modx->invokeEvent('OnMakeDocUrl', array('id' => $result, 'data' => $this->getFormData('fields')));
             if (is_array($evtOut) && count($evtOut) > 0) {
                 $url = array_pop($evtOut);
             }
             if ($url) {
                 $this->setField('content.url', $url);
             }
         }
         parent::process();
     }
 }
Beispiel #4
0
 public function delete($ids, $fire_events = NULL)
 {
     $out = parent::delete($ids, $fire_events);
     $this->query("ALTER TABLE {$this->makeTable($this->table)} AUTO_INCREMENT = 1");
     return $out;
 }