/** * 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->aIndicatorsSc !== null) { if ($this->aIndicatorsSc->isModified() || $this->aIndicatorsSc->isNew()) { $affectedRows += $this->aIndicatorsSc->save($con); } $this->setIndicatorsSc($this->aIndicatorsSc); } if ($this->aUserSc !== null) { if ($this->aUserSc->isModified() || $this->aUserSc->isNew()) { $affectedRows += $this->aUserSc->save($con); } $this->setUserSc($this->aUserSc); } if ($this->aGroupDataIndicadores !== null) { if ($this->aGroupDataIndicadores->isModified() || $this->aGroupDataIndicadores->isNew()) { $affectedRows += $this->aGroupDataIndicadores->save($con); } $this->setGroupDataIndicadores($this->aGroupDataIndicadores); } if ($this->isNew()) { $this->modifiedColumns[] = DataIndicadoresPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = DataIndicadoresPeer::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 += DataIndicadoresPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collAuditDataIndicadoress !== null) { foreach ($this->collAuditDataIndicadoress as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
public function executeStart_tree(sfWebRequest $request) { $tree_id = $request->getParameter('treeId'); $tree_id = explode('-', $tree_id); $tree_id = $tree_id[1]; $token = $request->getParameter('token'); $user = $this->getUser()->getAttribute(sfConfig::get('app_session_current_user'), null); $token_session = $this->getUser()->getAttribute(sfConfig::get('app_session_tree_production'), null); if ($token_session != null) { if ($user != null) { $tree = TreeScPeer::retrieveByPK($tree_id); if (is_object($tree)) { if ($tree->getFlag() == 1) { if ($token_session == $token) { $tree->setProduccion('production'); $tree->setUpdateAt(time()); $tree->save(); $criterio = new Criteria(); $criterio->add(IndicatorsScPeer::TREE_ID, $tree->getId()); $criterio->add(IndicatorsScPeer::FLAG, '%habilitado%', Criteria::LIKE); $criterio->add(IndicatorsScPeer::ULTIMO_NODO, 1); $criterio->addAscendingOrderByColumn(IndicatorsScPeer::PREVIOUS_ID); $list_indicadores = IndicatorsScPeer::doSelect($criterio); $group_data = new GroupDataIndicadores(); $group_data->setTreeId($tree->getId()); $group_data->setCreateAt(time()); $group_data->save(); foreach ($list_indicadores as $row) { $data = new DataIndicadores(); $data->setIndicadorId($row->getId()); $data->setUserId($row->getResponsableId()); $data->setGroupData($group_data->getId()); if ($row->getValorActualEntregado() != '') { $data->setData($row->getValorActualEntregado()); } else { $data->setData(0); } $data->setCreateAt(time()); $data->setUpdateAt(time()); $data->save(); $this->recalcular($data->getIndicatorsSc()); } $this->getUser()->getAttributeHolder()->remove(sfConfig::get('app_session_tree_production')); $serviceProjection = new ProjectionsService(); $serviceProjection->generateData($tree->getId()); $this->redirect('@projections_start?idTree=' . $tree->getId()); } else { return sfView::ERROR; } } else { $this->message = 'flag tree incorrect'; return sfView::ERROR; } } else { $this->message = 'tree not found'; return sfView::ERROR; } } else { $this->message = 'session expired'; return sfView::ERROR; } } else { $this->message = 'token error'; return sfView::ERROR; } }
private function actualizarNodosPorPeriodo($periodo_id) { $c = new Criteria(); $c->add(TreeScPeer::PERIODO_ID, $periodo_id); $c->add(TreeScPeer::PRODUCCION, 'production'); $c->add(IndicatorsScPeer::ULTIMO_NODO, 1); $c->add(IndicatorsScPeer::FLAG, 'habilitado'); $c->addJoin(TreeScPeer::ID, IndicatorsScPeer::TREE_ID); $nodos = IndicatorsScPeer::doSelect($c); if (count($nodos) > 0) { $group_data_indicadores = new GroupDataIndicadores(); $group_data_indicadores->setCreateAt(time()); $group_data_indicadores->setTreeId($nodos[0]->getTreeId()); $group_data_indicadores->save(); //$nodos es sòlo los ultimos nodos de un arbol foreach ($nodos as $row) { $data_indicadores = new DataIndicadores(); $data_indicadores->setIndicadorId($row->getId()); $data_indicadores->setUserId($row->getResponsableId()); $c = new Criteria(); $c->add(DataIndicadoresPeer::INDICADOR_ID, $row->getId()); $c->addDescendingOrderByColumn(DataIndicadoresPeer::CREATE_AT); $c->setLimit(1); $data_anterior_indicador = DataIndicadoresPeer::doSelectOne($c); if ($row->getDetNetworkAttributeId() == null) { /* si es null, es conector interno (manualmente) */ $data_indicadores->setData(0); $row->setValorActualEntregado(0); $row->save(); } else { $data_indicadores->setData($this->getIndicatorScData($row->getId())); $row->setValorActualEntregado($this->getIndicatorScData($row->getId())); $row->save(); } $data_indicadores->setGroupData($group_data_indicadores->getId()); $data_indicadores->setCreateAt(time()); $data_indicadores->setUpdateAt(time()); $data_indicadores->save(); } $ultima_fecha_del_array = $data_indicadores->getCreateAt(); if (count($nodos) > 0) { /* * Obtengo los indicadores que tienen indicadores hijos ( ultimos indicadores ) * o comienzo a recacular todos los valores Actuales de todos los indicadores */ $criterio = new Criteria(); $criterio->add(IndicatorsScPeer::TREE_ID, $nodos[0]->getTreeId()); $criterio->add(IndicatorsScPeer::FLAG, '%habilitado%', Criteria::LIKE); $criterio->add(IndicatorsScPeer::ULTIMO_NODO, 1); $criterio->addAscendingOrderByColumn(IndicatorsScPeer::PREVIOUS_ID); $list_indicadores = IndicatorsScPeer::doSelect($criterio); foreach ($list_indicadores as $row) { if ($row->getPreviousId() != 0) { $var = $this->recalcular($row, $ultima_fecha_del_array); } } } } }