public function updateDataIndicadores($idTree)
 {
     $criterio = new Criteria();
     $criterio->add(IndicatorsScPeer::TREE_ID, $idTree);
     $criterio->add(IndicatorsScPeer::ULTIMO_NODO, 1, Criteria::NOT_EQUAL);
     $listIndicadores = IndicatorsScPeer::doSelect($criterio);
     $countListIndicadores = IndicatorsScPeer::doCount($criterio);
     if ($countListIndicadores > 0) {
         foreach ($listIndicadores as $row) {
             $criteria = new Criteria();
             $criteria->add(DataIndicadoresPeer::INDICADOR_ID, $row->getId());
             DataIndicadoresPeer::doDelete($criteria);
         }
     }
     return array("success" => true, "message" => "exito");
 }
 private function fn_EliminarIndicadores($treeId)
 {
     /*Para eliminar indicadores por cada indicador*/
     $criteria = new Criteria();
     $criteria->add(IndicatorsScPeer::TREE_ID, $treeId);
     $listaIndicadores = IndicatorsScPeer::doSelect($criteria);
     if (count($listaIndicadores) > 0) {
         foreach ($listaIndicadores as $indicador) {
             //hay que buscar la dataIndicadores y eliminarlas
             $criteriaDataIndicadores = new Criteria();
             $criteriaDataIndicadores->add(DataIndicadoresPeer::INDICADOR_ID, $indicador->getId());
             DataIndicadoresPeer::doDelete($criteriaDataIndicadores);
             //hay que buscar las proyecciones y eliminarlas
             $criteriaProyecciones = new Criteria();
             $criteriaProyecciones->add(ProjectionsIndicatorsCsPeer::INDICADOR_ID, $indicador->getId());
             ProjectionsIndicatorsCsPeer::doDelete($criteriaProyecciones);
         }
         //acabado la eliminacion se procede a eliminar los indicadores
         IndicatorsScPeer::doDelete($criteria);
     }
 }
 public function returnCol_model($user, $indicator)
 {
     $criterio_busqueda = new Criteria();
     $criterio_busqueda->add(TreeScPeer::ID, $indicator[1]);
     $tree = TreeScPeer::doSelectOne($criterio_busqueda);
     $criterio_busqueda->clear();
     $criterio_busqueda->add(DataIndicadoresPeer::USER_ID, $user->getId());
     //    $criterio_busqueda->add(DataIndicadoresPeer::PERIODO_ID,$tree->getPeriodoId());
     $criterio_busqueda->add(DataIndicadoresPeer::INDICADOR_ID, $indicator[0]);
     $list = DataIndicadoresPeer::doSelect($criterio_busqueda);
     $var = "[";
     $var = $var . "{name:'name',index:'name', width:180, sorttype:'text',editable: false},{";
     $cantidad = 1;
     foreach ($list as $data) {
         $var = $var . "name:'f" . $cantidad . "',index:'f" . $cantidad . "',width:100,editable: true , editrules:{required:true,number:true} },";
         $var = $var . "{name:'idfecha" . $cantidad . "',index:'idfecha" . $cantidad . "',width:100,editable: true,hidden:true },{";
         $cantidad++;
     }
     $var = substr($var, 0, strlen($var) - 2) . ']';
     return $var;
 }
 public function executeAjax_mostrar_tree(sfWebRequest $request)
 {
     $user = $this->getUser()->getAttribute(sfConfig::get('app_session_current_user'), null);
     $id_tree = $request->getParameter('tree');
     if ($user != null) {
         $criterio = new Criteria();
         $criterio->add(TreeScPeer::USER_ID, $user->getId());
         $criterio->add(TreeScPeer::PRODUCCION, '%production%', Criteria::LIKE);
         $criterio->add(TreeScPeer::ID, $id_tree);
         $tree = TreeScPeer::doSelectOne($criterio);
         $criterio->clear();
         if (is_object($tree)) {
             $criterio->add(IndicatorsScPeer::TREE_ID, $tree->getId());
             $criterio->add(IndicatorsScPeer::FLAG, '%habilitado%', Criteria::LIKE);
             $criterio->addAscendingOrderByColumn(IndicatorsScPeer::PREVIOUS_ID);
             $list_indicadores = IndicatorsScPeer::doSelect($criterio);
             $this->lista_indicadores = $list_indicadores;
             $this->tree = $tree;
             /* con esto obtengo la fecha de proyeccion actual 
              */
             $criteria = new Criteria();
             $criteria->add(IndicatorsScPeer::TREE_ID, $tree->getId());
             $criteria->addJoin(IndicatorsScPeer::ID, DataIndicadoresPeer::INDICADOR_ID);
             $criteria->addDescendingOrderByColumn(DataIndicadoresPeer::CREATE_AT);
             $proyeccion = DataIndicadoresPeer::doSelectOne($criteria);
             $this->fechaProyeccion = $proyeccion->getCreateAt();
         } else {
             return sfView::ERROR;
         }
         return sfView::SUCCESS;
     } else {
         return sfView::ERROR;
     }
 }
 public function executeAjax_show_records_indicators(sfWebRequest $request)
 {
     //recojo el id del indicador para este caso es ultimo de lo contrario arrojara un mensaje de error
     $id_indicators = $request->getParameter('id_indicators');
     //Se elimina todos los registros de las dos tablas temporales.
     TmpDataReportsPeer::doDeleteAll();
     TmpTreeScPeer::doDeleteAll();
     //verifico es ultimo nodo
     $criteria = new Criteria();
     $criteria->add(IndicatorsScPeer::ID, $id_indicators);
     $indicators = IndicatorsScPeer::doSelectOne($criteria);
     $criteria->clear();
     if (is_object($indicators)) {
         $this->indicator = $indicators;
         //obtengo los indicadores que son los ultimos nodos
         $criteria->add(IndicatorsScPeer::TREE_ID, $indicators->getTreeId());
         $criteria->add(IndicatorsScPeer::ULTIMO_NODO, '1', Criteria::LIKE);
         $list_last_indicators = IndicatorsScPeer::doSelect($criteria);
         $criteria->clear();
         $this->list_last_indicators = $list_last_indicators;
         //----------> lista de los indicadores que son ultimos nodos
         // obtengo la cantidad de registros que tiene en la tabla 'data_indicadores'
         //verifico si el indicador es  ultimo nodo
         foreach ($list_last_indicators as $obj_id_indicators) {
             if ($obj_id_indicators->getId() == $id_indicators) {
                 //si el id del indicador que estoy buscando es igual a uno de los ultimos nodos
                 $id = $obj_id_indicators->getId();
                 break;
             }
             $id = null;
         }
         if ($id != null) {
             // si es ultimo nodo
             //Verifico la cantidad de rows que tiene
             $criteria->add(DataIndicadoresPeer::INDICADOR_ID, $id);
             $rows_in_data_indicadores = DataIndicadoresPeer::doCount($criteria);
             if ($rows_in_data_indicadores > 0) {
                 $object_rows = DataIndicadoresPeer::doSelect($criteria);
                 $this->indicator = $indicators;
                 $this->object_rows = $object_rows;
                 $criteria->clear();
             }
         } else {
             // si el indicador no es ultimo nodo
             //obtengo el numero de registros que tiene la tabla 'data_indicadores'
             foreach ($list_last_indicators as $obj_last_indicators) {
                 $obj_evaluado = $obj_last_indicators;
                 //---> solo me hace falta obtener un indicador de esa lista para saber la cantidad de registros
                 break;
             }
             //verifico los registros ingresados por ese indicador
             $criteria->add(DataIndicadoresPeer::INDICADOR_ID, $obj_evaluado->getId());
             // $rows_in_data_indicadores = DataIndicadoresPeer::doCount($criteria);
             //1) saco la informacion de los registros
             //2) $obj_evaluado->getId() ----->este ID esta en muchos registros
             $rows_in_data_indicadores = DataIndicadoresPeer::doCount($criteria);
             //------>numero de registros
             $data_indicators = DataIndicadoresPeer::doSelect($criteria);
             //---> obtengo los registros por cada ID
             // efectuo el for para replicar el arbol y llenar los valores de cada indicador
             if ($rows_in_data_indicadores > 0) {
                 //realizo el for con el numero de registros
                 //    for($i=0; $i<$rows_in_data_indicadores ; $i++){
                 $data_list_grafico = null;
                 foreach ($data_indicators as $reg_indicators) {
                     $criteria->clear();
                     $criteria->add(DataIndicadoresPeer::GROUP_DATA, $reg_indicators->getGroupData());
                     //---> BUSCO EL PRIMER GRUPO DE DATOS
                     $data_util_graficos = DataIndicadoresPeer::doSelect($criteria);
                     $lista_relaciones = null;
                     //obtengo el id del arbol creado en temporal
                     $array_result = $this->executeEspejo_reportes($indicators->getTreeId(), $data_util_graficos, $reg_indicators->getUpdateAt());
                     $id_tmp_creado = $array_result['array'];
                     $lista_relaciones = $array_result['lista'];
                     //obtengo los ultmimos nodos pero de los indicadores que estan creados en la tabla temporal
                     $criteria->add(TmpDataReportsPeer::TREE_ID, $id_tmp_creado);
                     $criteria->add(TmpDataReportsPeer::ULTIMO_NODO, '1', Criteria::LIKE);
                     $list_tmp_last_indicators = TmpDataReportsPeer::doSelect($criteria);
                     //----> lista de los ultimos nodos de la tabla tmp
                     //$list_relation = null;
                     foreach ($list_tmp_last_indicators as $ob) {
                         $this->recalculate_tree($ob);
                     }
                     //obtengo el id del indicador relacionado
                     $id_relation = $this->return_relation_id($lista_relaciones, $indicators->getId());
                     //busco en la tabla temporal por el id
                     $data_list_grafico[] = $id_relation;
                 }
                 //envio datos para el grafico
                 $criteria->clear();
                 $criteria->add(TmpDataReportsPeer::INDICADOR_ID, $indicators->getId());
                 $list_indicators_reports = TmpDataReportsPeer::doSelect($criteria);
                 //  }
             }
             $this->indicator = $indicators;
             $this->object_rows = $list_indicators_reports;
         }
     } else {
         // $this->indicators = null;
         $this->list_last_indicators = null;
         $this->object_rows = null;
     }
 }
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this UserSc is new, it will return
  * an empty collection; or if this UserSc has previously
  * been saved, it will retrieve related DataIndicadoress from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in UserSc.
  */
 public function getDataIndicadoressJoinGroupDataIndicadores($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     if ($criteria === null) {
         $criteria = new Criteria(UserScPeer::DATABASE_NAME);
     } elseif ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
     }
     if ($this->collDataIndicadoress === null) {
         if ($this->isNew()) {
             $this->collDataIndicadoress = array();
         } else {
             $criteria->add(DataIndicadoresPeer::USER_ID, $this->id);
             $this->collDataIndicadoress = DataIndicadoresPeer::doSelectJoinGroupDataIndicadores($criteria, $con, $join_behavior);
         }
     } else {
         // the following code is to determine if a new query is
         // called for.  If the criteria is the same as the last
         // one, just return the collection.
         $criteria->add(DataIndicadoresPeer::USER_ID, $this->id);
         if (!isset($this->lastDataIndicadoresCriteria) || !$this->lastDataIndicadoresCriteria->equals($criteria)) {
             $this->collDataIndicadoress = DataIndicadoresPeer::doSelectJoinGroupDataIndicadores($criteria, $con, $join_behavior);
         }
     }
     $this->lastDataIndicadoresCriteria = $criteria;
     return $this->collDataIndicadoress;
 }
 /**
  * Selects a collection of AuditDataIndicadores objects pre-filled with all related objects.
  *
  * @param      Criteria  $criteria
  * @param      PropelPDO $con
  * @param      String    $join_behavior the type of joins to use, defaults to Criteria::LEFT_JOIN
  * @return     array Array of AuditDataIndicadores objects.
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function doSelectJoinAll(Criteria $criteria, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $criteria = clone $criteria;
     // Set the correct dbName if it has not been overridden
     if ($criteria->getDbName() == Propel::getDefaultDB()) {
         $criteria->setDbName(self::DATABASE_NAME);
     }
     AuditDataIndicadoresPeer::addSelectColumns($criteria);
     $startcol2 = AuditDataIndicadoresPeer::NUM_COLUMNS - AuditDataIndicadoresPeer::NUM_LAZY_LOAD_COLUMNS;
     DataIndicadoresPeer::addSelectColumns($criteria);
     $startcol3 = $startcol2 + (DataIndicadoresPeer::NUM_COLUMNS - DataIndicadoresPeer::NUM_LAZY_LOAD_COLUMNS);
     $criteria->addJoin(AuditDataIndicadoresPeer::INDICADOR_ID, DataIndicadoresPeer::ID, $join_behavior);
     // symfony_behaviors behavior
     foreach (sfMixer::getCallables(self::getMixerPreSelectHook(__FUNCTION__)) as $sf_hook) {
         call_user_func($sf_hook, 'BaseAuditDataIndicadoresPeer', $criteria, $con);
     }
     $stmt = BasePeer::doSelect($criteria, $con);
     $results = array();
     while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $key1 = AuditDataIndicadoresPeer::getPrimaryKeyHashFromRow($row, 0);
         if (null !== ($obj1 = AuditDataIndicadoresPeer::getInstanceFromPool($key1))) {
             // We no longer rehydrate the object, since this can cause data loss.
             // See http://propel.phpdb.org/trac/ticket/509
             // $obj1->hydrate($row, 0, true); // rehydrate
         } else {
             $cls = AuditDataIndicadoresPeer::getOMClass(false);
             $obj1 = new $cls();
             $obj1->hydrate($row);
             AuditDataIndicadoresPeer::addInstanceToPool($obj1, $key1);
         }
         // if obj1 already loaded
         // Add objects for joined DataIndicadores rows
         $key2 = DataIndicadoresPeer::getPrimaryKeyHashFromRow($row, $startcol2);
         if ($key2 !== null) {
             $obj2 = DataIndicadoresPeer::getInstanceFromPool($key2);
             if (!$obj2) {
                 $cls = DataIndicadoresPeer::getOMClass(false);
                 $obj2 = new $cls();
                 $obj2->hydrate($row, $startcol2);
                 DataIndicadoresPeer::addInstanceToPool($obj2, $key2);
             }
             // if obj2 loaded
             // Add the $obj1 (AuditDataIndicadores) to the collection in $obj2 (DataIndicadores)
             $obj2->addAuditDataIndicadores($obj1);
         }
         // if joined row not null
         $results[] = $obj1;
     }
     $stmt->closeCursor();
     return $results;
 }
 /**
  * Get the associated DataIndicadores object
  *
  * @param      PropelPDO Optional Connection object.
  * @return     DataIndicadores The associated DataIndicadores object.
  * @throws     PropelException
  */
 public function getDataIndicadores(PropelPDO $con = null)
 {
     if ($this->aDataIndicadores === null && $this->indicador_id !== null) {
         $this->aDataIndicadores = DataIndicadoresPeer::retrieveByPk($this->indicador_id);
         /* The following can be used additionally to
         		   guarantee the related object contains a reference
         		   to this object.  This level of coupling may, however, be
         		   undesirable since it could result in an only partially populated collection
         		   in the referenced object.
         		   $this->aDataIndicadores->addAuditDataIndicadoress($this);
         		 */
     }
     return $this->aDataIndicadores;
 }
 private function verificar_insert_data($tree)
 {
     $tree = new TreeSc();
     $tree->getPeriodoId();
     //cada 15 dias
     $criterio = new Criteria();
     $criterio->add(IndicatorsScPeer::FLAG, '%habilitado%', Criteria::LIKE);
     $criterio->add(IndicatorsScPeer::TREE_ID, $tree->getId());
     $indicador = IndicatorsScPeer::doSelectOne($criterio);
     $criterio->clear();
     $criterio->add(DataIndicadoresPeer::INDICADOR_ID, $indicador->getId());
     $criterio->addDescendingOrderByColumn(DataIndicadoresPeer::CREATE_AT);
     $data = DataIndicadoresPeer::doSelectOne($criterio);
     $criterio = new Criteria();
     $criterio->add(DataIndicadoresPeer::INDICADOR_ID, 24);
     $criterio->addDescendingOrderByColumn(DataIndicadoresPeer::CREATE_AT);
     $data = DataIndicadoresPeer::doSelectOne($criterio);
     $ultima_de_fecha_registro = new DateTime($data->getCreateAt());
     $ultima_de_fecha_registro = $ultima_de_fecha_registro->format('Y-m-d');
     $array = explode('-', $ultima_de_fecha_registro);
     $fecha_actual = mktime(0, 0, 0, date('m'), date("d"), date('Y'));
     $fecha_actual = date('Y-m-d', $fecha_actual);
     /* if($fecha_proyectada<=$fecha_actual){}*/
     //semanal
     if ($tree->getPeriodoId() == 1) {
         $fecha_proyectada = mktime(0, 0, 0, $array[1], $array[2] + 7, $array[0]);
         $fecha_proyectada = date('Y-m-d', $fecha_proyectada);
         //cada quincena
     } elseif ($tree->getPeriodoId() == 2) {
         //si el dia de ultimo registro en menos a quince
         //busco el 15 de ese mes
         if ($array[2] < 15) {
             //la fecha programada es:
             $fecha_proyectada = $this->obtener_fecha_por_dia(15);
         } else {
             $fecha_proyectada = $this->obtener_fecha_por_dia(1);
         }
         //cada bimestre
     } elseif ($tree->getPeriodoId() == 3) {
         $fecha_proyectada = mktime(0, 0, 0, $array[1], $array[2] + 0, $array[0]);
         $fecha_proyectada = date('Y-m-d', $fecha_proyectada);
         //cada trimestre
     } else {
         $fecha_proyectada = mktime(0, 0, 0, $array[1], $array[2] + 0, $array[0]);
         $fecha_proyectada = date('Y-m-d', $fecha_proyectada);
     }
 }
 private function executeBuscar_anterior($dataBean)
 {
     $criterio_busqueda = new Criteria();
     $criterio_busqueda->add(DataIndicadoresPeer::INDICADOR_ID, $dataBean->getIndicadorId());
     $list_data = DataIndicadoresPeer::doSelect($criterio_busqueda);
     if (count($list_data) > 0) {
         //si hay un solo registro no hay anterior
         if (count($list_data) == 1) {
             return null;
             //no hay anterior
         } else {
             //vamos verificar si el el primero
             if ($list_data[0]->getId() == $dataBean->getId()) {
                 return null;
                 //no hay anterior
             } else {
                 $contador = 0;
                 foreach ($list_data as $row) {
                     if ($row->getId() == $dataBean->getId()) {
                         return $list_data[$contador - 1];
                     }
                     $contador++;
                 }
                 return null;
             }
         }
     } else {
         return null;
         //no hay anterior
     }
 }
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = DataIndicadoresPeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setIndicadorId($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setUserId($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setData($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setGroupData($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setCreateAt($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setUpdateAt($arr[$keys[6]]);
     }
 }
 public function executeSave(sfWebRequest $request)
 {
     for ($i = 1; $i < 10; $i++) {
         $id_data = $request->getParameter('idfecha' . $i);
         if ($id_data != "") {
             $data = DataIndicadoresPeer::retrieveByPK($id_data);
             if ($data->getData() != $request->getParameter('f' . $i)) {
                 $data->setData($request->getParameter('f' . $i));
                 $data->save();
                 //aca verificamos si el ultimo registro
                 $rpt = $this->is_the_last_record($data);
                 if ($rpt) {
                     $indicador = IndicatorsScPeer::retrieveByPK($data->getIndicadorId());
                     if (is_object($indicador)) {
                         $indicador->setValorActualEntregado($request->getParameter('f' . $i));
                         $indicador->save();
                     }
                     $criterio = new Criteria();
                     $criterio->add(IndicatorsScPeer::TREE_ID, $indicador->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) {
                         $var = $this->recalcular($row);
                     }
                     //set a los valores de actuales de los indicadores
                 }
             }
         }
     }
 }
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(DataIndicadoresPeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(DataIndicadoresPeer::DATABASE_NAME);
         $criteria->add(DataIndicadoresPeer::ID, $pks, Criteria::IN);
         $objs = DataIndicadoresPeer::doSelect($criteria, $con);
     }
     return $objs;
 }