Exemple #1
0
 public static function fromTransaction(Transaction $transaction, PropelPDO $con = null)
 {
     $transactionId = $transaction->getId();
     $bookingData = array();
     $bookings = BookingQuery::create()->filterByTransactionId($transactionId)->find($con);
     foreach ($bookings as $booking) {
         $bookingData[] = self::from($booking, $con);
     }
     $clockingData = array();
     $clockings = ClockingQuery::create()->joinTransactionClocking()->joinWith('ClockingType')->add(TransactionClockingPeer::TRANSACTION_ID, $transactionId)->find($con);
     foreach ($clockings as $clocking) {
         $clockingData[] = self::from($clocking, $con) + array('Type' => self::from($clocking->getClockingType($con), $con));
     }
     return array('Start' => $transaction->getStart('U'), 'End' => $transaction->getEnd('U'), 'Bookings' => $bookingData, 'Clockings' => $clockingData, 'User' => self::from($transaction->getUserRelatedByUserId($con), $con)) + $transaction->toArray();
 }
 /**
  * Exports the object as an array.
  *
  * You can specify the key type of the array by passing one of the class
  * type constants.
  *
  * @param     string  $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  *                    BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  *                    Defaults to BasePeer::TYPE_PHPNAME.
  * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
  * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
  * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
  *
  * @return array an associative array containing the field names (as keys) and field values
  */
 public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
 {
     if (isset($alreadyDumpedObjects['TransactionClocking'][serialize($this->getPrimaryKey())])) {
         return '*RECURSION*';
     }
     $alreadyDumpedObjects['TransactionClocking'][serialize($this->getPrimaryKey())] = true;
     $keys = TransactionClockingPeer::getFieldNames($keyType);
     $result = array($keys[0] => $this->getTransactionId(), $keys[1] => $this->getClockingId());
     if ($includeForeignObjects) {
         if (null !== $this->aClocking) {
             $result['Clocking'] = $this->aClocking->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
         }
         if (null !== $this->aTransaction) {
             $result['Transaction'] = $this->aTransaction->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
         }
     }
     return $result;
 }
Exemple #3
0
 /**
  * Exports the object as an array.
  *
  * You can specify the key type of the array by passing one of the class
  * type constants.
  *
  * @param     string  $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  *                    BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  *                    Defaults to BasePeer::TYPE_PHPNAME.
  * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to true.
  * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
  * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
  *
  * @return array an associative array containing the field names (as keys) and field values
  */
 public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
 {
     if (isset($alreadyDumpedObjects['Booking'][$this->getPrimaryKey()])) {
         return '*RECURSION*';
     }
     $alreadyDumpedObjects['Booking'][$this->getPrimaryKey()] = true;
     $keys = BookingPeer::getFieldNames($keyType);
     $result = array($keys[0] => $this->getId(), $keys[1] => $this->getTransactionId(), $keys[2] => $this->getBookingTypeId(), $keys[3] => $this->getLabel(), $keys[4] => $this->getValue());
     if ($includeForeignObjects) {
         if (null !== $this->aTransaction) {
             $result['Transaction'] = $this->aTransaction->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
         }
         if (null !== $this->aBookingType) {
             $result['BookingType'] = $this->aBookingType->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
         }
     }
     return $result;
 }
 public function newTransaction()
 {
     $transaction = new Transaction();
     $transaction->amount = floatval(Input::get('amount'));
     $transaction->fireflyuser_id = Auth::user()->id;
     $transaction->date = Input::get('date');
     $transaction->onetime = Input::get('onetime') == 'on' ? 1 : 0;
     $transaction->description = Input::get('description');
     if (Input::get('type') == 'min') {
         $transaction->amount = $transaction->amount * -1;
     }
     if (!is_null(Input::get('account'))) {
         $account = Auth::user()->accounts()->find(Input::get('account'));
         if (!is_null($account)) {
             $transaction->account_id = $account->id;
         }
     }
     // budget
     if (intval(Input::get('budget')) > 0) {
         $budget = Auth::user()->budgets()->find(intval(Input::get('budget')));
         if (!is_null($budget)) {
             $transaction->budget_id = $budget->id;
         }
     }
     // category
     if (strlen(Input::get('category')) != 0) {
         $categories = Auth::user()->categories()->get();
         //->where('name','=',Input::get('category'))->first();
         $category = null;
         foreach ($categories as $cat) {
             if (Crypt::decrypt($cat->name) == Input::get('category')) {
                 $category = $cat;
                 break;
             }
         }
         unset($cat, $categories);
         if (is_null($category)) {
             $category = new Category();
             $category->fireflyuser_id = Auth::user()->id;
             $category->name = Input::get('category');
             $category->showtrend = 0;
             $category->icon_id = Icon::first()->id;
             // FIXME moet niet hardcoded
             $validator = Validator::make($category->toArray(), Category::$rules);
             if ($validator->passes()) {
                 $category->name = Crypt::encrypt($category->name);
                 $category->save();
                 $transaction->category_id = $category->id;
             }
         } else {
             $transaction->category_id = $category->id;
         }
     }
     // beneficiary
     if (strlen(Input::get('beneficiary')) != 0) {
         $beneficiaries = Auth::user()->beneficiaries()->get();
         //->where('name','=',Input::get('beneficiary'))->first();
         $beneficiary = null;
         foreach ($beneficiaries as $ben) {
             if (Crypt::decrypt($ben->name) == Input::get('beneficiary')) {
                 $beneficiary = $ben;
                 break;
             }
         }
         unset($ben, $categories);
         if (is_null($beneficiary)) {
             $beneficiary = new Beneficiary();
             $beneficiary->fireflyuser_id = Auth::user()->id;
             $beneficiary->name = Input::get('beneficiary');
             $validator = Validator::make($beneficiary->toArray(), Beneficiary::$rules);
             if ($validator->passes()) {
                 $beneficiary->name = Crypt::encrypt($beneficiary->name);
                 $beneficiary->save();
                 $transaction->beneficiary_id = $beneficiary->id;
             }
         } else {
             $transaction->beneficiary_id = $beneficiary->id;
         }
     }
     $validator = Validator::make($transaction->toArray(), Transaction::$rules);
     $transaction->description = Crypt::encrypt($transaction->description);
     if ($validator->fails()) {
         return Redirect::to('/home/transaction/add')->withErrors($validator)->withInput();
     } else {
         // the transaction was valid! lets save some tags!
         $transaction->save();
         if (Input::get('tags') != null && strlen(Input::get('tags')) > 0) {
             $tags = explode(',', Input::get('tags'));
             foreach ($tags as $tag) {
                 $dbTag = Tag::findOrCreate($tag);
                 $transaction->tags()->attach($dbTag);
             }
         }
         return Redirect::to('/home/transaction/add');
     }
 }