예제 #1
0
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
 public function executeIndex(sfWebRequest $request)
 {
     $this->getResponse()->setSlot('js_document_ready', $this->getPartial('deal/js_init_deal.js'));
     $url = $request->getParameter("url", null);
     // handle form submit
     if ($request->getMethod() == "POST") {
         $params = $request->getParameter('like');
         $params['u_id'] = $this->getUser()->getUserId();
         if ($url) {
             $params['i_url'] = $url;
         }
         $activity = new Documents\YiidActivity();
         $activity->fromArray($params);
         // try to save activity
         try {
             $activity->save();
             $this->redirect("@coupon?id=" . $activity->getId() . "&u_code=" . $activity->getCCode());
         } catch (Exception $e) {
             // send error on exception
             $this->getLogger()->err($e->getMessage());
             $this->redirect('@default_deal');
             return sfView::SUCCESS;
         }
     }
     $deal = DealTable::getInstance()->getNextFromPool($this->getUser()->getUser(), $url);
     $this->deal = $deal;
     if (!$deal) {
         $this->hash = md5($this->getUser()->getId() . $url);
         $this->setTemplate('default_deal');
     }
 }
예제 #2
0
 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())));
 }
예제 #3
0
 public function executeDeal_details(sfWebRequest $request)
 {
     $this->getResponse()->setSlot('js_document_ready', $this->getPartial('deal_analytics/init_deal_analytics.js'));
     $lDealId = $request->getParameter('deal_id');
     $this->pDeal = DealTable::getInstance()->find($lDealId);
     $this->pEndDate = date("Y-m-d", strtotime("today"));
     $this->pLikes = $this->getDealLikes($this->pDeal, $this->pEndDate);
     $this->pUrlSummaries = $this->getUrlSummaryAnalytics($this->pDeal);
     $this->pUrls = $this->getUrlAnalytics($this->pDeal);
 }
예제 #4
0
 public function executeCredentials(sfWebRequest $request)
 {
     $domainId = $request->getParameter("domainid");
     if (!$domainId) {
         $dealId = $request->getParameter("deal_id");
         $deal = DealTable::getInstance()->find($dealId);
         $domainId = $deal->getDomainProfileId();
     }
     $this->domainProfile = DomainProfileTable::getInstance()->find($domainId);
 }
 protected function doClean($values)
 {
     $lDealId = isset($values[$this->getOption('id')]) ? $values[$this->getOption('id')] : '';
     $lDomainProfileId = isset($values[$this->getOption('domain_profile_id')]) ? $values[$this->getOption('domain_profile_id')] : '';
     $lStartDate = isset($values[$this->getOption('start_date')]) ? $values[$this->getOption('start_date')] : '';
     $lEndDate = isset($values[$this->getOption('end_date')]) ? $values[$this->getOption('end_date')] : '';
     if (DealTable::isOverlappingByParams($lDealId, $lDomainProfileId, $lStartDate, $lEndDate)) {
         throw new sfValidatorErrorSchema($this, array($this->getOption('end_date') => new sfValidatorError($this, 'invalid')));
     }
     return $values;
 }
 protected function doClean($values)
 {
     $lDealId = isset($values[$this->getOption('id')]) ? $values[$this->getOption('id')] : '';
     $lDeal = DealTable::getInstance()->find($lDealId);
     if ($lDeal && !$lDeal->isUnlimited() && $lDeal->getCouponType() != DealTable::COUPON_TYPE_MULTIPLE) {
         $lCouponQuantity = isset($values[$this->getOption('coupon_quantity')]) ? $values[$this->getOption('coupon_quantity')] : '';
         if ($lDeal->getCouponQuantity() > $lCouponQuantity) {
             throw new sfValidatorErrorSchema($this, array($this->getOption('coupon_quantity') => new sfValidatorError($this, 'invalid')));
         }
     }
     return $values;
 }
 public static function verify()
 {
     $context = sfContext::getInstance();
     $domainid = $context->getRequest()->getParameter("domainid");
     if (!$domainid) {
         $dealid = $context->getRequest()->getParameter("deal_id");
         $deal = DealTable::getInstance()->find($dealid);
         $domainid = $deal->getDomainProfileId();
     }
     $domainProfile = DomainProfileTable::getInstance()->find($domainid);
     if ($domainProfile && $domainProfile->getSfGuardUserId() == $context->getUser()->getUserId() && $domainProfile->getDetailedAnalytics()) {
         return;
     } else {
         $context->getController()->forward(sfConfig::get('sf_secure_module'), sfConfig::get('sf_secure_action'));
         throw new sfStopException();
     }
 }
예제 #8
0
 public function executeApprove(sfWebRequest $request)
 {
     $dealId = $request->getParameter("deal_id");
     $dealParams = $request->getParameter("deal");
     if (!$dealId) {
         $dealId = $dealParams['id'];
     }
     $this->deal = DealTable::getInstance()->find($dealId);
     $this->form = new ApproveDealForm($this->deal);
     if ($request->isMethod(sfRequest::PUT)) {
         $this->form->bind($dealParams);
         if ($this->form->isValid()) {
             $deal = $this->form->save();
             $deal->approve();
             $this->redirect('approve_deal/index');
         }
     }
 }
예제 #9
0
 public function testNewApiDealIsActiveImmediately()
 {
     $user = Doctrine_Core::getTable('sfGuardUser')->createQuery('u')->where('u.is_active = ?', true)->fetchOne();
     $this->assertEquals(10, DealTable::getInstance()->count());
     $data = UrlUtils::getUrlContent("http://api.spreadly.local/deals?access_token=" . $user->getAccessToken(), UrlUtils::HTTP_POST, self::$VALID_TEST_JSON);
     $this->assertEquals(11, DealTable::getInstance()->count());
     $deal = DealTable::getInstance()->findOneByName('Kampagne Like');
     $this->assertFalse($deal->isActive());
     $this->assertEquals(DealTable::STATE_SUBMITTED, $deal->getState());
     $data = UrlUtils::getUrlContent("http://api.spreadly.local/deals?access_token=" . $user->getAccessToken(), UrlUtils::HTTP_POST, self::$VALID_AUTOACTIVATE_TEST_JSON);
     $deal = DealTable::getInstance()->findOneByName('Kampagne Activate');
     $this->assertTrue($deal->isActive());
     $this->assertEquals(DealTable::STATE_ACTIVE, $deal->getState());
 }
<?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);
}
예제 #11
0
 public function executeGet_code_form($request)
 {
     $lDealId = $this->pDealId;
     $lDeal = DealTable::getInstance()->find($lDealId);
     $this->pForm = new DealForm($lDeal);
 }
예제 #12
0
 public function executeGet_deal_table(sfWebRequest $request)
 {
     $this->getResponse()->setContentType('application/json');
     $lQuery = DealTable::getInstance()->createQuery()->where('sf_guard_user_id = ?', $this->getUser()->getUserId())->orderBy("created_at DESC");
     $lDeals = $lQuery->execute();
     return $this->renderText(json_encode(array('success' => empty($lError), 'html' => $this->getPartial('deals/deal_table', array('pDeals' => $lDeals)))));
 }
예제 #13
0
 public function testPublisherDeals2()
 {
     $deal = DealTable::getInstance()->getNextFromPool($this->hugo, "http://www.missmotz.de/test");
     $this->assertEquals($deal->getType(), DealTable::TYPE_PUBLISHER);
     $lActivity = new Documents\YiidActivity();
     $lActivity->setUId($this->hugo->getId());
     $lActivity->setDId($deal->getId());
     $lActivity->setOiids($this->hugo->getOnlineIdentitesAsArray());
     $lActivity->setIUrl('http://www.missmotz.de/test');
     $lActivity->save();
     $deal = DealTable::getInstance()->getNextFromPool($this->hugo, "http://www.missmotz.de/test");
     $this->assertEquals($deal->getType(), DealTable::TYPE_POOL);
 }
    protected function execute($arguments = array(), $options = array())
    {
        try {
            sfContext::getInstance();
        } catch (Exception $e) {
            // aize the database connection
            $configuration = ProjectConfiguration::getApplicationConfiguration($options['application'], $options['env'], true);
            sfContext::createInstance($configuration);
        }
        $databaseManager = new sfDatabaseManager($this->configuration);
        $databaseManager->loadConfiguration();
        $connection = $databaseManager->getDatabase($options['connection'])->getConnection();
        $originalPostToServicesValue = sfConfig::get('app_settings_post_to_services');
        sfConfig::set('app_settings_post_to_services', 0);
        $this->log("Using mongo host: " . sfConfig::get('app_mongodb_host'));
        $lUserHugo = UserTable::retrieveByUsername('hugo');
        $lHugoOis = $lUserHugo->getOnlineIdentitesAsArray();
        $lUserJames = UserTable::retrieveByUsername('james');
        $lJamesOis = $lUserJames->getOnlineIdentitesAsArray();
        $lCommunityTwitter = CommunityTable::retrieveByCommunity('twitter');
        $lCommunityFb = CommunityTable::retrieveByCommunity('facebook');
        $lOiHugoTwitter = OnlineIdentityTable::retrieveByAuthIdentifier('http://twitter.com/account/profile?user_id=21092406', $lCommunityTwitter->getId());
        $lOiJamesFacebook = OnlineIdentityTable::retrieveByAuthIdentifier('james_fb', $lCommunityFb->getId());
        $urls = array('www.snirgel.de', 'notizblog.org', 'www.missmotz.de');
        $tags = array('geekstuff', 'otherthings', 'schuhe');
        $users = array($lUserHugo, $lUserJames);
        $services = array('facebook', 'twitter', 'linkedin', 'google');
        $deals = array('Campaign No. 1', 'Campaign No. 2', 'Campaign No. 3');
        $dm = MongoManager::getDM();
        for ($i = 0; $i < 100; $i++) {
            $url = $this->oneOfThese($urls);
            $tag = $this->oneOfThese($tags);
            $user = $this->oneOfThese($users);
            $cb_ref = $this->oneOfThese(array('', '', '', '', '', '', 'http://tierscheisse.de'));
            $ra = $this->random(1000);
            $theC = mt_rand(strtotime("3 days ago"), strtotime("today"));
            $array = array('url' => "http://{$url}/{$ra}", 'url_hash' => "hash.{$ra}", 'u_id' => $user->getId(), 'oiids' => $user->getOnlineIdentitesAsArray(), 'tags' => $tag . $ra, 'title' => "{$url} title", 'descr' => "{$url} description", 'comment' => "{$url} comment", 'c' => $theC, 'cb' => $this->randBoolean() ? $this->random(30) : 0, 'cb_referer' => $cb_ref != '' ? $cb_ref : null, 'cb_service' => $cb_ref != '' ? $this->oneOfThese($services) : null);
            $lActivity = new Documents\YiidActivity();
            $lActivity->fromArray($array);
            try {
                $lActivity->skipUrlCheck = true;
                $lActivity->save();
            } catch (Exception $e) {
                $this->log($e->getMessage());
            }
        }
        // same for deals
        for ($i = 0; $i < 100; $i++) {
            $url = $this->oneOfThese($urls);
            $tag = $this->oneOfThese($tags);
            $user = $this->oneOfThese($users);
            $cb_ref = $this->oneOfThese(array('', '', '', '', '', '', 'http://tierscheisse.de'));
            $i_url = $this->oneOfThese(array('http://ard.de', 'http://bild.de', 'http://spiegel.de', 'http://tierscheisse.de'));
            $ra = $this->random(1000);
            $theC = mt_rand(strtotime("3 days ago"), strtotime("today"));
            $deal = DealTable::getInstance()->findOneByName($this->oneOfThese($deals));
            $array = array('url' => "http://{$url}/{$ra}", 'url_hash' => "hash.{$ra}", 'u_id' => $user->getId(), 'oiids' => $user->getOnlineIdentitesAsArray(), 'tags' => $tag . $ra, 'title' => "{$url} title", 'descr' => "{$url} description", 'comment' => "{$url} comment", 'c' => $theC, 'd_id' => $deal->getId(), 'cb' => $this->randBoolean() ? $this->random(30) : 0, 'cb_referer' => $cb_ref != '' ? $cb_ref : null, 'i_url' => $i_url, 'cb_service' => $cb_ref != '' ? $this->oneOfThese($services) : null);
            $lActivity = new Documents\YiidActivity();
            $lActivity->fromArray($array);
            try {
                $lActivity->skipUrlCheck = true;
                $lActivity->save();
            } catch (Exception $e) {
                $this->log($e->getMessage());
            }
        }
        $ds = new Documents\DomainSettings();
        $ds->setDomain("blog.local");
        $ds->setMute(0);
        $ds->save();
        $ds = new Documents\DomainSettings();
        $ds->setDomain("pfefferle.org");
        $ds->setDisableAds(true);
        $ds->save();
        $ad = new Documents\Advertisement();
        $ad->setDomains(array("pfefferle.org", "notizblog.org", "www.spiegel.de", "blog.local"));
        $ad->setAdCode('<script type="text/javascript" src="http://a.ligatus.com/?ids=34548&t=js"></script>');
        $ad->setUpdatedAt(strtotime("now"));
        $ad->setStartingAt(strtotime("now"));
        $ad->setAdHeight(500);
        $ad->setAdWidth(50);
        $ad->save();
        $ad = new Documents\Advertisement();
        $ad->setDomains(array("blog.local"));
        $ad->setAdCode("<script type='text/javascript' src='http://imagesrv.adition.com/js/adition.js'></script>\n<script type='text/javascript' src='http://ad4.adfarm1.adition.com/js?wp_id=744125'></script>");
        $ad->setUpdatedAt(strtotime("now"));
        $ad->setStartingAt(strtotime("now"));
        $ad->setAdHeight(100);
        $ad->setAdWidth(800);
        $ad->save();
        $ad = new Documents\Advertisement();
        $ad->setDomains(array("pfefferle.org", "notizblog.org", "www.spiegel.de", "blog.local"));
        $ad->setAdCode('<script type="text/javascript"><!--
  google_ad_client = "ca-pub-1406192967534280";
  /* spreadly */
  google_ad_slot = "7458728780";
  google_ad_width = 250;
  google_ad_height = 250;
  //-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>');
        $ad->setUpdatedAt(strtotime("now"));
        $ad->setStartingAt(strtotime("now"));
        $ad->setAdHeight(250);
        $ad->setAdWidth(250);
        $ad->save();
        /*
        
        $lActivity = new Documents\YiidActivity();
        $lActivity->fromArray($array);
        $lActivity->save();
        
        $array = array(
          'url' => "http://$url",
          'oiids' => array($lOiJamesFacebook->getId()),
          'title' => "$url deal title",
          'descr' => "$url description",
          'comment' => "$url comment",
          'thumb' => null,
          'clickback' => null,
          'tags' => null,
          'u_id' => $lUserJames->getId()
        );
        
        $lActivity = new Documents\YiidActivity();
        $lActivity->fromArray($array);
        $lActivity->save();
        
        if($deal[0]->canApprove()) {
          $deal[0]->approve();
        }
        
        
        $url = 'notizblog.org';
        $array = array(
          'url' => "http://$url",
          'oiids' => array($lOiHugoTwitter->getId()),
          'title' => "$url deal title",
          'descr' => "$url description",
          'comment' => "$url comment",
          'thumb' => null,
          'clickback' => null,
          'tags' => null,
          'u_id' => $lUserHugo->getId()
        );
        
        $lActivity = new Documents\YiidActivity();
        $lActivity->fromArray($array);
        $lActivity->save();
        
        $deal = DealTable::getInstance()->findByDescription('missmotz approved description');
        if($deal[0]->canApprove()) {
          $deal[0]->approve();
        }
        
        $url = 'www.missmotz.de';
        $array = array(
          'url' => "http://$url",
          'oiids' => array($lOiHugoTwitter->getId()),
          'title' => "$url deal title",
          'descr' => "$url description",
          'comment' => "$url comment",
          'thumb' => null,
          'clickback' => null,
          'tags' => "Schuhe, Hemden",
          'u_id' => $lUserHugo->getId()
        );
        
        $lActivity = new Documents\YiidActivity();
        $lActivity->fromArray($array);
        $lActivity->save();
        */
        sfConfig::set('app_settings_post_to_services', $originalPostToServicesValue);
        $this->generateErrorLog();
    }