public function addDataIndicatores($indicadorBean)
 {
     $criteria = new Criteria();
     $criteria->add(GroupDataIndicadoresPeer::TREE_ID, $indicadorBean->getTreeId());
     $listGrupo = GroupDataIndicadoresPeer::doSelect($criteria);
     foreach ($listGrupo as $row) {
         $dataIndicador = new DataIndicadores();
         $dataIndicador->setIndicadorId($indicadorBean->getId());
         $dataIndicador->setUserId($indicadorBean->getResponsableId());
         $dataIndicador->setData(0);
         $dataIndicador->setGroupData($row->getId());
         $dataIndicador->setCreateAt($row->getCreateAt());
         $dataIndicador->setUpdateAt($row->getCreateAt());
         $dataIndicador->save();
     }
     return array("success" => true, "message" => "exito");
 }
 /**
  * Declares an association between this object and a DataIndicadores object.
  *
  * @param      DataIndicadores $v
  * @return     AuditDataIndicadores The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setDataIndicadores(DataIndicadores $v = null)
 {
     if ($v === null) {
         $this->setIndicadorId(NULL);
     } else {
         $this->setIndicadorId($v->getId());
     }
     $this->aDataIndicadores = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the DataIndicadores object, it will not be re-added.
     if ($v !== null) {
         $v->addAuditDataIndicadores($this);
     }
     return $this;
 }
 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);
                 }
             }
         }
     }
 }
 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;
     }
 }
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      DataIndicadores $value A DataIndicadores object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(DataIndicadores $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }