public function save() { $form = Form::load('logbook.views.AddBlogEntry'); if($form->validate()) { $auth = new Author(); $auth->clause('user_id',Application::current()->user()->id()); if($auth->id()) { $item = new Entry(); $item->parse(); $item->set('author_id',$auth->id()); if(!Application::param('entry_date')) $item->set('entry_date',date('Y-m-d H:i:s')); $item->synch(); Entry::setTagsAndSave($item,Application::param('entry_tags')); $group = new Group(); $group->noForeign(); $author_id = $item->get('author_id'); $entry_id = $item->get('entry_id'); if($groups = $group->fetch()) { foreach($groups as $group) { if(file_exists(Application::MANAGED_CODE.'lbk_default_access_'.$group->get('access_id'))) { $data = file_get_contents(Application::MANAGED_CODE.'lbk_default_access_'.$group->get('access_id')); $perms = unserialize($data); ManageGroupAccess::setPermissionsOnEntryForGroup($author_id,$entry_id,$group->id(),$perms); } } } Application::setUrlParam('author_id',Application::param('author_id')); Application::setUrlParam('entry_id',Application::param('entry_id')); LogbookAccess::publishLookupTables(); $this->redirectOnSave(); } else die('You are not an author!'); } }
function updateEntry($id) { if (is_null($id)) { Functions::setResponse(400); } $data = Functions::getJSONData(); try { $c = new Entry($id); foreach ($c->getFields() as $field) { $value = Functions::elt($data, $field['name']); if (is_null($value)) { Functions::setResponse(400); } $c->set($field['name'], $value); } $c->set('id', $id); $c->save(); return true; } catch (RuntimeException $e) { Functions::setResponse(404); } }
/** * Given an Entry object, iterate over all of the fields in that object * an insert them into their relevant entry tables. * * @param Entry $entry * An Entry object to insert into the database * @return boolean */ public function add(Entry $entry) { $fields = $entry->get(); Symphony::Database()->insert($fields, 'tbl_entries'); if (!($entry_id = Symphony::Database()->getInsertID())) { return false; } foreach ($entry->getData() as $field_id => $field) { if (!is_array($field) || empty($field)) { continue; } Symphony::Database()->delete('tbl_entries_data_' . $field_id, " `entry_id` = '{$entry_id}'"); $data = array('entry_id' => $entry_id); $fields = array(); foreach ($field as $key => $value) { if (is_array($value)) { foreach ($value as $ii => $v) { $fields[$ii][$key] = $v; } } else { $fields[max(0, count($fields) - 1)][$key] = $value; } } for ($ii = 0; $ii < count($fields); $ii++) { $fields[$ii] = array_merge($data, $fields[$ii]); } Symphony::Database()->insert($fields, 'tbl_entries_data_' . $field_id); } $entry->set('id', $entry_id); return true; }
/** * This function imports 10 rows of the CSV data * @return void */ private function __ajaxImportRows() { $messageSuffix = ''; $updated = array(); $ignored = array(); $csv = $this->__getCSV(); if ($csv != false) { // Load the drivers: $drivers = $this->getDrivers(); // Default parameters: $currentRow = intval($_POST['row']); $sectionID = $_POST['section-id']; $uniqueAction = $_POST['unique-action']; $uniqueField = $_POST['unique-field']; $fieldIDs = explode(',', $_POST['field-ids']); $entryID = null; // Load the fieldmanager: $fm = new FieldManager($this); // Load the entrymanager: $em = new EntryManager($this); // Load the CSV data of the specific rows: $csvTitles = $csv->titles; $csvData = $csv->data; for ($i = $currentRow * 10; $i < ($currentRow + 1) * 10; $i++) { // Start by creating a new entry: $entry = new Entry($this); $entry->set('section_id', $sectionID); // Ignore this entry? $ignore = false; // Import this row: $row = $csvData[$i]; if ($row != false) { // If a unique field is used, make sure there is a field selected for this: if ($uniqueField != 'no' && $fieldIDs[$uniqueField] == 0) { die(__('[ERROR: No field id sent for: "' . $csvTitles[$uniqueField] . '"]')); } // Unique action: if ($uniqueField != 'no') { // Check if there is an entry with this value: $field = $fm->fetch($fieldIDs[$uniqueField]); $type = $field->get('type'); if (isset($drivers[$type])) { $drivers[$type]->setField($field); $entryID = $drivers[$type]->scanDatabase($row[$csvTitles[$uniqueField]]); } else { $drivers['default']->setField($field); $entryID = $drivers['default']->scanDatabase($row[$csvTitles[$uniqueField]]); } if ($entryID != false) { // Update? Ignore? Add new? switch ($uniqueAction) { case 'update': $a = $em->fetch($entryID); $entry = $a[0]; $updated[] = $entryID; break; case 'ignore': $ignored[] = $entryID; $ignore = true; break; } } } if (!$ignore) { // Do the actual importing: $j = 0; foreach ($row as $value) { // When no unique field is found, treat it like a new entry // Otherwise, stop processing to safe CPU power. $fieldID = intval($fieldIDs[$j]); // If $fieldID = 0, then `Don't use` is selected as field. So don't use it! :-P if ($fieldID != 0) { $field = $fm->fetch($fieldID); // Get the corresponding field-type: $type = $field->get('type'); if (isset($drivers[$type])) { $drivers[$type]->setField($field); $data = $drivers[$type]->import($value, $entryID); } else { $drivers['default']->setField($field); $data = $drivers['default']->import($value, $entryID); } // Set the data: if ($data != false) { $entry->setData($fieldID, $data); } } $j++; } // Store the entry: $entry->commit(); } } } } else { die(__('[ERROR: CSV Data not found!]')); } if (count($updated) > 0) { $messageSuffix .= ' ' . __('(updated: ') . implode(', ', $updated) . ')'; } if (count($ignored) > 0) { $messageSuffix .= ' ' . __('(ignored: ') . implode(', ', $updated) . ')'; } die('[OK]' . $messageSuffix); }