Ejemplo n.º 1
0
 /**
  * Enter description here...
  *
  */
 public function createAction()
 {
     $this->requirePost();
     $form = $this->getNewByingsForm();
     if ($form->isValid($_POST)) {
         // do some inputting
         for ($i = 0; $i < 10; $i++) {
             if ($form->getValue("product{$i}")) {
                 $product = $form->getValue("product{$i}");
                 $price = $form->getValue("price{$i}");
                 $buyings = Table_Buyings::getInstance();
                 $buying = $buyings->createRow();
                 $buying->setDescription($product);
                 $buying->setPriceInEuro($price);
                 $buying->setResident($this->getCurrentResident());
                 $buying->save();
             }
         }
         // list byings
         $this->flash('Einkäufte eingetragen');
         $this->redirect('index');
     } else {
         $this->redirect('new');
     }
 }
Ejemplo n.º 2
0
 /**
  * Enter description here...
  *
  */
 public function createAction()
 {
     $this->requirePost();
     $form = $this->getNewByingsForm();
     if ($form->isValid($_POST)) {
         // do some inputting
         $buyings = array();
         for ($i = 0; $i < 10; $i++) {
             if ($form->getValue("product{$i}")) {
                 $product = $form->getValue("product{$i}");
                 $price = $form->getValue("price{$i}");
                 $buying = Table_Buyings::getInstance()->createRow();
                 $buying->setDescription($product);
                 $buying->setPriceInEuro($price);
                 $buying->setResident($this->getCurrentResident());
                 $buying->save();
                 $buyings[] = $buying;
             } else {
                 break;
             }
         }
         if (!empty($buyings)) {
             # tailor message that going to be sent to the other residents
             $message = $this->getCurrentResident()->getName();
             $message .= " hat folgende Dinge gekauft:\n";
             $buying = null;
             $summ = 0.0;
             foreach ($buyings as $buying) {
                 $message .= $buying->getDescription() . " für " . $buying->getPriceInEuro() . "€\n";
                 $summ += $buying->getPriceInEuro();
             }
             $message .= "\nGesammtwert: \t {$summ} €";
             foreach (Table_Residents::getInstance()->fetchAll() as $resident) {
                 if ($resident->getId() != $this->getCurrentResident()->getId()) {
                     # Send a message to the other residents. Telling them the current one
                     # entered a new buying.
                     $msg = Table_Messages::getInstance()->createRow();
                     $msg->setFrom('System');
                     $msg->setFor($resident);
                     $msg->setTitle('Neuer Einkauf');
                     $msg->setMessage($message);
                     $msg->save();
                 }
             }
         }
         // list byings
         $this->flash('Einkäufte eingetragen');
         $this->redirect('index');
     } else {
         $this->redirect('new');
     }
 }
Ejemplo n.º 3
0
 /**
  * Creates an Message to all residents.
  *
  * @param int $buyingId
  */
 protected function _createMessage($buyingId)
 {
     $buying = Table_Buyings::getInstance()->findById($buyingId);
     // create a message for each resident
     $residents = Table_Residents::getInstance()->fetchAll();
     foreach ($residents as $resident) {
         $date = array();
         $data['residend_id'] = $resident->getId();
         $data['title'] = 'Neuer Einkauf';
         $data['message'] = 'Neuer Einkauf';
         Table_Messages::getInstance()->createRow($data);
     }
 }