public function postSave(PropelPDO $con = null) { if ($this->roleIdsChanged) { // delete old roles $c = new Criteria(); $c->addAnd(KuserToUserRolePeer::KUSER_ID, $this->getId(), Criteria::EQUAL); KuserToUserRolePeer::doDelete($c); // add new roles $idsArray = explode(',', $this->roleIds); foreach ($idsArray as $id) { if (!is_null($id) && $id != '') { $kuserToRole = new KuserToUserRole(); $kuserToRole->setUserRoleId($id); $kuserToRole->setKuserId($this->getId()); $kuserToRole->save(); } } } $this->roleIdsChanged = false; return parent::postSave(); }
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(KuserToUserRolePeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $ret = $this->preDelete($con); if ($ret) { KuserToUserRolePeer::doDelete($this, $con); $this->postDelete($con); $this->setDeleted(true); $con->commit(); } else { $con->commit(); } } catch (PropelException $e) { $con->rollBack(); throw $e; } }
public function postSave(PropelPDO $con = null) { if ($this->roleIdsChanged) { // delete old roles $c = new Criteria(); $c->addAnd(KuserToUserRolePeer::KUSER_ID, $this->getId(), Criteria::EQUAL); KuserToUserRolePeer::doDelete($c); // add new roles $idsArray = explode(',', $this->roleIds); foreach ($idsArray as $id) { if (!is_null($id) && $id != '') { $kuserToRole = new KuserToUserRole(); $kuserToRole->setUserRoleId($id); $kuserToRole->setKuserId($this->getId()); $kuserToRole->save(); } } } $this->roleIdsChanged = false; //update all categoryKuser object with kuser if (categoryKuserPeer::isCategroyKuserExistsForKuser($this->getId())) { $featureStatusToRemoveIndex = new kFeatureStatus(); $featureStatusToRemoveIndex->setType(IndexObjectType::CATEGORY_USER); $featureStatusesToRemove = array(); $featureStatusesToRemove[] = $featureStatusToRemoveIndex; $filter = new categoryKuserFilter(); $filter->setUserIdEqual($this->getPuserId()); kJobsManager::addIndexJob($this->getPartnerId(), IndexObjectType::CATEGORY_USER, $filter, true, $featureStatusesToRemove); } return parent::postSave(); }