コード例 #1
0
  protected function execute($arguments = array(), $options = array())
  {
    $databaseManager = new sfDatabaseManager($this->configuration);
    $this->conn = $databaseManager->getDatabase('doctrine')->getDoctrineConnection();

    $sql = 'SELECT id FROM community';
    $where = array();
    if ( $options['cmin'] && $options['cmax']  && $options['cmin'] <= $options['cmax'])
    {
        $sql .= ' WHERE id BETWEEN ? AND ?';
        $where = array(intval($options['cmin']),intval($options['cmax']));
    }
    $commuIds = $this->conn->fetchColumn($sql, $where);
    foreach ($commuIds as $cid)
    {
      for ($i=0; $i < $options['number']; ++$i)
      {
        $ct = new CommunityTopic();
        $ct->setCommunity(Doctrine::getTable('community')->find($cid));
        $ct->setMemberId(self::fetchRandomMemberId($cid));
        $ct->setName('name');
        $ct->setBody('body');
        $ct->save();
        $ct->free();
        $this->logSection('created a community topic', sprintf("%s", $cid));
      }
    }
  }
コード例 #2
0
 protected function executeTransaction($conn, $arguments = array(), $options = array())
 {
     $communities = Doctrine::getTable('Community')->findAll(Doctrine::HYDRATE_ARRAY);
     foreach ($communities as $community) {
         for ($i = 0; $i < $options['number']; ++$i) {
             $ct = new CommunityTopic();
             $ct->setCommunityId($community['id']);
             $ct->setMemberId(self::fetchRandomMemberId($community['id']));
             $ct->setName('name');
             $ct->setBody('body');
             $ct->save();
             $ct->free();
             $this->logSection('created a community topic', sprintf("%s", $community['id']));
         }
     }
 }
コード例 #3
0
 public function insert(SimpleXMLElement $xml)
 {
     $member = Doctrine::getTable('Member')->find($this->getMemberIdByUrl((string) $xml->author->uri));
     if (!$member) {
         return false;
     }
     if ($this->member) {
         $acl = $this->getCollectionAcl($this->getParentObject(), $this->member);
         if (!$acl || !$acl->isAllowed($this->member->id, null, 'add')) {
             return false;
         }
     }
     $topic = new CommunityTopic();
     $topic->setMember($member);
     $topic->setCommunity($this->getParentObject());
     $topic->setName((string) $xml->title);
     $topic->setBody((string) $xml->content);
     $topic->save();
     return $topic;
 }
コード例 #4
0
ファイル: actions.class.php プロジェクト: te-koyama/openpne
 public function executePost(sfWebRequest $request)
 {
     try {
         $topicId = $request->getParameter('id');
         $communityId = $request->getParameter('community_id');
         $this->isValidNameAndBody($request->getParameter('name'), $request->getParameter('body'));
         if ($topicId) {
             $topic = $this->getTargetObject('topic', $topicId);
         } else {
             $this->forward400If(!$communityId, 'community_id parameter is not specified.');
             $topic = new CommunityTopic();
             $topic->setMemberId($this->member->getId());
             $topic->setCommunityId($communityId);
         }
         $this->forward400If(!$this->isAllowed($topic->getCommunity(), $this->member, 'add'), 'you are not allowed to create or update topics on this community');
         $topic->setName($request['name']);
         $topic->setBody($request['body']);
         $topic->save();
     } catch (opCommunityTopicAPIRuntimeException $e) {
         $this->forward400($e->getMessage());
     }
     $this->topic = $topic;
 }