/** * Get the associated IndicatorsSc object * * @param PropelPDO Optional Connection object. * @return IndicatorsSc The associated IndicatorsSc object. * @throws PropelException */ public function getIndicatorsSc(PropelPDO $con = null) { if ($this->aIndicatorsSc === null && $this->indicador_id !== null) { $this->aIndicatorsSc = IndicatorsScPeer::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->aIndicatorsSc->addAsignacionScs($this); */ } return $this->aIndicatorsSc; }
private function getIndicatorScData($indicator_sc_id) { $nodo = IndicatorsScPeer::retrieveByPk($indicator_sc_id); $det_net_attr_id = $nodo->getDetNetworkAttributeId(); $network_id = $nodo->getDetNetworkAttribute()->getNetworkId(); $usernameInNetwork = $nodo->getUsernameInNetwork(); $atributo = DetNetworkAttributePeer::retrieveByPK($det_net_attr_id); $keyword = $atributo->getAttribute()->getKeyWord(); $resp = 0; if ($network_id == '1') { /* Facebook */ $json_string = @file_get_contents("http://graph.facebook.com/" . $usernameInNetwork . "/"); if ($json_string === FALSE) { $resp = 0; } else { $json = json_decode($json_string); if (isset($json->{$keyword})) { if ($json->{$keyword} != '') { $resp = $json->{$keyword}; } else { $resp = 0; } } else { $resp = 0; } } } elseif ($network_id == '2') { /* Twitter */ $xml_string = @file_get_contents("http://api.twitter.com/1/users/show.xml?screen_name=" . $usernameInNetwork); if ($xml_string === FALSE) { $resp = 0; } else { $xml = simplexml_load_string($xml_string); if (isset($xml->{$keyword})) { if ($xml->{$keyword} != '') { $resp = $xml->{$keyword}; } else { $resp = 0; } } else { $resp = 0; } } } elseif ($network_id == '3') { /* Google Analytics */ $access_token = $this->useRefreshToken($nodo->getId()); if ($access_token != null) { $postdata = http_build_query(array('ids' => $usernameInNetwork, 'metrics' => $keyword, 'start-date' => $nodo->getGaFecFin(), 'end-date' => date("Y-m-d"), 'max-results' => '1', 'access_token' => $access_token)); $xml_string = @file_get_contents("https://www.google.com/analytics/feeds/data" . "?" . $postdata); if ($xml_string === FALSE) { $resp = 0; } else { $xml = simplexml_load_string($xml_string); if (isset($xml->entry)) { $metrics = $xml->entry->xpath("dxp:metric"); if ($metrics[0]['value'] != '') { $resp = $metrics[0]['value']; } else { $resp = 0; } } else { $resp = 0; } } } else { $resp = 0; } } return $resp; }