当前位置: 首页>>代码示例>>PHP>>正文


PHP DAOFactory::getDAO方法代码示例

本文整理汇总了PHP中DAOFactory::getDAO方法的典型用法代码示例。如果您正苦于以下问题:PHP DAOFactory::getDAO方法的具体用法?PHP DAOFactory::getDAO怎么用?PHP DAOFactory::getDAO使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DAOFactory的用法示例。


在下文中一共展示了DAOFactory::getDAO方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testOutput

 public function testOutput()
 {
     //not logged in
     $controller = new TwitterPluginHashtagConfigurationController(null, 'twitter', 'ginatrapani');
     $output = $controller->go();
     $v_mgr = $controller->getViewManager();
     $config = Config::getInstance();
     $this->assertEqual('You must <a href="' . $config->getValue('site_root_path') . 'session/login.php">log in</a> to do this.', $v_mgr->getTemplateDataItem('error_msg'));
     //logged in, no user set up
     $this->simulateLogin('me@example.com');
     $owner_dao = DAOFactory::getDAO('OwnerDAO');
     $owner = $owner_dao->getByEmail(Session::getLoggedInUser());
     $controller = new TwitterPluginHashtagConfigurationController(null, 'twitter', 'ginatrapani');
     $output = $controller->go();
     $v_mgr = $controller->getViewManager();
     $this->assertIsA($v_mgr->getTemplateDataItem('user'), 'string');
     $this->assertEqual('Twitter user @ginatrapani does not exist.', $v_mgr->getTemplateDataItem('error_msg'));
     //logged in, user set up
     $builders = array();
     $builders[] = FixtureBuilder::build('instances', array('network_username' => 'ginatrapani', 'network' => 'twitter'));
     $controller = new TwitterPluginHashtagConfigurationController(null, 'twitter', 'ginatrapani');
     $output = $controller->go();
     $v_mgr = $controller->getViewManager();
     $this->assertIsA($v_mgr->getTemplateDataItem('user'), 'string');
     $this->assertIsA($v_mgr->getTemplateDataItem('hashtags'), 'array');
 }
开发者ID:dgw,项目名称:ThinkUp,代码行数:26,代码来源:TestOfTwitterPluginHashtagConfigurationController.php

示例2: generateInsight

 public function generateInsight(Instance $instance, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     if (self::shouldGenerateInsight('favorited_links', $instance, $insight_date = 'today', $regenerate_existing_insight = true)) {
         $fpost_dao = DAOFactory::getDAO('FavoritePostDAO');
         $favorited_posts = $fpost_dao->getAllFavoritePosts($instance->network_user_id, $instance->network, 40);
         $todays_favorited_posts_with_links = array();
         foreach ($favorited_posts as $post) {
             if (date('Y-m-d', strtotime($post->pub_date)) == date('Y-m-d')) {
                 $post_text = $post->post_text;
                 $text_parser = new Twitter_Extractor($post_text);
                 $elements = $text_parser->extract();
                 if (count($elements['urls'])) {
                     $todays_favorited_posts_with_links[] = $post;
                 }
             }
         }
         $favorited_links_count = count($todays_favorited_posts_with_links);
         if ($favorited_links_count) {
             $verb = '';
             $post_type = '';
             if ($favorited_links_count == 1) {
                 $insight_text = $this->username . " " . $this->terms->getVerb('liked') . " <strong>1 " . $this->terms->getNoun('post') . "</strong> with a link in it.";
             } else {
                 $insight_text = $this->username . " " . $this->terms->getVerb('liked') . " <strong>" . $favorited_links_count . " " . $this->terms->getNoun('post', InsightTerms::PLURAL) . "</strong> with links in them:";
             }
             $this->insight_dao->insertInsightDeprecated("favorited_links", $instance->id, $this->insight_date, "Links you liked:", $insight_text, basename(__FILE__, ".php"), Insight::EMPHASIS_LOW, serialize($todays_favorited_posts_with_links));
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:dgw,项目名称:ThinkUp,代码行数:32,代码来源:favoritedlinks.php

示例3: control

 public function control()
 {
     $this->redirectToSternIndiaEndpoint('forgot.php');
     $config = Config::getInstance();
     //$this->addToView('is_registration_open', $config->getValue('is_registration_open'));
     // if (isset($_POST['email']) && $_POST['Submit'] == 'Send Reset') {
     // /$_POST['email'] = 'prabhat@sternindia.com';
     if (isset($_POST['email'])) {
         $this->disableCaching();
         $dao = DAOFactory::getDAO('UserDAO');
         $user = $dao->getByEmail($_POST['email']);
         if (isset($user)) {
             $token = $user->setPasswordRecoveryToken();
             $es = new ViewManager();
             $es->caching = false;
             //$es->assign('apptitle', $config->getValue('app_title_prefix')."ThinkUp" );
             $es->assign('first_name', $user->first_name);
             $es->assign('recovery_url', "session/reset.php?token={$token}");
             $es->assign('application_url', Utils::getApplicationURL(false));
             $es->assign('site_root_path', $config->getValue('site_root_path'));
             $message = $es->fetch('_email.forgotpassword.tpl');
             $subject = $config->getValue('app_title_prefix') . "Stern India Password Recovery";
             //Will put the things in queue to mail the things.
             Resque::enqueue('user_mail', 'Mailer', array($_POST['email'], $subject, $message));
             $this->addToView('link_sent', true);
         } else {
             $this->addErrorMessage('Error: account does not exist.');
         }
     }
     $this->setViewTemplate('Session/forgot.tpl');
     return $this->generateView();
 }
开发者ID:prabhatse,项目名称:olx_hack,代码行数:32,代码来源:class.ForgotPasswordController.php

示例4: testGetScoredLinks

 public function testGetScoredLinks()
 {
     $year = date('Y');
     $builders = self::setUpPublicInsight($this->instance);
     // set up posts with links (not photos)
     $builders[] = FixtureBuilder::build('posts', array('id' => 10, 'post_id' => 10, 'author_username' => $this->instance->network_username, 'author_user_id' => $this->instance->network_user_id, 'author_fullname' => 'Twitter User', 'author_avatar' => 'avatar.jpg', 'network' => $this->instance->network, 'post_text' => 'This is a post http://t.co/B5LAotKMWY with a link.', 'source' => 'web', 'pub_date' => "{$year}-01-01", 'reply_count_cache' => 10, 'is_protected' => false));
     $builders[] = FixtureBuilder::Build('links', array('post_key' => 10, 'url' => 'http://t.co/B5LAotKMWY', 'image_src' => '', 'expanded_url' => 'http://pic.twitter.com/vx4YL7Yz'));
     $builders[] = FixtureBuilder::build('posts', array('id' => 12, 'post_id' => 12, 'author_username' => $this->instance->network_username, 'author_user_id' => $this->instance->network_user_id, 'author_fullname' => 'Twitter User', 'author_avatar' => 'avatar.jpg', 'network' => $this->instance->network, 'post_text' => 'This is a post http://t.co/B5LAotKMWY with a link.', 'source' => 'web', 'pub_date' => "{$year}-01-01", 'reply_count_cache' => 12, 'is_protected' => false));
     $builders[] = FixtureBuilder::Build('links', array('post_key' => 12, 'url' => 'http://t.co/B5LAotKMWY', 'image_src' => '', 'expanded_url' => 'http://pic.twitter.com/vx4YL7Yz'));
     // set up posts with photos
     $builders[] = FixtureBuilder::build('posts', array('id' => 13, 'post_id' => 13, 'author_username' => $this->instance->network_username, 'author_user_id' => $this->instance->network_user_id, 'author_fullname' => 'Twitter User', 'author_avatar' => 'avatar.jpg', 'network' => $this->instance->network, 'post_text' => 'This is a post http://t.co/B5LAotKMWY with a link.', 'source' => 'web', 'pub_date' => "{$year}-01-01", 'reply_count_cache' => 12, 'is_protected' => false));
     $builders[] = FixtureBuilder::Build('links', array('post_key' => 13, 'url' => 'http://t.co/B5LAotKMWY', 'image_src' => 'http://pic.twitter.com.foo.jpg', 'expanded_url' => 'http://pic.twitter.com/vx4YL7Yz'));
     // set up one post with no link
     $builders[] = FixtureBuilder::build('posts', array('id' => 11, 'post_id' => 11, 'author_username' => $this->instance->network_username, 'author_user_id' => $this->instance->network_user_id, 'author_fullname' => 'Twitter User', 'author_avatar' => 'avatar.jpg', 'network' => $this->instance->network, 'post_text' => 'This post has no photo', 'source' => 'web', 'pub_date' => "{$year}-01-01", 'reply_count_cache' => 1, 'is_protected' => false));
     $insight_plugin = new EOYPopularLinkInsight();
     $post_dao = DAOFactory::getDAO('PostDAO');
     $last_year_of_posts = $post_dao->getThisYearOfPostsWithLinksIterator($author_id = $this->instance->network_user_id, $network = $this->instance->network);
     $scored_pics = $insight_plugin->getScoredLinks($last_year_of_posts);
     $sorted_pics = array(0 => array(12 => 60), 1 => array(10 => 50));
     $i = 0;
     foreach ($scored_pics as $post_id => $score) {
         $this->assertEqual($sorted_pics[$i][$post_id], $score);
         $i++;
     }
     $this->assertEqual($i, 2);
 }
开发者ID:pepeleproso,项目名称:ThinkUp,代码行数:26,代码来源:TestOfEOYPopularLinkInsight.php

示例5: processPostURLs

 /**
  * For a given post, extract URLs and store them, including image_src if that's from a known source like Twitpic,
  * Twitgoo, Yfrog, Instagr.am.
  * @param str $post_text
  * @param int $post_id
  * @param str $network
  * @param Logger $logger
  * @param arr $urls Array of URLs, optionally set, defaults to null
  */
 public static function processPostURLs($post_text, $post_id, $network, $logger, $urls = null)
 {
     if (!$urls) {
         $urls = Post::extractURLs($post_text);
     }
     if ($urls) {
         $link_dao = DAOFactory::getDAO('LinkDAO');
         $post_dao = DAOFactory::getDAO('PostDAO');
         $post = $post_dao->getPost($post_id, $network);
         if (isset($post->id)) {
             foreach ($urls as $url) {
                 $logger->logInfo("Processing URL {$url}", __METHOD__ . ',' . __LINE__);
                 $image_src = self::getImageSource($url);
                 //if we have an image_src, the URL is a known image source not in need of expansion
                 $expanded_url = $image_src !== '' ? $url : '';
                 $link_array = array('url' => $url, 'expanded_url' => $expanded_url, "image_src" => $image_src, 'post_key' => $post->id);
                 $link = new Link($link_array);
                 try {
                     $link_dao->insert($link);
                     $logger->logSuccess("Inserted " . $url . " " . ($image_src == '' ? '' : "(thumbnail " . $image_src . ") ") . "into links table", __METHOD__ . ',' . __LINE__);
                 } catch (DuplicateLinkException $e) {
                     $logger->logInfo($url . " " . ($image_src == '' ? '' : "(thumbnail " . $image_src . ") ") . " already exists in links table", __METHOD__ . ',' . __LINE__);
                 } catch (DataExceedsColumnWidthException $e) {
                     $logger->logInfo($url . " " . ($image_src == '' ? '' : "(thumbnail " . $image_src . ") ") . " data exceeds table column width", __METHOD__ . ',' . __LINE__);
                 }
             }
         }
     }
 }
开发者ID:dgw,项目名称:ThinkUp,代码行数:38,代码来源:class.URLProcessor.php

示例6: control

 public function control()
 {
     if (isset($_POST['Submit']) && $_POST['Submit'] == 'Send Reset') {
         $this->disableCaching();
         $dao = DAOFactory::getDAO('OwnerDAO');
         $user = $dao->getByEmail($_POST['email']);
         if (isset($user)) {
             $token = $user->setPasswordRecoveryToken();
             $es = new SmartyThinkUp();
             $es->caching = false;
             $config = Config::getInstance();
             $es->assign('apptitle', $config->getValue('app_title'));
             $es->assign('recovery_url', "session/reset.php?token={$token}");
             $es->assign('server', isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost');
             $es->assign('site_root_path', $config->getValue('site_root_path'));
             $message = $es->fetch('_email.forgotpassword.tpl');
             Mailer::mail($_POST['email'], $config->getValue('app_title') . " Password Recovery", $message);
             $this->addSuccessMessage('Password recovery information has been sent to your email address.');
         } else {
             $this->addErrorMessage('Error: account does not exist.');
         }
     }
     $this->setViewTemplate('session.forgot.tpl');
     return $this->generateView();
 }
开发者ID:NickBall,项目名称:ThinkUp,代码行数:25,代码来源:class.ForgotPasswordController.php

示例7: adminControl

 public function adminControl()
 {
     if (!$this->is_missing_param) {
         // verify CSRF token
         $this->validateCSRFToken();
         $is_active = $_GET["a"] != 1 ? false : true;
         $plugin_dao = DAOFactory::getDAO('PluginDAO');
         $result = $plugin_dao->setActive($_GET["pid"], $is_active);
         if ($result > 0) {
             $plugin_folder = $plugin_dao->getPluginFolder($_GET["pid"]);
             $webapp = Webapp::getInstance();
             try {
                 $plugin_class_name = $webapp->getPluginObject($plugin_folder);
                 $p = new $plugin_class_name();
                 if ($is_active) {
                     $p->activate();
                 } else {
                     $p->deactivate();
                 }
             } catch (Exception $e) {
                 //plugin object isn't registered, do nothing
                 //echo $e->getMessage();
             }
         }
         $this->addToView('result', $result);
         $this->view_mgr->clear_all_cache();
     }
     return $this->generateView();
 }
开发者ID:nix4,项目名称:ThinkUp,代码行数:29,代码来源:class.ToggleActivePluginController.php

示例8: control

 public function control()
 {
     $this->view_name = isset($_GET['v']) ? $_GET['v'] : 'default';
     $post_dao = DAOFactory::getDAO('PostDAO');
     $this->setPageTitle('Post Details');
     $this->setViewTemplate('post.index.tpl');
     $network = isset($_GET['n']) ? $_GET['n'] : 'twitter';
     if ($this->shouldRefreshCache()) {
         if (isset($_GET['t']) && is_numeric($_GET['t'])) {
             $post_id = $_GET['t'];
             $post = $post_dao->getPost($post_id, $network);
             if (isset($post)) {
                 $config = Config::getInstance();
                 $this->addToView('disable_embed_code', $config->getValue('is_embed_disabled') || $post->is_protected);
                 if (isset($_GET['search'])) {
                     $this->addToView('search_on', true);
                 }
                 if (!$post->is_protected || $this->isLoggedIn()) {
                     $plugin_option_dao = DAOFactory::GetDAO('PluginOptionDAO');
                     $options = $plugin_option_dao->getOptionsHash('geoencoder', true);
                     if (isset($options['distance_unit']->option_value)) {
                         $distance_unit = $options['distance_unit']->option_value;
                     } else {
                         $distance_unit = 'km';
                     }
                     $this->addToView('post', $post);
                     $this->addToView('unit', $distance_unit);
                     $replies = $post_dao->getRepliesToPost($post_id, $network, 'default', $distance_unit);
                     $public_replies = array();
                     foreach ($replies as $reply) {
                         if (!$reply->author->is_protected) {
                             $public_replies[] = $reply;
                         }
                     }
                     $public_replies_count = count($public_replies);
                     $this->addToView('public_reply_count', $public_replies_count);
                     if ($this->isLoggedIn()) {
                         $this->addToView('replies', $replies);
                     } else {
                         $this->addToView('replies', $public_replies);
                     }
                     $all_replies_count = count($replies);
                     $private_reply_count = $all_replies_count - $public_replies_count;
                     $this->addToView('private_reply_count', $private_reply_count);
                     $webapp = Webapp::getInstance();
                     $sidebar_menu = $webapp->getPostDetailMenu($post);
                     $this->addToView('sidebar_menu', $sidebar_menu);
                     $this->loadView($post);
                 } else {
                     $this->addErrorMessage('Insufficient privileges');
                 }
             } else {
                 $this->addErrorMessage('Post not found');
             }
         } else {
             $this->addErrorMessage('Post not specified');
         }
     }
     return $this->generateView();
 }
开发者ID:raycornelius,项目名称:ThinkUp,代码行数:60,代码来源:class.PostController.php

示例9: testFlickrCrawl

    public function  testFlickrCrawl() {
        $builders = $this->buildData();

        $crawler = Crawler::getInstance();
        $config = Config::getInstance();

        //use fake Flickr API key
        $plugin_builder = FixtureBuilder::build('plugins', array('id'=>'2', 'folder_name'=>'flickrthumbnails'));
        $option_builder = FixtureBuilder::build('options', array(
            'namespace' => OptionDAO::PLUGIN_OPTIONS . '-2',
            'option_name' => 'flickr_api_key',
            'option_value' => 'dummykey') );
        //$config->setValue('flickr_api_key', 'dummykey');

        $this->simulateLogin('admin@example.com', true);
        $crawler->crawl();

        $ldao = DAOFactory::getDAO('LinkDAO');

        $link = $ldao->getLinkById(43);
        $this->assertEqual($link->expanded_url, 'http://farm3.static.flickr.com/2755/4488149974_04d9558212_m.jpg');
        $this->assertEqual($link->error, '');

        $link = $ldao->getLinkById(42);
        $this->assertEqual($link->expanded_url, '');
        $this->assertEqual($link->error, 'No response from Flickr API');

        $link = $ldao->getLinkById(41);
        $this->assertEqual($link->expanded_url, '');
        $this->assertEqual($link->error, 'No response from Flickr API');
    }
开发者ID:rkabir,项目名称:ThinkUp,代码行数:31,代码来源:TestOfFlickrThumbnailsPlugin.php

示例10: getAuthParameters

 /**
  * Returns URL-encoded parameters needed to make an API call.
  * @param str $username
  * @return str Parameters to use in a URL to make an API call
  */
 public static function getAuthParameters($username)
 {
     $owner_dao = DAOFactory::getDAO('OwnerDAO');
     $pwd_from_db = $owner_dao->getPass($username);
     $api_secret = Session::getAPISecretFromPassword($pwd_from_db);
     return 'un=' . urlencode($username) . '&as=' . urlencode($api_secret);
 }
开发者ID:rayyan,项目名称:ThinkUp,代码行数:12,代码来源:class.ThinkUpAuthAPIController.php

示例11: generateInsight

 public function generateInsight(Instance $instance, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     if (self::shouldGenerateInsight('link_prompt', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = null, $count_last_week_of_posts = null, $excluded_networks = array('foursquare', 'youtube'), $alternate_day = (int) date('j') % 2)) {
         $post_dao = DAOFactory::getDAO('PostDAO');
         $link_dao = DAOFactory::getDAO('LinkDAO');
         // Check from midnight two days ago until an hour from now
         // (to avoid clock-sync issues)
         $recent_posts = $post_dao->getPostsByUserInRange($instance->network_user_id, $instance->network, date('Y-m-d H:i:s', strtotime('-2 days midnight')), date('Y-m-d H:i:s', strtotime('+1 hour')));
         $posts_with_links = array();
         foreach ($recent_posts as $post) {
             $post_text = $post->post_text;
             $text_parser = new Twitter_Extractor($post_text);
             $elements = $text_parser->extract();
             if (count($elements['urls'])) {
                 $posts_with_links[] = $post;
             }
         }
         $num_posts = $post_dao->countAllPostsByUserSinceDaysAgo($instance->network_user_id, $instance->network, 30);
         $num_links = $link_dao->countLinksPostedByUserSinceDaysAgo($instance->network_user_id, $instance->network, 30);
         if ($num_posts && $num_links / $num_posts > 0.2 && count($recent_posts) && !count($posts_with_links)) {
             $insight_text = $this->username . " hasn't " . $this->terms->getVerb('posted') . " a link in the last 2 days. It may be time to share an interesting link with " . $this->terms->getNoun('friend', InsightTerms::PLURAL) . ".";
             $this->insight_dao->insertInsightDeprecated('link_prompt', $instance->id, $this->insight_date, "Nudge:", $insight_text, basename(__FILE__, ".php"), Insight::EMPHASIS_LOW);
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:dgw,项目名称:ThinkUp,代码行数:28,代码来源:linkprompt.php

示例12: generateInsight

 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     $video_dao = DAOFactory::getDAO('VideoDAO');
     $filename = basename(__FILE__, ".php");
     foreach ($last_week_of_posts as $post) {
         if ($post->network == 'youtube') {
             $video = $video_dao->getVideoByID($post->post_id, 'youtube');
             $simplified_post_date = date('Y-m-d', strtotime($video->pub_date));
         } else {
             break;
         }
         // Get the average baselines
         $total_likes_and_dislikes = $video->likes + $video->dislikes;
         $percent_likes = round($video->likes / $total_likes_and_dislikes * 100, 2);
         $percent_dislikes = round($video->dislikes / $total_likes_and_dislikes * 100, 2);
         // If the video splits opinion in the range of 60/40 likes / dislikes or 40/60 likes / dislikes
         if ($percent_likes >= 40 && $percent_likes <= 60) {
             $headline = $video->post_text . " really touched a nerve!";
             $insight_text = "{$percent_likes}" . "% of people liked ";
             $insight_text .= "<a href=\"http://plus.google.com/{$instance->network_user_id}/about\">" . $instance->network_username;
             $insight_text .= '</a>\'s video ';
             $insight_text .= "<a href=\"http://www.youtube.com/watch?v={$post->post_id}\">" . $video->post_text . "</a> ";
             $insight_text .= "and " . $percent_dislikes . "% disliked it.";
             $this->insight_dao->insertInsightDeprecated("split_opinions" . $video->id, $instance->id, $simplified_post_date, $headline, $insight_text, $filename, 1, serialize($video));
         }
     }
 }
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:29,代码来源:splitopinions.php

示例13: testShouldGenerateInsight

 public function testShouldGenerateInsight()
 {
     $instance = new Instance();
     $instance->id = 10;
     $instance->network_username = 'testeriffic';
     $instance->network = 'twitter';
     $time_now = date("Y-m-d H:i:s");
     $today = date('Y-m-d', strtotime('today'));
     $yesterday = date('Y-m-d', strtotime('-1 day'));
     $builders = array();
     $builders[] = FixtureBuilder::build('insights', array('id' => 76, 'instance_id' => 10, 'slug' => 'some_slug', 'date' => $today, 'time_generated' => $time_now));
     $builders[] = FixtureBuilder::build('insights', array('id' => 77, 'instance_id' => 10, 'slug' => 'some_other_slug', 'date' => $yesterday, 'time_generated' => $time_now));
     $insight_plugin_parent = new InsightPluginParent();
     $insight_plugin_parent->insight_dao = DAOFactory::getDAO('InsightDAO');
     // Test default values
     $this->assertTrue($insight_plugin_parent->shouldGenerateInsight('a_slug', $instance));
     $this->assertFalse($insight_plugin_parent->shouldGenerateInsight('some_slug', $instance));
     // Test regeneration on a given date
     $this->assertTrue($insight_plugin_parent->shouldGenerateInsight('a_slug', $instance, $insight_date = $today));
     $this->assertFalse($insight_plugin_parent->shouldGenerateInsight('some_other_slug', $instance, $insight_date = $yesterday));
     $this->assertTrue($insight_plugin_parent->shouldGenerateInsight('some_other_slug', $instance, $insight_date = $yesterday, $regenerate_existing_insight = true));
     // Test for day of week
     $dow1 = date('w');
     $dow2 = date('w', strtotime('-1 day'));
     $this->assertTrue($insight_plugin_parent->shouldGenerateInsight('a_slug', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = $dow1));
     $this->assertFalse($insight_plugin_parent->shouldGenerateInsight('a_slug', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = $dow2));
     // Test with last week of posts
     $this->assertTrue($insight_plugin_parent->shouldGenerateInsight('a_slug', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = null, $count_last_week_of_posts = 13));
     $this->assertFalse($insight_plugin_parent->shouldGenerateInsight('a_slug', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = null, $count_last_week_of_posts = 0));
     // Test excluded networks
     $this->assertTrue($insight_plugin_parent->shouldGenerateInsight('a_slug', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = null, $count_last_week_of_posts = null, $excluded_networks = array('facebook')));
     $this->assertFalse($insight_plugin_parent->shouldGenerateInsight('a_slug', $instance, $insight_date = 'today', $regenerate_existing_insight = false, $day_of_week = null, $count_last_week_of_posts = null, $excluded_networks = array('twitter', 'facebook')));
 }
开发者ID:dgw,项目名称:ThinkUp,代码行数:33,代码来源:TestOfInsightPluginParent.php

示例14: generateInsight

 public function generateInsight(Instance $instance, User $user, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $user, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     if ($instance->network == 'twitter' || $instance->network == 'facebook') {
         if ($instance->network == 'facebook' && self::shouldGenerateWeeklyInsight($this->slug, $instance, 'today', false, 1)) {
             $run = true;
         } else {
             if ($instance->network == 'twitter' && self::shouldGenerateWeeklyInsight($this->slug, $instance, 'today', false, 5)) {
                 $run = true;
             }
         }
         if ($run) {
             $photo_this_week = $this->findPostWithPhoto($last_week_of_posts);
             if (!$photo_this_week) {
                 $post_dao = DAOFactory::getDAO('PostDAO');
                 $posts = $post_dao->getAllPostsByUsernameOrderedBy($instance->network_username, $instance->network, $count = 0, $order_by = "pub_date", $in_last_x_days = 14, $iterator = false, $is_public = false);
                 $photo_at_all = $this->findPostWithPhoto($posts);
                 if ($photo_at_all) {
                     $insight = new Insight();
                     $insight->slug = $this->slug;
                     $insight->instance_id = $instance->id;
                     $insight->date = $this->insight_date;
                     $days = floor((time() - strtotime($photo_at_all->pub_date)) / (60 * 60 * 24));
                     $insight->headline = $this->getVariableCopy(array("A great time for a pic", "%total days without a pic", "A thousand words unsaid"), array('total' => $days));
                     $insight->text = $this->username . " hasn't posted a photo in {$days} day" . ($days == 1 ? "" : "s") . ". " . "It might be worth finding something to share.";
                     $insight->filename = basename(__FILE__, ".php");
                     $insight->emphasis = Insight::EMPHASIS_LOW;
                     $this->insight_dao->insertInsight($insight);
                 }
             }
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:ngugijames,项目名称:ThinkUp,代码行数:35,代码来源:photoprompt.php

示例15: generateInsight

 public function generateInsight(Instance $instance, $last_week_of_posts, $number_days)
 {
     parent::generateInsight($instance, $last_week_of_posts, $number_days);
     $this->logger->logInfo("Begin generating insight", __METHOD__ . ',' . __LINE__);
     $existing_insight = $this->insight_dao->getInsight("posts_on_this_day_popular_flashback", $instance->id, $this->insight_date);
     if (!isset($existing_insight)) {
         //Generate flashback post list
         $post_dao = DAOFactory::getDAO('PostDAO');
         $flashback_posts = $post_dao->getOnThisDayFlashbackPosts($instance->network_user_id, $instance->network, $this->insight_date);
         $most_popular_post = null;
         $most_responses = 0;
         if (isset($flashback_posts) && sizeof($flashback_posts) > 0) {
             foreach ($flashback_posts as $post) {
                 $total_responses = $post->reply_count_cache + $post->all_retweets + $post->favlike_count_cache;
                 if ($total_responses > 0 && $total_responses > $most_responses) {
                     $most_popular_post = $post;
                     $most_responses = $total_responses;
                 }
             }
             if (isset($most_popular_post)) {
                 $post_year = date(date('Y', strtotime($most_popular_post->pub_date)));
                 $current_year = date('Y');
                 $number_of_years_ago = $current_year - $post_year;
                 $plural = $number_of_years_ago > 1 ? 's' : '';
                 $insight_text = "{$this->username}'s most popular post <strong>{$number_of_years_ago} year{$plural} ago" . "</strong> today was:";
                 $this->insight_dao->insertInsight("posts_on_this_day_popular_flashback", $instance->id, $this->insight_date, "Time machine:", $insight_text, basename(__FILE__, ".php"), Insight::EMPHASIS_LOW, serialize($most_popular_post));
             }
         }
     }
     $this->logger->logInfo("Done generating insight", __METHOD__ . ',' . __LINE__);
 }
开发者ID:kuthulas,项目名称:ProjectX,代码行数:31,代码来源:flashbacks.php


注:本文中的DAOFactory::getDAO方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。