/**
  * This app only cares about equipments as belonging to a certain room,
  * not for example, all of them globally, so Equipments instances are tied
  * to one certain Room.
  * @param \Rooms\Model\Room $room
  * @return $this
  */
 public function init(Room $room)
 {
     $this->room = $room;
     $this->setServiceLocator($room->getServiceLocator());
     $this->set_init();
     return $this;
 }
 public function create($data)
 {
     if (empty($data['id'])) {
         $data['id'] = 0;
     }
     $form = new RoomForm();
     $room = new Room();
     $form->setInputFilter($room->getInputFilter());
     $form->setData($data);
     if ($form->isValid()) {
         $room->exchangeArray($form->getData());
         $id = $this->getRoomTable()->saveRoom($room);
     }
     return $this->get($id);
 }
 /**
  * For JS AJAX validation - validates a property of Room object.
  * @return JSON status=ok|error,message={string}
  */
 public function validateJSONAction()
 {
     try {
         $propName = $this->params()->fromPost('propName');
         if (!in_array($propName, Room::propertyNames())) {
             throw new \Exception('Wrong property provided.');
         }
         $value = $this->params()->fromPost('value');
         if (!$propName || !$value) {
             throw new \Exception('No property and/or value given.');
         }
         $form = new RoomForm();
         $form->setInputFilter($this->getServiceLocator()->get('room')->getInputFilter());
         $form->setData(array($propName => $value))->isValid();
         $elements = $form->getElements();
         $element = $elements[$propName];
         if (count($element->getMessages())) {
             return $this->myJsonModel(array('status' => 'error', 'message' => $element->getMessages()));
         } else {
             return $this->myJsonModel(array('status' => 'ok', 'message' => ''));
         }
     } catch (\Exception $e) {
         return $this->myJsonModel(array('status' => 'error', 'message' => $e->getMessage()));
     }
 }