<commit_before><?php

/**
 * This file is part of the OpenPNE package.
 * (c) OpenPNE Project (http://www.openpne.jp/)
 *
 * For the full copyright and license information, please view the LICENSE
 * file and the NOTICE file that were distributed with this source code.
 */

/**
 * opCalendarPluginToolkit
 *
 * @package    OpenPNE
 * @subpackage calendar
 * @author     <NAME> <<EMAIL>>
 */
class opCalendarPluginToolkit
{
  /**
   * updateGoogleCalendarCronFlags()
   *
   * Cronでの自動更新設定を反映するメソッド
   *
   * @param  String  $src            Google Api を更新する カレンダーのキーとなるソース
   * @param  Integer $cron_flag      cron 使用有無
   * @param  Integer $public_flag    スケジュールの公開範囲
   * @param  mixed   $member         Member インスタンス (Optional)
   */
  static public function updateGoogleCalendarCronFlags($src, $cron_flag, $public_flag, Member $member = null)
  {
    if (null === $member)
    {
      $member = sfContext::getInstance()->getMember();
    }

    $member->setConfig('google_cron_update', $cron_flag);
    if (!$cron_flag)
    {
      return false;
    }

    $crondata = $member->getConfig('google_cron_update_params');
    $update_params = array();
    if ($crondata)
    {
      $update_params = unserialize($crondata);
    }
    $update_params['src'][] = $src;
    $update_params['src'] = array_unique($update_params['src']);
    $update_params['public_flag'] = $public_flag;
    $member->setConfig('google_cron_update_params', serialize($update_params));
  }

  /**
   * getAllGoogleCalendarCronConfig()
   *
   * Cronでの自動更新設定を取得するメソッド
   *
   */
  static public function getAllGoogleCalendarCronConfig()
  {
    $scheduleMemberTable = Doctrine_Core::getTable('MemberConfig');
    $conn = $scheduleMemberTable->getConnection();

    $mctable = $scheduleMemberTable->getTableName();
    $sql = 'SELECT mc.member_id as member_id, mc2.value as serial,'
         . ' mc3.value as token, mc4.value as secret'
         . ' FROM '.$mctable.' as mc'
         . ' JOIN '.$mctable.' as mc2 ON mc.member_id = mc2.member_id'
         . ' JOIN '.$mctable.' as mc3 ON mc.member_id = mc3.member_id'
         . ' JOIN '.$mctable.' as mc4 ON mc.member_id = mc4.member_id'
         . ' WHERE mc.name = ? AND mc.value = ?'
         . ' AND mc2.name = ? AND mc3.name = ? AND mc4.name = ?';

    return $conn->fetchAll($sql, array(
      'google_cron_update',
      1,
      'google_cron_update_params',
      'google_calendar_oauth_token',
      'google_calendar_oauth_token_secret',
    ));
  }

  /**
   * insertSchedules()
   *
   * APIから取得した配列をScheduleに挿入するメソッド
   *
   * @param  Array   $list           スケジュールの配列
   * @param  Integer $public_flag    スケジュールの公開範囲
   * @param  Boolean $isSaveEmail  APIから取得した本人のメールアドレスを保存するか否か
   * @param  mixed   $member         Member インスタンス (Optional)
   * @return Boolean 該当する member_id、ヒットしない場合は false
   */
  static public function insertSchedules(Google_Service_Calendar_Events $events, $publicFlag, $isSaveEmail = true, Member $member = null)
  {
    static $first = true;

    $count = count($events['items']);
    $okCount = 0;

    if (null === $member)<commit_msg>(refs #3795) minimal data from opCalendarPluginToolkit::getAllGoogleCalendarCronConfig() method.<commit_after><?php

/**
 * This file is part of the OpenPNE package.
 * (c) OpenPNE Project (http://www.openpne.jp/)
 *
 * For the full copyright and license information, please view the LICENSE
 * file and the NOTICE file that were distributed with this source code.
 */

/**
 * opCalendarPluginToolkit
 *
 * @package    OpenPNE
 * @subpackage calendar
 * @author     <NAME> <<EMAIL>>
 */
class opCalendarPluginToolkit
{
  /**
   * updateGoogleCalendarCronFlags()
   *
   * Cronでの自動更新設定を反映するメソッド
   *
   * @param  String  $src            Google Api を更新する カレンダーのキーとなるソース
   * @param  Integer $cron_flag      cron 使用有無
   * @param  Integer $public_flag    スケジュールの公開範囲
   * @param  mixed   $member         Member インスタンス (Optional)
   */
  static public function updateGoogleCalendarCronFlags($src, $cron_flag, $public_flag, Member $member = null)
  {
    if (null === $member)
    {
      $member = sfContext::getInstance()->getMember();
    }

    $member->setConfig('google_cron_update', $cron_flag);
    if (!$cron_flag)
    {
      return false;
    }

    $crondata = $member->getConfig('google_cron_update_params');
    $update_params = array();
    if ($crondata)
    {
      $update_params = unserialize($crondata);
    }
    $update_params['src'][] = $src;
    $update_params['src'] = array_unique($update_params['src']);
    $update_params['public_flag'] = $public_flag;
    $member->setConfig('google_cron_update_params', serialize($update_params));
  }

  /**
   * getAllGoogleCalendarCronConfig()
   *
   * Cronでの自動更新設定を取得するメソッド
   *
   */
  static public function getAllGoogleCalendarCronConfig()
  {
    $conn = ScheduleMemberTable::getInstance()->getConnection();

    $sql = <<<EOT
SELECT
 mc.member_id AS member_id,
 mc2.value AS serial
 FROM member_config AS mc
 LEFT JOIN member_config AS mc2
 ON mc.member_id = mc2.member_id
 AND mc.name_value_hash = ?
 AND mc.name = ?
 AND mc2.name = ?
;
EOT;

    return $conn->fetchAll($sql, array(
      md5('google_cron_update,1'),
      'google_cron_update',
      'google_cron_update_params',
    ));
  }

  /**
   * insertSchedules()
   *
   * APIから取得した配列をScheduleに挿入するメソッド
   *
   * @param  Array   $list           スケジュールの配列
   * @param  Integer $public_flag    スケジュールの公開範囲
   * @param  Boolean $isSaveEmail  APIから取得した本人のメールアドレスを保存するか否か
   * @param  mixed   $member         Member インスタンス (Optional)
   * @return Boolean 該当する member_id、ヒットしない場合は false
   */
  static public function insertSchedules(Google_Service_Calendar_Events $events, $publicFlag, $isSaveEmail = true, Member $member = null)
  {
    static $first = true;

    $count = count($events['items']);
    $okCount = 0;

    if (null === $member)
{'fraction_non_alphanumeric': 0.12342311626321173, 'fraction_numerical': 0.0042618479372655985, 'mean_word_length': 3.152158527954706, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2878228', 'n_tokens_mistral': 2186, 'n_tokens_neox': 2140, 'n_words': 420}