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));
         }
     }
 }
 public function saveMember(Community $community)
 {
     if ($this->isNew()) {
         $member = new CommunityMember();
         $member->setPosition('admin');
         $member->setMemberId(sfContext::getInstance()->getUser()->getMemberId());
         $member->setCommunity($community);
         $member->save();
     }
 }
  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 ($isRegisterPolicy == 'close') {
         $communityMember->setIsPre(true);
     }
     $communityMember->save();
 }
  private function createCluster($memberNum, $offset)
  {
    $memberIds = array();  
    $members = Doctrine::getTable('Member')->createQuery()->select('id')->where('is_active != 0')->limit($memberNum)->offset($memberNum * $offset)->execute();

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

      $community->setName(sprintf('dummy%d community', $community->getId()));
      $community->save();

      $configData = array(
        array('description', $community->getName()),
        array('topic_authority', 'public'),
        array('public_flag', 'public'),
        array('register_policy', 'open')
      );

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

      for ($j = 0; $j < $memberNum; ++$j)
      {
        $communityMember = new CommunityMember();
        $communityMember->setCommunity($community);
        $communityMember->setMember($members[$j]);
        if (0 == $j)
        {
          $communityMember->addPosition('admin');
        }
        $communityMember->save();
      }
    }
  }
 public function insert(SimpleXMLElement $xml)
 {
     $member = Doctrine::getTable('Member')->find($this->getMemberIdByUrl((string) $xml->author->uri));
     if (!$member) {
         return false;
     }
     $community = new Community();
     $community->setName((string) $xml->title);
     $community->save();
     $admin = new CommunityMember();
     $admin->setPosition('admin');
     $admin->setMember($member);
     $admin->setCommunity($community);
     $admin->save();
     $config = new CommunityConfig();
     $config->setName('description');
     $config->setValue((string) $xml->content);
     $config->setCommunity($community);
     $config->save();
     return $community;
 }
 public function listenToPostActionEventCommunityJoin($arguments)
 {
     $memberId = sfContext::getInstance()->getUser()->getMemberId();
     $communityId = $arguments['actionInstance']->getVar('id');
     $communityMember = Doctrine::getTable('CommunityMember')->retrieveByMemberIdAndCommunityId($memberId, $communityId);
     if (!$communityMember) {
         $communityMember = new CommunityMember();
         $communityMember->setCommunityId($communityId);
         $communityMember->setMemberId($memberId);
         $communityMember->setIsPre(true);
     }
     if ($communityMember->getIsPre()) {
         $isInvited = opCommunityIntroductionPlugin::isInvitedCommunity($communityId, $memberId);
         if ($isInvited) {
             $communityMember->setIsPre(false);
             $communityMember->save();
             sfContext::getInstance()->getUser()->setFlash('notice', 'You have just joined to this %community%.');
             sfContext::getInstance()->getController()->redirect('community/home?id=' . $communityId);
         }
     }
 }
 protected function executeTransaction($conn, $arguments = array(), $options = array())
 {
     $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.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();
         }
         $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();
         $this->logSection('community+', $community->getName());
     }
 }
Beispiel #9
0
 public static function CommunityLink($community, $print = true, $leave = false)
 {
     if (is_null($individual = Main::user())) {
         throw new CException('Respective user is null.');
     }
     if (is_null($community)) {
         throw new CException('Respective community is null.');
     } else {
         $membership = CommunityMember::model()->find('community_id=' . $community->id . ' and individual_id=' . $individual->id);
     }
     $content = null;
     if (is_null($membership)) {
         $content .= CHtml::form(array('/community/member/join/' . $community->id));
         $content .= CHtml::hiddenField('individual_id', $individual->id);
         $content .= CHtml::submitButton('Join', array('class' => 'friend_sarch_btn'));
         $content .= CHtml::endForm();
     } else {
         switch ($membership->status) {
             case 0:
                 // for deactive membership.
                 $content .= CHtml::form(array('/community/member/join/' . $community->id));
                 $content .= CHtml::hiddenField('individual_id', $individual->id);
                 $content .= CHtml::submitButton('Join', array('class' => 'friend_sarch_btn'));
                 $content .= CHtml::endForm();
                 break;
             case 1:
                 if (!(Yii::app()->user->id === $community->owner->id) and $leave) {
                     $content .= CHtml::form(array('/community/member/leave/' . $community->id));
                     $content .= CHtml::hiddenField('individual_id', $individual->id);
                     $content .= CHtml::submitButton('Leave', array('class' => 'friend_sarch_btn', 'onclick' => "return confirm('Are you sure to leave this community ?')"));
                     $content .= CHtml::endForm();
                 } else {
                     //$content.=CHtml::link('Settings',array('/community/requests/'.$community->id),array('class'=>'friend_sarch_btn'));
                     //$content.=CHtml::button('Requests',array('class'=>'friend_sarch_btn','onclick'=>Yii::app()->homeUrl));
                 }
                 break;
             case 2:
                 $content .= CHtml::button('Request Sent', array('class' => 'friend_sarch_btn'));
                 break;
             default:
                 break;
         }
     }
     if ($print) {
         echo $content;
     } else {
         return $content;
     }
 }