/** * Run the migrations. * * @return void */ public function up() { Schema::create('locations', function ($table) { $table->increments('id'); $table->string('code'); $table->string('name'); $table->longText('address'); $table->string('email'); $table->string('contact_no'); $table->string('location_type_id'); $table->string('parent_location_id'); $table->string('valid_till'); $table->string('created_by'); $table->longText('organizer_details'); $table->timestamps(); $table->softDeletes(); }); Schema::create('location_types', function ($table) { $table->increments('id'); $table->string('name'); $table->integer('level'); }); $lt = new LocationType(); $lt->name = 'Cluster Head'; $lt->level = 1; $lt->save(); $lt = new LocationType(); $lt->name = 'Regional Hospital'; $lt->level = 2; $lt->save(); $lt = new LocationType(); $lt->name = 'Mobile Campaign'; $lt->level = 3; $lt->save(); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { $location = Location::find($id); $location_types = array('') + LocationType::all()->lists('name', 'id'); //$parent_locations = array('') + Location::all()->lists('code', 'name'); //$parent_locations = array('') + Location::where('location_type_id', 'IN', array(1, 2)); $parent_locations = array('') + Location::whereIn('location_type_id', array(1, 2))->lists('code', 'id'); return View::make('locations.create', array('location' => $location, 'location_types' => $location_types, 'parent_locations' => $parent_locations)); }
/** * Allows a user to view the details of a location. * */ public function detailsAction() { $this->view->acl = array('edit' => $this->_helper->hasAccess('edit'), 'delete' => $this->_helper->hasAccess('delete')); $get = Zend_Registry::get('getFilter'); if (!isset($get->locationId)) { throw new Ot_Exception_Input('msg-error-locationIdNotSet'); } $location = new Location(); $thisLocation = $location->find($get->locationId); if (is_null($thisLocation)) { throw new Ot_Exception_Data('msg-error-noLocation'); } $locationType = new LocationType(); $type = $locationType->getTypeById($thisLocation['locationType']); $thisLocation->locationType = $type; $this->view->location = $thisLocation; $this->view->messages = $this->_helper->flashMessenger->getMessages(); $this->_helper->pageTitle("workshop-location-details:title", $thisLocation->name); }
/** * Gets the form for adding and editing a location * * @param array $values * @return Zend_Form */ public function form($values = array()) { $form = new Zend_Form(); $form->setAttrib('id', 'locationForm')->setDecorators(array('FormElements', array('HtmlTag', array('tag' => 'div', 'class' => 'zend_form')), 'Form')); $name = $form->createElement('text', 'name', array('label' => 'Name:')); $name->setRequired(true)->addFilter('StringTrim')->addFilter('StripTags')->setAttrib('maxlength', '64')->setValue(isset($values['name']) ? $values['name'] : ''); $status = $form->createElement('select', 'status', array('label' => 'Status:')); $status->addMultiOption('enabled', 'Enabled'); $status->addMultiOption('disabled', 'Disabled'); $status->setValue(isset($values['status']) ? $values['status'] : 'enabled'); $locationType = new LocationType(); $types = $locationType->fetchAll(null, 'name'); $type = $form->createElement('select', 'locationType', array('label' => 'Location Type:')); foreach ($types as $t) { $type->addMultiOption($t->typeId, $t->name); } $type->setRequired(true)->setValue(isset($values['locationType']) ? $values['locationType'] : ''); $capacity = $form->createElement('text', 'capacity', array('label' => 'Capacity:')); $capacity->setRequired(true)->addFilter('StringTrim')->addFilter('StripTags')->addValidator('Digits')->setAttrib('maxlength', '64')->setValue(isset($values['capacity']) ? $values['capacity'] : ''); $address = $form->createElement('text', 'address', array('label' => 'Address:')); $address->setRequired(true)->addFilter('StringTrim')->addFilter('StripTags')->setAttrib('maxlength', '255')->setValue(isset($values['address']) ? $values['address'] : ''); $description = $form->createElement('textarea', 'description', array('label' => 'Description:')); $description->setRequired(false)->addFilter('StringTrim')->setAttrib('style', 'width: 95%; height: 300px;')->setValue(isset($values['description']) ? $values['description'] : ''); $submit = $form->createElement('submit', 'submitButton', array('label' => 'Submit')); $submit->setDecorators(array(array('ViewHelper', array('helper' => 'formSubmit')))); $cancel = $form->createElement('button', 'cancel', array('label' => 'Cancel')); $cancel->setAttrib('id', 'cancel'); $cancel->setDecorators(array(array('ViewHelper', array('helper' => 'formButton')))); $form->addElements(array($name, $status, $type, $capacity, $address, $description)); $form->setElementDecorators(array('ViewHelper', 'Errors', array('HtmlTag', array('tag' => 'div', 'class' => 'elm')), array('Label', array('tag' => 'span'))))->addElements(array($submit, $cancel)); if (isset($values['locationId'])) { $locationId = $form->createElement('hidden', 'locationId'); $locationId->setValue($values['locationId']); $locationId->setDecorators(array(array('ViewHelper', array('helper' => 'formHidden')))); $form->addElement($locationId); } return $form; }
function addLocationForm() { //global all variables global $locationForm, $tool; $locationInfoKey = array("name", "desc", "country", "province", "city", "address1", "address2", "zip", "group", "notes", "type"); $fieldType = array(8 => "drop_down", 9 => "text_area", 10 => "drop_down"); $locationHeader = array("Location Information"); $locationTitle = array("Name", "Description", "Country", "Province", "City", "Address 1", "Address 2", "Zip Code", "Contact", "Notes", "Location Type"); $allLocationType = LocationType::get_location_types(); $allGroups = Contact::get_groups(); $locationForm->setHeadings($locationHeader); $locationForm->setTitles($locationTitle); $locationForm->setData($locationInfo); $locationForm->setSortable(false); $locationForm->setDatabase($locationInfoKey); $locationForm->setAddValue("addLocation"); $locationForm->setType($allGroups); $locationForm->setType($allLocationType); $locationForm->setFieldType($fieldType); echo $locationForm->newLocationForm(); }
/** * Allows a user to delete a location type * */ public function deleteAction() { $get = Zend_Registry::get('getFilter'); if (!isset($get->typeId)) { throw new Ot_Exception_Input('msg-error-typeIdNotSet'); } $locationType = new LocationType(); $thisLocationType = $locationType->find($get->typeId); if (is_null($thisLocationType)) { throw new Ot_Exception_Data('msg-error-noLocationType'); } $this->view->locationType = $thisLocationType; $form = Ot_Form_Template::delete('deleteForm'); if ($this->_request->isPost() && $form->isValid($_POST)) { $where = $locationType->getAdapter()->quoteInto('typeId = ?', $get->typeId); $locationType->delete($where); $this->_helper->flashMessenger->addMessage('msg-info-locationTypeDeleted'); $this->_helper->redirector->gotoUrl('/workshop/locationType/index'); } $this->_helper->pageTitle('workshop-location-type-delete:title'); $this->view->form = $form; }