Exemplo n.º 1
0
 public function copyChart($src)
 {
     $chart = new Chart();
     // new id
     $chart->setId($this->getUnusedRandomId());
     // but the rest remains the same
     $chart->setUser($src->getUser());
     $chart->setTitle($src->getTitle() . ' (' . __('Copy') . ')');
     $chart->setMetadata(json_encode($src->getMetadata()));
     $chart->setTheme($src->getTheme());
     $chart->setLocale($src->getLocale());
     $chart->setType($src->getType());
     $chart->setCreatedAt(time());
     $chart->setLastModifiedAt(time());
     $chart->setLastEditStep(3);
     // we need to copy the data, too
     $chart->writeData($src->loadData());
     $chart->save();
     return $chart;
 }
Exemplo n.º 2
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      PropelPDO $con
  * @return     int The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws     PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aUser !== null) {
             if ($this->aUser->isModified() || $this->aUser->isNew()) {
                 $affectedRows += $this->aUser->save($con);
             }
             $this->setUser($this->aUser);
         }
         if ($this->aChart !== null) {
             if ($this->aChart->isModified() || $this->aChart->isNew()) {
                 $affectedRows += $this->aChart->save($con);
             }
             $this->setChart($this->aChart);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Exemplo n.º 3
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aUser !== null) {
             if ($this->aUser->isModified() || $this->aUser->isNew()) {
                 $affectedRows += $this->aUser->save($con);
             }
             $this->setUser($this->aUser);
         }
         if ($this->aOrganization !== null) {
             if ($this->aOrganization->isModified() || $this->aOrganization->isNew()) {
                 $affectedRows += $this->aOrganization->save($con);
             }
             $this->setOrganization($this->aOrganization);
         }
         if ($this->aChartRelatedByForkedFrom !== null) {
             if ($this->aChartRelatedByForkedFrom->isModified() || $this->aChartRelatedByForkedFrom->isNew()) {
                 $affectedRows += $this->aChartRelatedByForkedFrom->save($con);
             }
             $this->setChartRelatedByForkedFrom($this->aChartRelatedByForkedFrom);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         if ($this->chartsRelatedByIdScheduledForDeletion !== null) {
             if (!$this->chartsRelatedByIdScheduledForDeletion->isEmpty()) {
                 foreach ($this->chartsRelatedByIdScheduledForDeletion as $chartRelatedById) {
                     // need to save related object because we set the relation to null
                     $chartRelatedById->save($con);
                 }
                 $this->chartsRelatedByIdScheduledForDeletion = null;
             }
         }
         if ($this->collChartsRelatedById !== null) {
             foreach ($this->collChartsRelatedById as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->jobsScheduledForDeletion !== null) {
             if (!$this->jobsScheduledForDeletion->isEmpty()) {
                 JobQuery::create()->filterByPrimaryKeys($this->jobsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->jobsScheduledForDeletion = null;
             }
         }
         if ($this->collJobs !== null) {
             foreach ($this->collJobs as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
$user = new User();
$user->setEmail('test');
$pwd = !empty($dw_config['testuser_pwd']) ? $dw_config['testuser_pwd'] : 'test';
$user->setPwd(hash_hmac('sha256', $pwd, DW_AUTH_SALT));
$user->setRole('editor');
$user->setCreatedAt(time());
$user->save();
$themes = DatawrapperTheme::all(true);
foreach (glob("../test/test-charts/*.json") as $test) {
    $config = json_decode(file_get_contents($test), true);
    $data = $config['_data'];
    unset($config['_data']);
    unset($config['_sig']);
    if (isset($config['_id'])) {
        $config['metadata']['describe']['__test_id'] = $config['_id'];
        unset($config['_id']);
    }
    unset($config['id']);
    foreach ($themes as $theme) {
        $chart = new Chart();
        $chart->setId(ChartQuery::create()->getUnusedRandomId());
        $chart->setUser($user);
        $chart->unserialize($config);
        $chart->writeData($data);
        $chart->setTheme($theme['id']);
        $chart->setLastEditStep(5);
        $chart->save();
    }
}
print "To see the charts, please visit\n";
print 'http://' . $GLOBALS['dw_config']['domain'] . '/admin/charts/' . $user->getId() . "\n";
Exemplo n.º 5
0
$t->isa_ok($sha1, 'string', '->save() creates a sha for each chart');
$g->setKilometersFrom(235);
$g->save();
$sha2 = $g->getHash();
$t->cmp_ok($sha1, '!=', $sha2, '->save() The hash field is updated each time the object is changed');
$g = new Chart();
$g->setFormat('png');
$g->setKilometersTo(12423);
$g->setUserId($ut->getUserId('ruf'));
$g->link('Vehicles', array($ut->getVehicleId('vw-touran-1-4-tsi')));
$g->link('Categories', array($ut->getIdForCategory('Fuel')));
$sha = $g->getHash();
$g2 = new Chart();
$g2->setUserId($ut->getUserId('ruf'));
$g->save();
$finalsha = $g->getHash();
$t->isnt($sha, $finalsha, 'When saving the object, ->save() checks that a unique sha is set. If not, a new one is generated.');
// ->delete()
$t->diag('->delete()');
$g = new Chart();
$g->setUserId($ut->getUserId('ruf'));
$g->save();
$id = $g->getId();
$path = $g->getChartFileSystemPath();
$fs = new sfFilesystem(new sfEventDispatcher());
$fs->touch($path);
$t->cmp_ok(file_exists($path), '===', true, 'A Chart may have an associated figure file.');
$g->delete();
$g2 = Doctrine_Core::getTable('Chart')->findOneById($id);
$t->cmp_ok($g2, '===', false, '->delete() deletes the chart from the DB');
$t->cmp_ok(file_exists($path), '===', false, '->delete() also deletes the image associated to the Chart');
Exemplo n.º 6
0
 protected function saveNewChart()
 {
     $chart = new Chart();
     $params = $this->parameters;
     $foreign = array('categories_list' => 'Categories', 'vehicles_list' => 'Vehicles');
     $chart->fromArray($this->parameters);
     foreach ($foreign as $field => $class) {
         if (isset($params[$field])) {
             $chart->link($class, $params[$field]);
         }
     }
     try {
         $chart->save();
     } catch (Exception $exc) {
         $sfe = new sfException();
         throw $sfe->createFromException($exc);
     }
     $this->chart = $chart;
     return $chart;
 }