Ejemplo n.º 1
0
	/**
	 * getRoute() Utility Function
	 * 
	 * Returns a new valid ItemRoute array
	 * 
	 * @param Item $item
	 * @param integer $rid
	 * @return array 
	 */
	private function newItemRoute($item, $rid)
	{
		return array(
			'id' => $item->getId(), 
			'img' => Delivery::getMarkerImage($rid)
		);
	}
Ejemplo n.º 2
0
	/**
	 * Returns the Current ItemStatus
	 * @throws ControllerException
	 */
	public function executeItemStatusImage()
	{
		if (!$this->getRequest()->isXmlHttpRequest()) {
			throw new ControllerException("Method not allowed.");
		}

		$id = $this->getRequest()->get('id');
		$item = Item::find($id);
		
		if (is_null($item)) {
			throw new ControllerException("Item does not exist.");
		}
		return json_encode(array(
			'id' => $item->getId(), 
			'img' => $item->getStatusMarkerImage()
		));
		
	}
	/**
	 * Returns the Create Delivery Form
	 */
	public function executeCreate()
	{
		
		$errors = array();
		$validator = new DeliveryValidator();
		
		$fromAddress = $this->getRequest()->get('from');
		$toAddress = $this->getRequest()->get('to');
		
		$errors = $validator->validateAddress($fromAddress, 'from-', '', $this->app);
		$errors = array_merge($errors, $validator->validateAddress($toAddress, 'to-', '', $this->app));
		
		$delivery = new Delivery();
		
		$delivery->setFromAddress(new Address($fromAddress));
		$delivery->setToAddress(new Address($toAddress));
		
		$createItemList = explode(',',$this->app->escape($this->getRequest()->get('create-item-list')));
		$nrOfCreations = count($createItemList); 
		
		for ($i=0; $i < $nrOfCreations; $i++) {
			if (!empty($createItemList[$i])) {
				
				$properties = explode('|', $createItemList[$i]);
				$name = $properties[0];
				$mintemp = $properties[1];
				$maxtemp = $properties[2];
				
				$newItem = new Item();
				$newItem->setName($name);
				$newItem->setTempMin((int)$mintemp);
				$newItem->setTempMax((int)$maxtemp);
				
				$errors = array_merge($errors, $validator->validateItem(
						$name, $mintemp, $maxtemp, $i));
				
				$delivery->addItem($newItem);
			}
		}
		
		if (count($errors) == 0) { 
			$delivery->save();
			return $this->redirect('/delivery/view/' . $delivery->getId());
		}
		return $this->render('delivery.add.twig', array(
			'delivery' => $delivery,
			'errors' => $errors,
			'form_action' => '/delivery/create',
		));
	}