示例#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->aSfReviewReason !== null) {
             if ($this->aSfReviewReason->isModified() || $this->aSfReviewReason->isNew()) {
                 $affectedRows += $this->aSfReviewReason->save($con);
             }
             $this->setSfReviewReason($this->aSfReviewReason);
         }
         if ($this->aSfReview !== null) {
             if ($this->aSfReview->isModified() || $this->aSfReview->isNew()) {
                 $affectedRows += $this->aSfReview->save($con);
             }
             $this->setSfReview($this->aSfReview);
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = SfReviewModerationPeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setNew(false);
             } else {
                 $affectedRows += SfReviewModerationPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
示例#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->asfGuardUser !== null) {
             if ($this->asfGuardUser->isModified() || $this->asfGuardUser->isNew()) {
                 $affectedRows += $this->asfGuardUser->save($con);
             }
             $this->setsfGuardUser($this->asfGuardUser);
         }
         if ($this->aSfReviewType !== null) {
             if ($this->aSfReviewType->isModified() || $this->aSfReviewType->isNew()) {
                 $affectedRows += $this->aSfReviewType->save($con);
             }
             $this->setSfReviewType($this->aSfReviewType);
         }
         if ($this->aSfReviewStatus !== null) {
             if ($this->aSfReviewStatus->isModified() || $this->aSfReviewStatus->isNew()) {
                 $affectedRows += $this->aSfReviewStatus->save($con);
             }
             $this->setSfReviewStatus($this->aSfReviewStatus);
         }
         if ($this->aSfReviewRelatedBySfReviewId !== null) {
             if ($this->aSfReviewRelatedBySfReviewId->isModified() || $this->aSfReviewRelatedBySfReviewId->isNew()) {
                 $affectedRows += $this->aSfReviewRelatedBySfReviewId->save($con);
             }
             $this->setSfReviewRelatedBySfReviewId($this->aSfReviewRelatedBySfReviewId);
         }
         if ($this->isNew()) {
             $this->modifiedColumns[] = SfReviewPeer::ID;
         }
         // If this object has been modified, then save it to the database.
         if ($this->isModified()) {
             if ($this->isNew()) {
                 $pk = SfReviewPeer::doInsert($this, $con);
                 $affectedRows += 1;
                 // we are assuming that there is only 1 row per doInsert() which
                 // should always be true here (even though technically
                 // BasePeer::doInsert() can insert multiple rows).
                 $this->setId($pk);
                 //[IMV] update autoincrement primary key
                 $this->setNew(false);
             } else {
                 $affectedRows += SfReviewPeer::doUpdate($this, $con);
             }
             $this->resetModified();
             // [HL] After being saved an object is no longer 'modified'
         }
         if ($this->collSfReviewsRelatedBySfReviewId !== null) {
             foreach ($this->collSfReviewsRelatedBySfReviewId as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->collSfReviewAttachs !== null) {
             foreach ($this->collSfReviewAttachs as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         if ($this->collSfReviewModerations !== null) {
             foreach ($this->collSfReviewModerations as $referrerFK) {
                 if (!$referrerFK->isDeleted()) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
示例#3
0
 public static function postReview($userId, $typeId, $entityId, $value, $text = false, $entity = false, $rm = false, $fb = '?', $source = '', $anonymous = '?', $tw = '?')
 {
     $prevValue = false;
     $guessAnonymous = $anonymous && $anonymous == '?' ? true : false;
     $guessFB = $fb && $fb == '?' ? true : false;
     $guessTW = $tw && $tw == '?' ? true : false;
     if ($guessAnonymous) {
         $user = sfGuardUserPeer::retrieveByPK($userId);
         if ($user) {
             $anonymous = $user->getProfile()->getAnonymous();
         }
     }
     if (!$entityId || !$value) {
         throw new Exception("Not enough parameters.");
     }
     if ($value != -1 && $value != 1) {
         throw new Exception("Invalid data for 'value'.");
     }
     // Check if already exists
     $c = new Criteria();
     if (!$typeId) {
         $c->add(SfReviewPeer::SF_REVIEW_ID, $entityId);
     } else {
         $c->add(SfReviewPeer::ENTITY_ID, $entityId);
     }
     $c->add(SfReviewPeer::SF_GUARD_USER_ID, $userId);
     $c->add(SfReviewPeer::SF_REVIEW_TYPE_ID, $typeId ? $typeId : null);
     $review = SfReviewPeer::doSelectOne($c);
     if (!$review) {
         $review = new SfReview();
         if (!$typeId) {
             $review->setSfReviewId($entityId);
         } else {
             $review->setEntityId($entityId);
         }
         $review->setSfReviewTypeId($typeId ? $typeId : null);
         $review->setSfGuardUserId($userId);
         $review->setCreatedAt(new DateTime());
         $review->setSource($source);
     } else {
         if ($rm && $value == $review->getValue() && $review->getIsActive()) {
             $review->setIsActive(false);
         } else {
             $review->setIsActive(true);
         }
         $review->setModifiedAt(new DateTime());
     }
     $review->setValue($value);
     if ($text) {
         $aText = SfVoUtil::cutToLength($text, self::MAX_LENGTH, '');
         $aText = strip_tags($aText);
         $review->setText($aText);
     }
     $review->setSfReviewStatusId(1);
     $review->setIpAddress($_SERVER['REMOTE_ADDR']);
     $review->setCookie(sfContext::getInstance()->getRequest()->getCookie('symfony'));
     $review->setCulture(sfContext::getInstance()->getUser()->getCulture());
     if (!$guessFB) {
         $review->setToFb($fb);
     }
     if (!$guessTW) {
         $review->setToTw($tw);
     }
     if (!$guessAnonymous || $review->isNew()) {
         $review->setAnonymous($anonymous);
     }
     try {
         $review->save();
         if (!$typeId) {
             $parentReview = SfReviewPeer::retrieveByPk($entityId);
             $parentReview->setBalance(SfReviewManager::getBalanceByReviewId($entityId));
             $parentReview->save();
         }
         if (!$entity) {
             if (!$typeId) {
                 $aEntityId = $parentReview->getEntityId();
                 $aTypeId = $parentReview->getSfReviewTypeId();
             } else {
                 $aTypeId = $typeId;
                 $aEntityId = $entityId;
             }
             $reviewType = SfReviewTypePeer::retrieveByPK($aTypeId);
             $peer = $reviewType->getModel() . 'Peer';
             $entity = $peer::retrieveByPK($aEntityId);
         }
         $entity->updateCalcs();
         $entity->save();
     } catch (Exception $e) {
         throw new Exception('Error writing review.');
     }
     return $review->getIsActive() ? $review : false;
 }