Beispiel #1
0
 /**
  * Save the current balance
  *
  * @param   string   $type  Record type (inserting or updating)
  * @return  boolean  True on success
  */
 public function _saveBalance($type)
 {
     if ($type == 'creation') {
         $model = Account::blank();
     } else {
         $model = Account::oneByUserId($this->uid);
     }
     $model->set(['uid' => $this->uid, 'balance' => $this->balance, 'earnings' => $this->earnings, 'credit' => $this->credit]);
     if (!$model->save()) {
         $this->setError($model->getError());
         return false;
     }
     return true;
 }
Beispiel #2
0
 /**
  * Remove all user blog entries for the given user ID
  *
  * Method is called after user data is deleted from the database
  *
  * @param   array    $user     Holds the user data
  * @param   boolean  $success  True if user was succesfully stored in the database
  * @param   string   $msg      Message
  * @return  boolean
  */
 public function onMemberAfterDelete($user, $success, $msg)
 {
     if (!$success) {
         return false;
     }
     $userId = \Hubzero\Utility\Arr::getValue($user, 'id', 0, 'int');
     if ($userId) {
         try {
             $entry = \Hubzero\Bank\Account::oneByUserId($user['id']);
             if (!$entry->destroy()) {
                 throw new Exception($entry->getError());
             }
             $transactions = \Hubzero\Bank\Transaction::all()->whereEquals('uid', $user['id']);
             foreach ($transactions->rows() as $row) {
                 if (!$row->destroy()) {
                     throw new Exception($row->getError());
                 }
             }
         } catch (Exception $e) {
             return false;
         }
     }
     return true;
 }
Beispiel #3
0
 /**
  * Edit an entry
  *
  * @return     void
  */
 public function editTask()
 {
     if ($uid = Request::getInt('uid', 0)) {
         $this->view->row = \Hubzero\Bank\Account::oneByUserId($uid);
         if (!$this->view->row->get('balance')) {
             $this->view->row->set('uid', $uid);
             $this->view->row->set('balance', 0);
             $this->view->row->set('earnings', 0);
         }
         $this->database->setQuery("SELECT * FROM `#__users_transactions` WHERE uid=" . $uid . " ORDER BY created DESC, id DESC");
         $this->view->history = $this->database->loadObjectList();
     } else {
         $this->view->setLayout('find');
     }
     // Set any errors
     foreach ($this->getErrors() as $error) {
         $this->view->setError($error);
     }
     // Output the HTML
     $this->view->display();
 }