コード例 #1
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->aClocking !== null) {
             if ($this->aClocking->isModified() || $this->aClocking->isNew()) {
                 $affectedRows += $this->aClocking->save($con);
             }
             $this->setClocking($this->aClocking);
         }
         if ($this->aTransaction !== null) {
             if ($this->aTransaction->isModified() || $this->aTransaction->isNew()) {
                 $affectedRows += $this->aTransaction->save($con);
             }
             $this->setTransaction($this->aTransaction);
         }
         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;
 }
コード例 #2
0
ファイル: clocking.php プロジェクト: dapepe/tymio
 /**
  * Checks whether the clocking's start and end dates are within the time limit.
  * Throws an exception if the time limit is exceeded.
  *
  * @return void
  * @see pastGraceTimeExceeded()
  */
 private function validateTimeLimits(Account $account, User $authUser, Clocking $clocking, PropelPDO $con = null)
 {
     $type = $clocking->getClockingType($con);
     if ($type === null) {
         throw new Exception('Could not get clocking type with ID #' . $clocking->getTypeId() . ' for clocking #' . $clocking->getId() . '.');
     }
     // Check time limit in seconds
     $propertyName = KeyReplace::replace(self::PROPERTY_CLOCKING_TIME_LIMIT, array('type' => $type->getIdentifier()));
     $domain = $authUser->getDomain($con);
     $lastChanged = $clocking->getLastChanged('U');
     $end = $clocking->getEnd('U');
     // Check clocking-type-specific limit first, fall back to default
     $editTimeLimit = PropertyPeer::get($propertyName, $account, $domain, $authUser, $con);
     if ($editTimeLimit === null) {
         $editTimeLimit = PropertyPeer::get(self::PROPERTY_CLOCKING_TIME_LIMIT_DEFAULT, $account, $domain, $authUser, $con);
     }
     $errorData = array('changed' => $lastChanged, 'end' => $end, 'limit' => $editTimeLimit);
     if ($editTimeLimit !== null and !is_numeric($editTimeLimit)) {
         throw new APIException(self::ERROR_TIME_LIMIT, 'Invalid non-numeric value ' . json_encode($editTimeLimit) . ' encountered for property "' . $propertyName . '".', $errorData);
     }
     $minTimeAllowed = time() - $editTimeLimit;
     $result = ((double) $end > $minTimeAllowed and ($clocking->isNew() or (double) $lastChanged > $minTimeAllowed));
     if ($result) {
         return;
     }
     throw new APIException(self::ERROR_TIME_LIMIT, 'Clocking cannot be edited any more after ' . round($editTimeLimit / 3600.0, 2) . ' hours.', $errorData);
 }