insert() public method

Inserts row in a table.
public insert ( $data ) : Nette\Database\Table\IRow | integer | boolean
return Nette\Database\Table\IRow | integer | boolean Returns IRow or number of affected rows for Selection or table without primary key
Beispiel #1
0
 /**
  * Default form handler
  */
 public function process()
 {
     /** @var ArrayHash $values */
     $values = $this->values;
     try {
         $this->onBeforeProcess($this, $values);
         if (isset($values->id)) {
             $this->onBeforeUpdate($this, $values);
             $arr = (array) $values;
             unset($arr['id']);
             $row = $this->selection->wherePrimary($values->id)->fetch();
             $row->update($arr);
             $this->onAfterUpdate($row, $this, $values);
         } else {
             $this->onBeforeInsert($this, $values);
             $row = $this->selection->insert($values);
             $this->onAfterInsert($row, $this, $values);
         }
         $this->onAfterProcess($row, $this, $values);
     } catch (\PDOException $e) {
         $this->addError($e->getMessage());
         dump($e);
         Debugger::log($e);
     }
 }
Beispiel #2
0
 /**
  * Inserts row in a table
  *
  * @param  array|\Traversable|(Selection|self) $data array($column => $value)|\Traversable|(Selection|self) for INSERT ... SELECT
  * @return HyperRow|int|bool Returns HyperRow or number of affected rows for Selection or table without primary key
  */
 public function insert($data)
 {
     if ($data instanceof self) {
         $data = $data->selection;
     }
     $result = $this->selection->insert($data);
     if ($result instanceof ActiveRow) {
         return $this->factory->createRow($result, $this->selection->getName());
     }
     return $result;
 }
Beispiel #3
0
 public function insert($data, $forceRegenerateTimes = FALSE)
 {
     unset($data['subject_id']);
     $pd = parent::insert($data);
     $id = $pd->id;
     if ($forceRegenerateTimes) {
         $this->generateAllTimes();
     } else {
         $this->generateAllTimes(20, $id);
     }
     return $pd;
 }
Beispiel #4
0
 /**
  *	Checks if in database table changelog are some changes that
  *	wasnt executed
  */
 public function importNewChangelogData()
 {
     $newChanges = false;
     // check if there are some unexecuted queries in database
     $changelogTable = clone $this->changelogTable;
     if ($changelogTable->where('executed', 0)->count('*') > 0) {
         // there are some unexecuted queries
         return true;
     }
     // load files with database changes
     foreach (Finder::findFiles('*.sql')->exclude('init.sql')->in($this->changelogPath) as $key => $file) {
         // check if file was already inserted into changelog table
         $filename = $file->getBasename('.sql');
         $fileParts = explode('_', $filename);
         if (count($fileParts) < 2) {
             throw new \Nette\UnexpectedValueException('Changelog file "' . $filename . '" has unexpected form. It should be %timestamp%_%name%.sql');
         }
         $changelogTable = clone $this->changelogTable;
         if ($changelogTable->where('file', $file->getBasename())->count('*') > 0) {
             // this file content was already inserted
             continue;
         }
         $newChanges = true;
         // content of the file is not in database table, insert it
         $filePathname = $file->getPathname();
         $fileContent = trim(file_get_contents($filePathname));
         $queries = explode(';', $fileContent);
         foreach ($queries as $query) {
             $query = trim($query);
             if (empty($query)) {
                 continue;
             }
             $data = array('file' => $file->getBasename(), 'description' => substr($fileParts[1], 0), 'query' => $query, 'executed' => 0, 'ins_timestamp' => $fileParts[0], 'ins_dt' => new \DateTime(), 'ins_process_id' => 'DbChangelog::areNewChangelogData');
             $this->changelogTable->insert($data);
         }
         if (empty($queries) || empty($fileContent)) {
             $newChanges = false;
         }
     }
     return $newChanges;
 }
 public function insert($data)
 {
     if ($data instanceof \Traversable && !$data instanceof Selection) {
         $data = iterator_to_array($data);
     }
     if (Nette\Utils\Validators::isList($data)) {
         foreach (array_keys($data) as $key) {
             $data[$key][$this->column] = $this->active;
         }
     } else {
         $data[$this->column] = $this->active;
     }
     return parent::insert($data);
 }
Beispiel #6
0
 public function insert($data)
 {
     if ($data instanceof \Traversable && !$data instanceof Selection) {
         $data = iterator_to_array($data);
     }
     if (is_array($data)) {
         $data[$this->column] = $this->active;
     }
     return parent::insert($data);
 }
Beispiel #7
0
 public function insert($data)
 {
     $coords = Geolocation::getCoordsFromText($data['map_coords']);
     $data['lat'] = $coords[0];
     $data['lon'] = $coords[1];
     $to_code = isset($data['locality_nickname']) ? $data['name'] . " " . $data['locality_nickname'] . " " . $data['locality_id'] : $data['name'] . " " . $data['locality_id'];
     $data['code'] = $data['code'] != '' ? $data['code'] : \Nette\Utils\Strings::webalize($to_code);
     $data['stroller'] = isset($data['stroller']) && $data['stroller'] == 1 ? 1 : 0;
     $data['visible'] = isset($data['visible']) && $data['visible'] == 1 ? 1 : 0;
     $data['ad_onhomepage'] = isset($data['ad_onhomepage']) && $data['ad_onhomepage'] == 1 ? 1 : 0;
     $data['ad'] = isset($data['ad']) && $data['ad'] == 1 ? 1 : 0;
     $data['show_in_catalogue'] = isset($data['show_in_catalogue']) && $data['show_in_catalogue'] == 1 ? 1 : 0;
     $data['show_in_calendar'] = isset($data['show_in_calendar']) && $data['show_in_calendar'] == 1 ? 1 : 0;
     $data['changed'] = new \Nette\DateTime();
     $data['created'] = new \Nette\DateTime();
     //$data['ad_shire'] = isset($data['ad_shire']) && $data['ad_shire'] == 0 ? null : $data['ad_shire'];
     //$data['ad_category'] = isset($data['ad_category']) && $data['ad_category'] == 0 ? null : $data['ad_category'];
     unset($data['categories']);
     parent::insert($data);
 }
Beispiel #8
0
 public function insert($data)
 {
     $data['code'] = Nette\Utils\Strings::webalize($data['subject_name'] . " " . $data['name']);
     $data['changed'] = new \Nette\DateTime();
     $data['created'] = new \Nette\DateTime();
     $coords = Geolocation::getCoordsFromText($data['subject_gps']);
     $data['lat'] = $coords[0];
     $data['lon'] = $coords[1];
     $data['last_edit_id'] = isset($this->context->user->id) ? $this->context->user->id : NULL;
     $pd = parent::insert($data);
     return $pd;
 }
Beispiel #9
0
 public function insert($data)
 {
     unset($data['subject_id']);
     $pd = parent::insert($data);
     return $pd;
 }