public function save($fire_events = null, $clearCache = false) { if ($this->newDoc) { $rows = $this->modx->db->select('`sf_id`', $this->makeTable($this->table), '`sf_rid`=' . $this->field['sf_rid']); $this->field['sf_index'] = $this->modx->db->getRecordCount($rows); $this->touch('sf_createdon'); } return parent::save(); }
protected function _save($fire_events = null, $clearCache = false) { if (empty($this->field['sg_image'])) { $this->log['emptyImage'] = 'Image is empty in <pre>' . print_r($this->field, true) . '</pre>'; return false; } $rid = $this->get('sg_rid'); if (empty($rid)) { $rid = $this->default_field['sg_rid']; } $rid = (int) $rid; if ($this->newDoc) { $q = $this->query('SELECT count(`sg_id`) FROM ' . $this->makeTable($this->table) . ' WHERE `sg_rid`=' . $rid); $this->field['sg_index'] = $this->modx->db->getValue($q); $this->touch('sg_createdon'); } $q = $this->query('SELECT `template` FROM ' . $this->makeTable('site_content') . ' WHERE id=' . $rid); $template = $this->modx->db->getValue($q); if ($out = parent::save($fire_events, $clearCache)) { if ($this->newDoc) { $this->invokeEvent('OnFileBrowserUpload', array('filepath' => $this->get('filepath'), 'filename' => $this->get('filename'), 'template' => $template, 'sg_rid' => $rid), $fire_events); } $fields = $this->field; $fields['template'] = $template; $fields['sg_id'] = $out; $fields['newDoc'] = $this->newDoc; $this->invokeEvent('OnSimpleGallerySave', $fields, $fire_events); } return $out; }