protected function executeTransaction($conn, $arguments = array(), $options = array())
 {
     $members = Doctrine::getTable('Member')->findAll(Doctrine::HYDRATE_ARRAY);
     $communities = Doctrine::getTable('Community')->findAll(Doctrine::HYDRATE_ARRAY);
     if (count($communities) < $options['number']) {
         throw new Exception('Too few communities. Please run "opKdt:generate-community" first.');
     }
     $communityIds = array_map(create_function('$c', 'return (int)$c[\'id\'];'), $communities);
     foreach ($members as $member) {
         $joinCommunities = Doctrine::getTable('Community')->retrievesByMemberId($member['id'], null);
         $joinCommunityIds = array();
         if ($joinCommunities) {
             foreach ($joinCommunities as $c) {
                 $joinCommunityIds[] = $c->getId();
             }
         }
         $candidate = array_diff($communityIds, $joinCommunityIds);
         shuffle($candidate);
         $candidateSlices = array_slice($candidate, 0, $options['number']);
         foreach ($candidateSlices as $communityId) {
             $cm = new CommunityMember();
             $cm->setCommunityId($communityId);
             $cm->setMemberId($member['id']);
             $cm->save();
             $cm->free();
             $this->logSection('added a community member', sprintf("%s - %s", $member['id'], $communityId));
         }
     }
 }
  protected function execute($arguments = array(), $options = array())
  {
    $databaseManager = new sfDatabaseManager($this->configuration);
    $this->conn = $databaseManager->getDatabase('doctrine')->getDoctrineConnection();

    $sql = 'SELECT id FROM member WHERE is_active != 0';
    $where = array();
    if ( $options['min'] && $options['max']  && $options['min'] <= $options['max'])
    {
        $sql .= ' AND id BETWEEN ? AND ?';
        $where = array(intval($options['min']),intval($options['max']));
    }
    $memberIds = $this->conn->fetchColumn($sql, $where);

    $communities = Doctrine::getTable('Community')->findAll(Doctrine::HYDRATE_ARRAY);
    if (count($communities) < $options['number'])
    {
      throw new Exception('Too few communities. Please run "opKdt:generate-community" first.');
    }
    $communityIds = array_map(create_function('$c', 'return (int)$c[\'id\'];'), $communities);

    foreach ($memberIds as $memberid)
    {
      $joinCommunities = Doctrine::getTable('Community')->retrievesByMemberId($memberid, null);
      $joinCommunityIds = array();
      if ($joinCommunities)
      {
        foreach ($joinCommunities as $c)
        {
          $joinCommunityIds[] = $c->getId();
        }
      }

      $candidate = array_diff($communityIds, $joinCommunityIds);
      shuffle($candidate);
      $candidateSlices = array_slice($candidate, 0, $options['number']);

      foreach ($candidateSlices as $communityId)
      {
        $cm = new CommunityMember();
        $cm->setCommunityId($communityId);
        $cm->setMemberId($memberid);
        $cm->save();
        $cm->free();
        $this->logSection('added a community member', sprintf("%s - %s", $memberid, $communityId));
      }
    }
  }
 public function join($memberId, $communityId, $isRegisterPolicy = 'open')
 {
     if ($this->isPreMember($memberId, $communityId)) {
         throw new Exception('This member has already applied this community.');
     }
     if ($this->isMember($memberId, $communityId)) {
         throw new Exception('This member has already joined this community.');
     }
     $communityMember = new CommunityMember();
     $communityMember->setMemberId($memberId);
     $communityMember->setCommunityId($communityId);
     if ('close' === $isRegisterPolicy) {
         $communityMember->setIsPre(true);
     }
     $communityMember->save();
     $communityMember->free(true);
 }
  protected function execute($arguments = array(), $options = array())
  {
    $databaseManager = new sfDatabaseManager($this->configuration);

    $n = (int)$options['number'];

    $adminMember = Doctrine::getTable('Member')->find($options['admin-member']);
    if (!$adminMember)
    {
      throw new Exception("not found member: ".$options['admin-member']);
    }

    $communityCategory = Doctrine::getTable('CommunityCategory')->find($options['category']);
    if (!$communityCategory)
    {
      throw new Exception("not found category: ".$options['category']);
    }

    for ($i = 0; $i < $n; $i++)
    {
      $community = new Community();
      $community->setName('dummy');
      $community->setCommunityCategory($communityCategory);
      $community->save();

      $community->setName(sprintf($options['name-format'], $community->getId()));
      $community->save();

      $configData = array(
        array('description', $community->getName()),
      );

      if (version_compare(OPENPNE_VERSION, '3.6.0-dev', '>='))
      {
        // new version
        $configData[] = array('topic_authority', 'public');
        $configData[] = array('public_flag', 'public');
      }

      if (version_compare(OPENPNE_VERSION, '3.5.0-dev', '>='))
      {
        // new version
        $configData[] = array('register_policy', 'open');
      }
      else
      {
        // old version
        $configData[] = array('register_poricy', 'open');
      }

      foreach ($configData as $config)
      {
        $communityConfig = new CommunityConfig();
        $communityConfig->setCommunity($community);
        $communityConfig->setName($config[0]);
        $communityConfig->setValue($config[1]);
        $communityConfig->save();
        $communityConfig->free();
      }

      $communityMember = new CommunityMember();
      $communityMember->setCommunity($community);
      $communityMember->setMember($adminMember);

      if (version_compare(OPENPNE_VERSION, '3.3.1-dev', '>='))
      {
        $communityMember->addPosition('admin');
      }
      else
      {
        $communityMember->setPosition('admin');
      }

      $communityMember->save();
      $communityMember->free();
      $this->logSection('community+', $community->getName());
    }
  }