/** * returns the document manager for the main db * * @return Doctrine\ODM\MongoDB\DocumentManager */ public static function getDM() { if (null === self::$document_manager) { self::$document_manager = self::instantiateDocumentManager(); } return self::$document_manager; }
/** * send notification */ public function execute() { // normal google hub \PubSubHubbub::push("http://pubsubhubbub.appspot.com/", "hub.mode=publish&hub.url=" . urlencode("http://api." . \sfConfig::get("app_settings_host") . "/feeds/global")); \PubSubHubbub::push("http://pubsubhubbub.superfeedr.com/", "hub.mode=publish&hub.url=" . urlencode("http://api." . \sfConfig::get("app_settings_host") . "/feeds/global")); // @todo googles Social Data Hub // \PubSubHubbub::push("http://pshbsubber.appspot.com/sub/spreadly", "", array("X-Hub-Signature" => "sha1=secret_checksum")); $dm = \MongoManager::getDM(); $ya = $dm->getRepository("Documents\\YiidActivity")->find(new \MongoId($this->getYiidActivityId())); if (!$ya) { return false; } // send webmentions or pingbacks $mc = new \MentionClient(\sfConfig::get('app_settings_my_url') . "/share/" . $ya->getId()); $mc->sendSupportedMentions($ya->getUrl()); $dp = $ya->getDomainProfile(); if (!$dp) { return false; } $ds = $dp->getDomainSubscriptions(); if (!$ds) { return false; } foreach ($ds as $s) { $info = \PubSubHubbub::push($s->getCallback(), $this->toJson($ya), array("Content-Type: application/json")); // all good -- anything in the 200 range if (substr($info['http_code'], 0, 1) == "2") { $this->finished(); } elseif ($info['http_code'] == 408) { $this->reschedule(array("code" => 408, "message" => "Server Timeout")); } else { $this->failed(array("code" => $info['http_code'], "message" => "PuSH failed")); } } }
public function executeInitiator_stats(sfWebRequest $request) { $lDeal = DealTable::getInstance()->find($request->getParameter('deal_id')); //var_dump($lDeal->getId()); $dm = MongoManager::getStatsDM(); $this->aas = $dm->getRepository('Documents\\AnalyticsActivity')->findBy(array("d_id" => intval($lDeal->getId()))); }
/** * Executes delete action * * @param sfRequest $request A request object */ public function executeDelete(sfWebRequest $request) { $id = $request->getParameter("id"); if ($ad = MongoManager::getDm()->getRepository('Documents\\Advertisement')->findOneBy(array("id" => $id))) { $ad->delete(); } $this->redirect("advertisement/index"); }
public function executeAtom_feed($request) { $id = $request->getParameter("id"); $user = UserTable::retrieveByUsername($id); $this->forward404Unless($user); $this->activities = MongoManager::getDM()->getRepository('Documents\\YiidActivity')->findLatestByUserId($user->getId()); $this->user = $user; $this->setLayout("atom_layout"); }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $analytics_activity = MongoManager::getStatsDM()->getRepository('Documents\\AnalyticsActivity'); $this->activities = $analytics_activity->findBy(array("user_id" => intval($this->getUser()->getUserId())))->limit(30)->sort(array("cb" => "DESC")); $this->likes_complete = $analytics_activity->findBy(array("user_id" => intval($this->getUser()->getUserId())))->count(); $this->clickbacks_complete = $analytics_activity->getOverallClickbacks($this->getUser()->getUserId()); $q = Doctrine_Query::create(); $q->addWhere("tg.taggable_id = ?", array($this->getUser()->getUserId())); $this->tags = PluginTagTable::getAllTagNameWithCount($q, array("model" => "User", "limit" => 100)); }
public function executeCoupon(sfWebRequest $request) { $this->getResponse()->setSlot('js_document_ready', $this->getPartial('deal/js_init_deal.js')); $dm = MongoManager::getDM(); $activity = $dm->getRepository('Documents\\YiidActivity')->find($request->getParameter('id')); if ($activity) { $this->deal = $activity->getDeal(); } else { $this->setTemplate('default_deal'); } }
public function executeUser($request) { $id = $request->getParameter("id"); $user = sfGuardUserTable::getInstance()->retrieveByUsernameOrEmailAddress($id); $this->forward404Unless($user); $hosts = array(); foreach ($user->getDomainProfiles() as $domain_profile) { $hosts[] = $domain_profile->getUrl(); } $lDm = MongoManager::getStatsDM(); $this->activities = $lDm->createQueryBuilder("Documents\\AnalyticsActivity")->field("host")->in($hosts)->sort(array("date" => -1))->limit(10)->getQuery()->execute(); $this->user = $user; $this->setLayout("atom_layout"); }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeHost(sfWebRequest $request) { $social_object = MongoManager::getDM()->getRepository('Documents\\SocialObject'); $this->forward404Unless($request->getParameter("id")); $so = $social_object->find(new MongoId($request->getParameter("id"))); $this->forward404Unless($so); $this->social_object = $so; $this->social_objects = $social_object->findBy(array("url" => array('$regex' => parse_url($so->getUrl(), PHP_URL_HOST))))->limit(10)->sort(array("u" => -1)); $this->first_share = MongoManager::getStatsDM()->getRepository('Documents\\AnalyticsActivity')->findBy(array("host" => parse_url($so->getUrl(), PHP_URL_HOST)))->sort(array("date" => 1))->limit(1)->getNext(); $this->last_share = MongoManager::getStatsDM()->getRepository('Documents\\AnalyticsActivity')->findBy(array("host" => parse_url($so->getUrl(), PHP_URL_HOST)))->sort(array("date" => -1))->limit(1)->getNext(); $us = MongoManager::getStatsDM()->getRepository('Documents\\UrlSummary'); $this->url_summarys = $us->findBy(array("host" => parse_url($so->getUrl(), PHP_URL_HOST)))->limit(10)->sort(array("mp" => -1)); $hs = MongoManager::getStatsDM()->getRepository('Documents\\HostSummary'); $this->host_summary = $hs->findOneBy(array("host" => parse_url($so->getUrl(), PHP_URL_HOST))); }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $lUrl = $request->getParameter("url", null); $lUrl = UrlUtils::narmalizeUrlScheme($lUrl); $request->setParameter("url", $lUrl); $this->url = $lUrl; $this->error = $this->pError = null; if (!$lUrl) { return $this->setTemplate("share"); } if ($request->getMethod() == "POST") { $lParams = $request->getParameter('like'); $lParams['u_id'] = $this->getUser()->getUserId(); $lActivity = new Documents\YiidActivity(); $lActivity->fromArray($lParams); // try to save activity try { $lActivity->save(); $this->redirect("@deal?url=" . urlencode($lUrl)); } catch (Exception $e) { // send error on exception $this->getLogger()->err($e->getMessage()); $this->pError = $e->getMessage(); } } $dm = MongoManager::getDM(); $this->pActivity = $dm->getRepository("Documents\\YiidActivity")->findOneBy(array("url" => $lUrl, "u_id" => intval($this->getUser()->getId()), "d_id" => array('$exists' => false))); // if user has already liked if ($this->pActivity) { $this->redirect("@deal?url=" . urlencode($lUrl)); } $lYiidMeta = new YiidMeta(); $lYiidMeta->fromParams($request->getParameterHolder()); $this->pYiidMeta = SocialObjectParser::fetch($request->getParameter("url"), $lYiidMeta); if ($this->pYiidMeta === false) { $this->error = "the url '{$lUrl}' is not well formed!"; return $this->setTemplate("share"); } $domainProfile = DomainProfileTable::getInstance()->retrieveByUrl($lUrl); $this->trackingUrl = null; if ($domainProfile) { $this->trackingUrl = $domainProfile->getTrackingUrl(); } $this->getResponse()->setSlot('js_document_ready', $this->getPartial('like/js_init_like.js', array('pImgCount' => count($this->pYiidMeta->getImages()), 'pUrl' => $request->getParameter("url")))); }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeCounter(sfWebRequest $request) { $this->getResponse()->setContentType('application/json'); $this->setLayout(false); $url = $request->getParameter("url", null); if (!$url) { $this->getResponse()->setStatusCode(409); return sfView::ERROR; } $dm = MongoManager::getDM(); $social_object = $dm->getRepository("Documents\\SocialObject")->findOneByUrl($url); if ($social_object) { $this->getResponse()->setStatusCode(200); $this->response_array = array("success" => array("code" => 200, "message" => "URL shared"), "counter" => $social_object->getLikeCount()); } else { $this->getResponse()->setStatusCode(204); $this->response_array = array("success" => array("code" => 204, "message" => "URL not yet shared"), "counter" => 0); } }
/** * * * */ public function executeWidget(sfWebRequest $request) { // $url = $request->getParameter("url"); $this->url = $url; // extract host $host = parse_url($url, PHP_URL_HOST); // get most liked urls of the last 30 days /*url_repo = MongoManager::getStatsDM()->getRepository('Documents\ActivityUrlStats'); $this->last30 = $url_repo->findLast30OrderedAndLimited(array($host), 5); if($this->last30) { $this->last30 = $this->last30->toArray(); }*/ $this->urls = MongoManager::getStatsDM()->getRepository('Documents\\AnalyticsActivity')->findLatestByHost($host, 6); // get latest users that liked one of the urls $this->activities = MongoManager::getStatsDM()->getRepository('Documents\\AnalyticsActivity')->findLatestByHost($host, 9); // disable layout $this->setLayout(false); }
public function executeGet_url_detail_by_range(sfWebRequest $request) { $this->getResponse()->setContentType('application/json'); $from = $request->getParameter("date-from"); $to = $request->getParameter("date-to"); $lDm = MongoManager::getStatsDM(); $lUrlSummary = $lDm->getRepository("Documents\\ActivityUrlStats")->findByUrlsAndRange(array($this->pUrl), $from, $to); if ($lUrlSummary) { $lUrlSummary = $lUrlSummary->toArray(); if (count($lUrlSummary) > 1) { $lUrlSummary = $lUrlSummary[0]; } } $lUrls = $lDm->getRepository("Documents\\AnalyticsActivity")->findBy(array("url" => $this->pUrl, "day" => array('$gte' => new MongoDate(strtotime($from)), '$lte' => new MongoDate(strtotime($to))))); $lUrlsRange = $lDm->getRepository("Documents\\ActivityUrlStats")->findBy(array("url" => $this->pUrl, "day" => array('$gte' => new MongoDate(strtotime($from)), '$lte' => new MongoDate(strtotime($to))))); $lUrlsRange = $lUrlsRange->toArray(); $lLikesRange = array_values($this->padLikes($lUrlsRange, $from, $to)); $lReturn['content'] = $this->getPartial('analytics/url_detail_content_by_range', array('pUrl' => $this->pUrl, 'pUrls' => $lUrls, 'pUrlSummary' => $lUrlSummary, 'pDomainProfile' => $this->pDomainProfile, 'showdate' => $from . '-' . $to, 'pLikes' => $lLikesRange, 'pStartDay' => $from, 'showdate' => format_date(strtotime($from)) . ' to ' . format_date(strtotime($to)))); return $this->renderText(json_encode($lReturn)); }
public function executeSubscribe_api(sfWebRequest $request) { $dm = MongoManager::getDM(); $this->pHostId = $request->getParameter('host_id'); $this->pDomainProfile = Doctrine::getTable('DomainProfile')->find($this->pHostId); //gibt es nen endpoint? sollte mit in domain-profile-object und muss auch in index für die tabelle gesetzt sein pro domain-profile $this->pEndpoint = DomainSubscriptionsTable::getInstance()->findOneBy("domain_profile_id", $this->pDomainProfile->getId()); $this->pOk = $dm->getRepository("Documents\\PushJob")->countValidPuSHsLast24h($this->pHostId); $this->pTimeout = $dm->getRepository("Documents\\PushJob")->countTimeoutPuSHsLast24h($this->pHostId); $this->pResponseFail = $dm->getRepository("Documents\\PushJob")->countFailedPuSHsLast24h($this->pHostId); }
public function getLatestYiidActivity() { return \MongoManager::getDM()->getRepository("Documents\\YiidActivity")->findOneBy(array('social_object.$id' => new \MongoId($this->getId()))); }
/** * Executes index action * * @param sfRequest $request A request object */ public function executeIndex(sfWebRequest $request) { $lDm = MongoManager::getDM(); $this->pErrors = $lDm->createQueryBuilder("Documents\\ApiErrorLog")->find()->sort(array("c" => -1))->limit(30)->getQuery()->execute(); }
<?php /** * a batch file to send an email if a deal is expired * * @author Matthias Pfefferle */ require_once dirname(__FILE__) . '/../../config/ProjectConfiguration.class.php'; $configuration = ProjectConfiguration::getApplicationConfiguration('statistics', 'dev', false); sfContext::createInstance($configuration); $dm = MongoManager::getDM(); $logger = sfContext::getInstance()->getLogger(); $deals = DealTable::getInstance()->getExpiredDealsByExpirationDate(); $message = null; foreach ($deals as $deal) { $message .= "http://spreadly.com/backend.php/deal/" . $deal->getId() . "/edit \n"; } if ($message) { sfContext::getInstance()->getMailer()->composeAndSend($sender = array(sfConfig::get("app_email_address") => sfConfig::get("app_email_sender")), sfConfig::get("app_settings_support_email"), '[expired deals]', $message); }
/** * Executes delete action * * @param sfRequest $request A request object */ public function executeDelete(sfWebRequest $request) { $id = $request->getParameter("id"); if ($ds = MongoManager::getDm()->getRepository('Documents\\DomainSettings')->findOneBy(array("id" => $id))) { $ds->delete(); } $this->redirect("domain_settings/index"); }
/** * Applies the alarming attribute to a given query retrieving products. * * @param Doctrine_Query $query - query to have alarming attribute applied. * @param Integer $value - alarming? */ public function applyDealIdFilter($query, $value) { $rootAlias = $query->getRootAlias(); $dm = MongoManager::getDM(); $yas = $dm->getRepository('Documents\\YiidActivity')->findBy(array('d_id' => intval($value))); $user_ids = array(); foreach ($yas as $ya) { $user_ids[] = $ya->getUId(); } $user_ids = array_unique($user_ids); if (count($user_ids) == 0) { $user_ids[] = -1; } $query->whereIn($rootAlias . '.id', $user_ids); return $query; }
public function executeRemoveJobs(sfWebRequest $request) { $dm = MongoManager::getDm(); $dm->createQueryBuilder('Documents\\Job')->remove()->getQuery()->execute(); return $this->redirect('job/index'); }
/** * Get the MongoDB database object. */ public static function get_database() { $conn = MongoManager::get_connection(); if (!$conn) { return false; } return $conn->{conf('Mongo', 'name')}; }
/** * A nicer way to delete the object */ public function delete() { $dm = \MongoManager::getDM(); $dm->remove($this); $dm->flush(); }
public function getYiidActivity() { $dm = \MongoManager::getDM(); return $dm->getRepository("Documents\\YiidActivity")->find(new \MongoId($this->getYiidActivityId())); }
public function getSpreadCount() { $yiid_activity_repo = MongoManager::getDM()->getRepository('Documents\\YiidActivity'); return $yiid_activity_repo->countByOnlineIdentityIds(array($this->getId())); }
/** * Imports all likes from a facebook account to store it in the mongodb * * @param int $online_identity */ public static function importInterests($online_identity) { $token = AuthTokenTable::getByUserAndOnlineIdentity($online_identity->getUserId(), $online_identity->getId()); if (!$token) { $online_identity->deactivate(); throw new Exception('damn theres no token!', '666'); } // get likes $response = UrlUtils::sendGetRequest("https://graph.facebook.com/me/likes?access_token=" . $token->getTokenKey()); // mongo manager $dm = MongoManager::getDM(); // check likes if ($response && ($objects = json_decode($response, true))) { if (!isset($objects['data'])) { return false; } // iterate and save in mongodb foreach ($objects["data"] as $object) { $interest = $dm->getRepository('Documents\\Interest')->upsert($object); // check interest if ($interest) { $user_interest = $dm->getRepository('Documents\\UserInterest')->upsert($online_identity, $interest); } } } return; }
public function getRank() { return \MongoManager::getStatsDM()->getRepository("Documents\\UserRank")->getCurrent($this->getId()); }
/** * If `$vals` is false, we're creating a new object from scratch. * If it contains an array, it's a new object from an array. * If `$is_new` is false, then the array is an existing field * (mainly used internally by `fetch()`). * If `$vals` contains a single value, the object is retrieved from the database. */ public function __construct($vals = false, $is_new = true) { $this->name = $this->name === '' ? strtolower(get_class($this)) : $this->name; $this->db = MongoManager::get_database(); if ($this->db) { $this->collection = $this->db->{$this->name}; } if (is_object($vals)) { if (get_class($vals) !== 'MongoId') { $vals = (array) $vals; } } if (is_array($vals)) { $this->data = $vals; if (isset($vals[$this->key])) { $this->keyval = $vals[$this->key]; } if ($is_new) { $this->is_new = true; } } elseif ($vals !== false) { $res = $this->collection->findOne(array('_id' => $this->_id($vals))); if (!$res) { $this->error = 'No object by that ID.'; } else { $this->data = (array) $res; $this->keyval = $this->data[$this->key]; } } else { $this->is_new = true; } }
private function calc($range, $lastRange) { $data = array(); $data['current_user_count'] = UserTable::getInstance()->countByRange($range[0], $range[1]); $data['last_user_count'] = UserTable::getInstance()->countByRange($lastRange[0], $lastRange[1]); $data['user_count_delta'] = $this->delta($data['current_user_count'], $data['last_user_count']); $data['current_stats_user_count'] = SfGuardUserTable::getInstance()->countByRange($range[0], $range[1]); $data['last_stats_user_count'] = SfGuardUserTable::getInstance()->countByRange($lastRange[0], $lastRange[1]); $data['stats_user_count_delta'] = $this->delta($data['current_stats_user_count'], $data['last_stats_user_count']); $data['current_likes_count'] = MongoManager::getDm()->getRepository('Documents\\YiidActivity')->countByRange($range[0], $range[1]); $data['last_likes_count'] = MongoManager::getDm()->getRepository('Documents\\YiidActivity')->countByRange($lastRange[0], $lastRange[1]); $data['likes_count_delta'] = $this->delta($data['current_likes_count'], $data['last_likes_count']); $data['current_cbl_count'] = MongoManager::getDm()->getRepository('Documents\\YiidActivity')->countCBLByRange($range[0], $range[1]); $data['last_cbl_count'] = MongoManager::getDm()->getRepository('Documents\\YiidActivity')->countCBLByRange($lastRange[0], $lastRange[1]); $data['cbl_count_delta'] = $this->delta($data['current_cbl_count'], $data['last_cbl_count']); $data['current_domain_count'] = DomainProfileTable::getInstance()->countByRange($range[0], $range[1]); $data['last_domain_count'] = DomainProfileTable::getInstance()->countByRange($lastRange[0], $lastRange[1]); $data['domain_count_delta'] = $this->delta($data['current_domain_count'], $data['last_domain_count']); $data['current_verified_domain_count'] = DomainProfileTable::getInstance()->countVerifiedByRange($range[0], $range[1]); $data['last_verified_domain_count'] = DomainProfileTable::getInstance()->countVerifiedByRange($lastRange[0], $lastRange[1]); $data['verified_domain_count_delta'] = $this->delta($data['current_verified_domain_count'], $data['last_verified_domain_count']); $data['current_stats'] = MongoManager::getStatsDm()->getRepository('Documents\\AnalyticsActivity')->findOnlyByRange($range[0], $range[1]); $data['last_stats'] = MongoManager::getStatsDm()->getRepository('Documents\\AnalyticsActivity')->findOnlyByRange($lastRange[0], $lastRange[1]); $data['current_stats'] = $data['current_stats'] && $data['current_stats']->hasNext() ? $data['current_stats']->getNext() : null; $data['last_stats'] = $data['last_stats'] && $data['last_stats']->hasNext() ? $data['last_stats']->getNext() : null; $data['current_clickback_count'] = $data['current_stats'] ? $data['current_stats']['value']['cb'] : 0; $data['last_clickback_count'] = $data['last_stats'] ? $data['last_stats']['value']['cb'] : 0; $data['clickback_count_delta'] = $this->delta($data['current_clickback_count'], $data['last_clickback_count']); $data['current_media_penetration_count'] = $data['current_stats'] ? $data['current_stats']['value']['mp'] : 0; $data['last_media_penetration_count'] = $data['last_stats'] ? $data['last_stats']['value']['mp'] : 0; $data['media_penetration_count_delta'] = $this->delta($data['current_media_penetration_count'], $data['last_media_penetration_count']); $data['share_distribution'] = $data['current_stats'] ? array($data['current_stats']['value']['s']['facebook'] ? $data['current_stats']['value']['s']['facebook']['l'] : 0, $data['current_stats']['value']['s']['twitter'] ? $data['current_stats']['value']['s']['twitter']['l'] : 0, $data['current_stats']['value']['s']['linkedin'] ? $data['current_stats']['value']['s']['linkedin']['l'] : 0, $data['current_stats']['value']['s']['google'] ? $data['current_stats']['value']['s']['google']['l'] : 0) : array(0, 0, 0, 0); $data['share_distribution_labels'] = array('Fb:' . $data['share_distribution'][0], 'Tw:' . $data['share_distribution'][1], 'Li:' . $data['share_distribution'][2], 'Go:' . $data['share_distribution'][3]); if ($this->range == 'today' || $this->range == 'yesterday') { $lActivityStats = MongoManager::getStatsDm()->getRepository("Documents\\ActivityStats")->findByRangeGroupByDay($range[0], $range[1]); $h = null; if ($lActivityStats && $lActivityStats->hasNext()) { $temp = $lActivityStats->getNext(); $h = $temp['value']['h']; unset($h['php_ckuf']); } $data['current_likes_range'] = $h ? $h : array(); $lActivityStats = MongoManager::getStatsDm()->getRepository("Documents\\DealStats")->findByRangeGroupByDay($range[0], $range[1]); $h = null; if ($lActivityStats && $lActivityStats->hasNext()) { $temp = $lActivityStats->getNext(); $h = $temp['value']['h']; unset($h['php_ckuf']); } $data['current_deals_range'] = $h ? $h : array(); } else { $lActivityStats = MongoManager::getStatsDm()->getRepository("Documents\\ActivityStats")->findLikesByRangeGroupByDay($range[0], $range[1]); if ($lActivityStats) { $lActivityStats = $lActivityStats->toArray(); $data['current_likes_range'] = array_values($this->padLikes($lActivityStats, date('c', $range[0]), date('c', $range[1]))); $lActivityStats = MongoManager::getStatsDm()->getRepository("Documents\\DealStats")->findLikesByRangeGroupByDay($range[0], $range[1]); $lActivityStats = $lActivityStats->toArray(); $data['current_deals_range'] = array_values($this->padLikes($lActivityStats, date('c', $range[0]), date('c', $range[1]))); } } $data['top_users'] = array_slice(MongoManager::getStatsDm()->getRepository("Documents\\AnalyticsActivity")->groupByUsers($range[0], $range[1]), 0, 5); $data['top_hosts'] = array_slice(MongoManager::getStatsDm()->getRepository("Documents\\AnalyticsActivity")->groupByHosts($range[0], $range[1]), 0, 5); $data['top_urls'] = array_slice(MongoManager::getStatsDm()->getRepository("Documents\\AnalyticsActivity")->groupByUrls($range[0], $range[1]), 0, 5); //$cb = new Chartbeat(); //$data['current_popup_visitors_count'] = $cb->getVisitorsByDate($this->range); $data['current_pi_count'] = intval(VisitTable::countPisForDay($range[0])); $data['last_pi_count'] = intval(VisitTable::countPisForDay($lastRange[0])); $data['pi_count_delta'] = $this->delta($data['current_pi_count'], $data['last_pi_count']); $data['current_conversion'] = $this->conversion($data['current_likes_count'], $data['current_pi_count']); $data['last_conversion'] = $this->conversion($data['last_likes_count'], $data['last_pi_count']); $data['conversion_delta'] = $this->delta($data['current_conversion'], $data['last_conversion']); return $data; }
/** * Get the MongoDB database object. */ public static function get_database() { return MongoManager::get_connection()->{conf('Mongo', 'name')}; }
private function getUrlAnalytics($deal) { $lDm = MongoManager::getStatsDM(); return $lDm->getRepository("Documents\\AnalyticsActivity")->findBy(array("d_id" => intval($deal->getId()))); }