public function init() { parent::init(); $this->setTitle('Edit Work Place'); $this->addPlace->setLabel('Save Changes'); }
public function addWorkPlaceAction() { $this->view->user = $user = Engine_Api::_()->core()->getSubject(); $this->view->form = $form = new Ynmember_Form_WorkPlace_Create(); // Check method and data validity. $posts = $this->getRequest()->getPost(); if (!$this->getRequest()->isPost()) { return; } if (!$form->isValid($posts)) { return; } $values = $form->getValues(); $tableWork = Engine_Api::_()->getItemTable('ynmember_workplace'); $place = $tableWork->createRow(); $place->company = $values['company']; //$place -> location = $values['location_address']; $place->location = isset($_POST['location']) && $_POST['location'] != '' ? $_POST['location'] : $values['location_address']; $place->longitude = $values['long']; $place->latitude = $values['lat']; $place->current = $values['current']; $place->creation_date = date("Y-m-d H:i:s"); $place->modified_date = date("Y-m-d H:i:s"); $place->user_id = $user->getIdentity(); $place->save(); if ($values['current'] == 1) { $select = $tableWork->select()->where('workplace_id <> ?', $place->getIdentity())->where('user_id = ?', $user->getIdentity()); $results = $tableWork->fetchAll($select); foreach ($results as $row) { $row->current = 0; $row->save(); } } // Auth $auth = Engine_Api::_()->authorization()->context; $roles = array('owner', 'owner_member', 'registered', 'everyone'); if (empty($values['auth_view'])) { $values['auth_view'] = 'everyone'; } $viewMax = array_search($values['auth_view'], $roles); foreach ($roles as $i => $role) { $auth->setAllowed($place, $role, 'view', $i <= $viewMax); } return $this->_forward('success', 'utility', 'core', array('messages' => array(Zend_Registry::get('Zend_Translate')->_('Work place added.')), 'format' => 'smoothbox', 'smoothboxClose' => true, 'parentRefresh' => true)); }