/** * Store a newly created resource in storage. * * @return Response */ public function store() { $validator = $this->validate(); if ($validator->fails()) { if (Request::ajax()) { return Response::json(array('success' => false, 'messages' => $validator->messages())); } return Redirect::back()->withErrors($validator->messages())->withInput(Input::all()); } $donor = new Donor(); $donor->name = Input::get('name'); $donor->dob = Input::get('dob'); $donor->nic = Input::get('nic'); $donor->gender = Input::get('gender'); $donor->telephone = Input::get('telephone'); $donor->blood_group_id = Input::get('blood_group_id'); $donor->email = Input::get('email'); $donor->address = Input::get('address'); $donor->details = Input::get('details'); $donor->save(); if (Request::ajax()) { return Response::json(array('success' => true, 'donors' => [''] + Donor::all()->lists('name_with_blood_group', 'id'), 'donor_id' => $donor->id)); } Session::flash('success', 'Successfully created donor!'); return Redirect::route('donor.index'); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'show' page. */ public function actionCreate() { $model = new Donor(); if (isset($_POST['Donor'])) { $model->attributes = $_POST['Donor']; $model->companyId = Yii::app()->user->getState('selectedCompanyId'); if ($model->save()) { ChangeLog::addLog('ADD', 'Donor', $model->toString()); $this->redirect(array('admin', 'id' => $model->id)); } } $model->dateChanged = User::getDateFormatted(date('Y-m-d')); $this->render('create', array('model' => $model)); }
public function actionCreate() { $model = new Donor(); if (isset($_POST['Donor'])) { $model->setAttributes($_POST['Donor']); if ($model->save()) { if (Yii::app()->getRequest()->getIsAjaxRequest()) { Yii::app()->end(); } else { $this->redirect(array('view', 'id' => $model->id)); } } } $this->render('create', array('model' => $model)); }
/** * Run the database seeds. * * @return void */ public function run() { Eloquent::unguard(); DB::table('donors')->truncate(); $donor = new Donor(); $donor->name = "Lorem Ipsum"; $donor->dob = '1980-10-10'; $donor->blood_group_id = 1; $donor->gender = 1; $donor->save(); $donor = new Donor(); $donor->name = "Dolar Sit"; $donor->dob = '1980-10-10'; $donor->blood_group_id = 2; $donor->gender = 2; $donor->save(); $donor = new Donor(); $donor->name = "Amet Lo"; $donor->dob = '1980-10-10'; $donor->blood_group_id = 1; $donor->gender = 1; $donor->save(); $donor = new Donor(); $donor->name = "Consectetur"; $donor->dob = '1980-10-10'; $donor->blood_group_id = 4; $donor->gender = 2; $donor->save(); $donor = new Donor(); $donor->name = "Voluptatem"; $donor->dob = '1980-10-10'; $donor->blood_group_id = 6; $donor->gender = 2; $donor->save(); $donor = new Donor(); $donor->name = "Lorem Ipsum"; $donor->dob = '1980-10-10'; $donor->blood_group_id = 1; $donor->gender = 1; $donor->save(); $donor = new Donor(); $donor->name = "Dolar Sit"; $donor->dob = '1980-10-10'; $donor->blood_group_id = 2; $donor->gender = 2; $donor->save(); $donor = new Donor(); $donor->name = "Amet Lo"; $donor->dob = '1980-10-10'; $donor->blood_group_id = 1; $donor->gender = 1; $donor->save(); $donor = new Donor(); $donor->name = "Consectetur"; $donor->dob = '1980-10-10'; $donor->blood_group_id = 4; $donor->gender = 2; $donor->save(); $donor = new Donor(); $donor->name = "Voluptatem"; $donor->dob = '1980-10-10'; $donor->blood_group_id = 6; $donor->gender = 2; $donor->save(); }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aDonor !== null) { if ($this->aDonor->isModified() || $this->aDonor->isNew()) { $affectedRows += $this->aDonor->save($con); } $this->setDonor($this->aDonor); } if ($this->aGiftTypeRelatedByGiftType !== null) { if ($this->aGiftTypeRelatedByGiftType->isModified() || $this->aGiftTypeRelatedByGiftType->isNew()) { $affectedRows += $this->aGiftTypeRelatedByGiftType->save($con); } $this->setGiftTypeRelatedByGiftType($this->aGiftTypeRelatedByGiftType); } if ($this->aCampaign !== null) { if ($this->aCampaign->isModified() || $this->aCampaign->isNew()) { $affectedRows += $this->aCampaign->save($con); } $this->setCampaign($this->aCampaign); } if ($this->aFund !== null) { if ($this->aFund->isModified() || $this->aFund->isNew()) { $affectedRows += $this->aFund->save($con); } $this->setFund($this->aFund); } if ($this->isNew()) { $this->modifiedColumns[] = DonationPeer::ID; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = DonationPeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setId($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += DonationPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } $this->alreadyInSave = false; } return $affectedRows; }
/** * Add or edit donor * CODE: donor_create */ public function executeUpdate(sfWebRequest $request) { # security if (!$this->getUser()->hasCredential(array('Administrator'), false)) { $this->getUser()->setFlash("warning", 'You don\'t have permission to access this url ' . $request->getReferer()); $this->redirect('dashboard/index'); } if ($request->getParameter('id')) { $donor = DonorPeer::retrieveByPK($request->getParameter('id')); $this->forward404Unless($donor); $this->title = 'Edit donor'; $success = 'Donor information has been successfully changed!'; } else { $donor = new Donor(); $this->title = 'Add new donor'; $success = 'Donor information has been successfully created!'; } $this->back = $request->getReferer(); $this->form = new DonorForm($donor); if ($request->isMethod('post')) { $this->referer = $request->getReferer(); $this->form->bind($request->getParameter('donor')); if ($this->form->isValid()) { $donor->setCoDonorId($this->form->getValue('co_donor_id')); if ($this->form->getValue('affiliation_id') == 0) { $donor->setAffiliationId(null); } else { $donor->setAffiliationId($this->form->getValue('affiliation_id')); } if ($this->form->getValue('block_mailings') == null) { $donor->setBlockMailings(0); } else { $donor->setBlockMailings($this->form->getValue('block_mailings')); } $donor->setProspectComment($this->form->getValue('prospect_comment')); $donor->setSalutation($this->form->getValue('salutation')); if ($this->form->getValue('company_id') == 0) { $donor->setCompanyId(null); } else { $donor->setCompanyId($this->form->getValue('company_id')); } $donor->setPosition($this->form->getValue('position')); $donor->setDonorPotential($this->form->getValue('donor_potential')); if ($this->form->getValue('person_id') == 0) { $donor->setPersonId(null); } else { $donor->setPersonId($this->form->getValue('person_id')); } if ($this->form->isNew()) { $donor->setDateAdded(date()); } $donor->setDateUpdated(date()); $donor->save(); $this->getUser()->setFlash('success', $success); $last = $request->getParameter('back'); if (strstr($last, 'donation/create')) { $back_url = $last; } else { $back_url = 'donor'; } $this->redirect($back_url); } else { $this->getUser()->setFlash('success', 'Please select Person, Company or Affiliation!'); } } else { # Set referer URL $this->referer = $request->getReferer() ? $request->getReferer() : '@donor'; } $this->donor = $donor; }