コード例 #1
0
 public function create()
 {
     $tweet = new Tweet();
     $fromAccount = false;
     if ($this->GetData('account_id')) {
         $account = TwitterAccount::find_by_id($this->GetData('account_id'));
         if ($account) {
             $fromAccount = true;
             $tweet->twitter_account_id = $account->id;
             $tweet->account = $account;
         }
     }
     if ($this->post) {
         $tweet->message = $this->PostData('message');
         $tweet->set_publish_at($this->PostData('publish_at'));
         if ($this->PostData('twitter_account_id')) {
             $tweet->twitter_account_id = $this->PostData('twitter_account_id');
         }
         if ($tweet->save()) {
             Site::Flash('notice', 'Your tweet has been added');
             if ($fromAccount) {
                 Redirect("admin/twitter/accounts/{$account->id}/");
             } else {
                 Redirect("admin/twitter/tweets");
             }
         }
     }
     if ($fromAccount) {
         $this->assign('account', $account);
     } else {
         $accounts = array();
         $allAccounts = TwitterAccount::find_all();
         foreach ($allAccounts as $account) {
             $accounts[$account->id] = $account->name;
         }
         $this->assign('accounts', $accounts);
     }
     $this->assign("tweet", $tweet);
     $this->assign("fromAccount", $fromAccount);
     $this->title = "Add Tweet";
     $this->render("tweet/create.tpl");
 }