/**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make(Input::all(), array('name' => 'required'));
     if ($validator->fails()) {
         return Response::json($validator->messages(), 400);
     }
     $category = new Category();
     $category->name = Input::get('name');
     $category->description = Input::get('description');
     $category->save();
     return Response::json(array('success_code' => 'OK', 'data' => $category->toArray()), 200);
 }
Example #2
0
 /**
  * Store a newly created resource in storage.
  * POST /categories
  *
  * @return Response
  */
 public function store()
 {
     //
     $category = new Category();
     $category->name = Request::get('name');
     $category->description = Request::get('description');
     //$category->user_id = Auth::user()->id;
     // Validation and Filtering is sorely needed!!
     // Seriously, I'm a bad person for leaving that out.
     if (Auth::user()->id == 1) {
         $category->save();
         return Response::json(array('error' => false, 'categories' => $category->toArray()), 200);
     } else {
         return Response::json(array('error' => true, 'reason' => 'Error with user id' . Auth::user()->id), 200);
     }
 }
Example #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['Product'][$this->getPrimaryKey()])) {
         return '*RECURSION*';
     }
     $alreadyDumpedObjects['Product'][$this->getPrimaryKey()] = true;
     $keys = ProductPeer::getFieldNames($keyType);
     $result = array($keys[0] => $this->getEntityId(), $keys[1] => $this->getName(), $keys[2] => $this->getPrice(), $keys[3] => $this->getSku(), $keys[4] => $this->getDateCreated(), $keys[5] => $this->getCategoryId(), $keys[6] => $this->getUrlKey(), $keys[7] => $this->getProductImage());
     $virtualColumns = $this->virtualColumns;
     foreach ($virtualColumns as $key => $virtualColumn) {
         $result[$key] = $virtualColumn;
     }
     if ($includeForeignObjects) {
         if (null !== $this->aCategory) {
             $result['Category'] = $this->aCategory->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
         }
     }
     return $result;
 }
 /**
  * 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 TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME,
  *                    TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
  *                    Defaults to TableMap::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 = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
 {
     if (isset($alreadyDumpedObjects['GoogleshoppingTaxonomy'][$this->getPrimaryKey()])) {
         return '*RECURSION*';
     }
     $alreadyDumpedObjects['GoogleshoppingTaxonomy'][$this->getPrimaryKey()] = true;
     $keys = GoogleshoppingTaxonomyTableMap::getFieldNames($keyType);
     $result = array($keys[0] => $this->getId(), $keys[1] => $this->getTheliaCategoryId(), $keys[2] => $this->getGoogleCategory(), $keys[3] => $this->getLangId());
     $virtualColumns = $this->virtualColumns;
     foreach ($virtualColumns as $key => $virtualColumn) {
         $result[$key] = $virtualColumn;
     }
     if ($includeForeignObjects) {
         if (null !== $this->aCategory) {
             $result['Category'] = $this->aCategory->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
         }
         if (null !== $this->aLang) {
             $result['Lang'] = $this->aLang->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
         }
     }
     return $result;
 }
 /**
  * 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 TableMap::TYPE_PHPNAME, TableMap::TYPE_STUDLYPHPNAME,
  *                    TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM.
  *                    Defaults to TableMap::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 = TableMap::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
 {
     if (isset($alreadyDumpedObjects['CriteriaSearchCategoryFeature'][$this->getPrimaryKey()])) {
         return '*RECURSION*';
     }
     $alreadyDumpedObjects['CriteriaSearchCategoryFeature'][$this->getPrimaryKey()] = true;
     $keys = CriteriaSearchCategoryFeatureTableMap::getFieldNames($keyType);
     $result = array($keys[0] => $this->getId(), $keys[1] => $this->getCategoryId(), $keys[2] => $this->getFeatureId(), $keys[3] => $this->getSearchable());
     $virtualColumns = $this->virtualColumns;
     foreach ($virtualColumns as $key => $virtualColumn) {
         $result[$key] = $virtualColumn;
     }
     if ($includeForeignObjects) {
         if (null !== $this->aCategory) {
             $result['Category'] = $this->aCategory->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
         }
         if (null !== $this->aFeature) {
             $result['Feature'] = $this->aFeature->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
         }
     }
     return $result;
 }
Example #6
0
 public function doEditTransfer($id)
 {
     $transfer = Auth::user()->transfers()->find($id);
     if ($transfer) {
         $transfer->amount = floatval(Input::get('amount'));
         $transfer->description = Input::get('description');
         $transfer->date = Input::get('date');
         // account_from (special)
         if (!is_null(Input::get('account_from'))) {
             $account = Auth::user()->accounts()->find(Input::get('account_from'));
             if (!is_null($account)) {
                 $transfer->account_from = $account->id;
             }
         }
         // account_to (special)
         if (!is_null(Input::get('account_to'))) {
             $account = Auth::user()->accounts()->find(Input::get('account_to'));
             if (!is_null($account)) {
                 $transfer->account_to = $account->id;
             }
         }
         // category (special)
         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;
                 $validator = Validator::make($category->toArray(), Category::$rules);
                 if ($validator->passes()) {
                     $category->name = Crypt::encrypt($category->name);
                     $category->save();
                     $transfer->category_id = $category->id;
                 }
             } else {
                 $transfer->category_id = $category->id;
             }
         } else {
             $transfer->category_id = null;
         }
         // budget (special)
         if (intval(Input::get('budget')) > 0) {
             $budget = Auth::user()->budgets()->find(intval(Input::get('budget')));
             if (!is_null($budget)) {
                 $transfer->budget_id = $budget->id;
             }
         }
         // target (special)
         if (strlen(Input::get('target')) > 0) {
             $targets = Auth::user()->targets()->get();
             //->where('name','=',Input::get('category'))->first();
             $target = null;
             foreach ($targets as $t) {
                 if (Crypt::decrypt($t->description) == Input::get('target')) {
                     $transfer->target_id = $t->id;
                     break;
                 }
             }
             unset($targets, $t);
         } else {
             $transfer->target_id = null;
         }
         $validator = Validator::make($transfer->toArray(), Transfer::$rules);
         $transfer->description = Crypt::encrypt($transfer->description);
         if ($validator->fails()) {
             return Redirect::to('/home/transfer/edit/' . $transfer->id)->withErrors($validator)->withInput();
         } else {
             $transfer->save();
             return Redirect::to('/home');
         }
     } else {
         App::abort(404);
     }
 }
 public function doEditTransaction($id)
 {
     $transaction = Auth::user()->transactions()->find($id);
     if ($transaction) {
         // set some basic values:
         $transaction->amount = floatval(Input::get('amount'));
         $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;
             }
         } else {
             $transaction->category_id = null;
         }
         // 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;
             }
         } else {
             $transaction->beneficiary_id = null;
         }
         $validator = Validator::make($transaction->toArray(), Transaction::$rules);
         $transaction->description = Crypt::encrypt($transaction->description);
         if ($validator->fails()) {
             return Redirect::to('/home/transaction/edit/' . $transaction->id)->withErrors($validator)->withInput();
         } else {
             // work the tags
             $tags = explode(',', Input::get('tags'));
             $sync = array();
             foreach ($tags as $tag) {
                 $dbTag = Tag::findOrCreate($tag);
                 $sync[] = $dbTag->id;
             }
             $transaction->tags()->sync($sync);
             $transaction->save();
             return Redirect::to('/home/transactions');
         }
     } else {
         return App::abort(404);
     }
 }