public function init() { parent::init(); $this->setTitle('Edit Player Card'); $this->submit->setLabel('Save Changes'); }
public function createAction() { if (!$this->_helper->requireUser->isValid()) { return; } $viewer = Engine_Api::_()->user()->getViewer(); // Create form $this->view->form = $form = new User_Form_Playercard_Create(); if (!$this->getRequest()->isPost()) { return; } $posts = $this->getRequest()->getPost(); if ($posts['category_id'] == 2) { $this->view->showPreferredFoot = true; } else { $this->view->showPreferredFoot = false; } if ($posts['relation_id'] == 0) { $this->view->showOther = true; } else { $this->view->showOther = false; } $category_id = $posts['category_id']; $sportCattable = Engine_Api::_()->getDbtable('sportcategories', 'user'); $node = $sportCattable->getNode($category_id); $categories = $node->getChilren(); if (count($categories)) { $position_options = array(0 => ''); foreach ($categories as $category) { $position_options[$category->getIdentity()] = $category->title; $node = $sportCattable->getNode($category->getIdentity()); $positons = $node->getChilren(); foreach ($positons as $positon) { $position_options[$positon->getIdentity()] = '-- ' . $positon->title; } } $form->getElement('position_id')->setMultiOptions($position_options); $this->view->showPosition = true; } else { $this->view->showPosition = false; } // Location $provincesAssoc = array(); $country_id = $posts['country_id']; if ($country_id) { $provincesAssoc = Engine_Api::_()->getDbTable('locations', 'user')->getLocationsAssoc($country_id); $provincesAssoc = array('0' => '') + $provincesAssoc; } $form->getElement('province_id')->setMultiOptions($provincesAssoc); $citiesAssoc = array(); $province_id = $posts['province_id']; if ($province_id) { $citiesAssoc = Engine_Api::_()->getDbTable('locations', 'user')->getLocationsAssoc($province_id); $citiesAssoc = array('0' => '') + $citiesAssoc; } $form->getElement('city_id')->setMultiOptions($citiesAssoc); if (!$form->isValid($posts)) { return; } // Process $values = $form->getValues(); if (Engine_Api::_()->getApi('settings', 'core')->getSetting('user.relation_require', 1) && $values['relation_id'] == 0 && empty($values['relation_other'])) { $form->getElement('relation_other')->addError('Please complete this field - it is required.'); return false; } $values['user_id'] = $viewer->getIdentity(); $db = Engine_Api::_()->getDbtable('playercards', 'user')->getAdapter(); $db->beginTransaction(); try { // Create player $values['languages'] = json_encode($values['languages']); if ($this->_getParam('club_parent', 0)) { $club = Engine_Api::_()->getItem('group', $this->_getParam('club_parent', 0)); $values['parent_type'] = $club->getType(); $values['parent_id'] = $club->getIdentity(); } $table = Engine_Api::_()->getDbtable('playercards', 'user'); $player_card = $table->createRow(); $player_card->setFromArray($values); $player_card->save(); if (!empty($values['languages'])) { foreach (json_decode($values['languages']) as $langId) { // save language map $mappingTable = Engine_Api::_()->getDbtable('languagemappings', 'user'); $mappingTable->save($langId, $player_card); } } // Set photo if (!empty($values['photo'])) { $player_card->setPhoto($form->photo); } //set allow view for specific users $user_ids = explode(",", $values['user_ids']); $userItemViewTable = Engine_Api::_()->getDbTable('userItemView', 'user'); foreach ($user_ids as $user_id) { $row = $userItemViewTable->createRow(); $row->user_id = $user_id; $row->item_id = $player_card->getIdentity(); $row->item_type = $player_card->getType(); $row->save(); } // CREATE AUTH STUFF HERE $auth = Engine_Api::_()->authorization()->context; $roles = array('owner', 'owner_member', 'owner_network', 'everyone'); if (isset($values['auth_view'])) { $auth_view = $values['auth_view']; } else { $auth_view = "everyone"; } $viewMax = array_search($auth_view, $roles); foreach ($roles as $i => $role) { $auth->setAllowed($player_card, $role, 'view', $i <= $viewMax); } $auth_comment = "everyone"; $commentMax = array_search($auth_comment, $roles); foreach ($roles as $i => $role) { $auth->setAllowed($player_card, $role, 'comment', $i <= $commentMax); } $db->commit(); if ($player_card->parent_type == 'group') { $club = Engine_Api::_()->getItem('group', $player_card->parent_id); return $this->_redirectCustom($club); } // Redirect $tab = $this->_getParam('tab', ''); $pageURL = 'http'; if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") { $pageURL .= "s"; } $pageURL .= "://"; $url = $pageURL . $_SERVER['HTTP_HOST'] . $viewer->getHref() . '/view/tab/' . $tab; return $this->_helper->redirector->gotoUrl($url); } catch (Engine_Image_Exception $e) { $db->rollBack(); $form->addError(Zend_Registry::get('Zend_Translate')->_('The image you selected was too large.')); } catch (Exception $e) { $db->rollBack(); throw $e; } }