/** * getGroupData - Get group data and realted stuff * * @param int $grpId * @return array */ private function getGroupData($grpId) { // Get authentication $auth = Zend_Auth::getInstance(); // Get group data $grpModel = new Default_Model_Groups(); $grpData = $grpModel->getGroupData($grpId); $grpData['description_grp'] = $this->oibs_nl2p($grpData['description_grp']); //$grpData['description_grp'] = str_replace("\n", '<br>', $grpData['description_grp']); $grpData['body_grp'] = $this->oibs_nl2p($grpData['body_grp'], ""); //$grpData['body_grp'] = str_replace("\n", '<br>', $grpData['body_grp']); // User has identity if ($auth->hasIdentity()) { $grpData['user_identity'] = true; $grpData['user_id'] = $auth->getIdentity()->user_id; } else { $grpData['user_identity'] = false; } // Group admins $grpAdminsModel = new Default_Model_GroupAdmins(); $grpAdmins = $grpAdminsModel->getGroupAdmins($grpId); $grpData['grp_admins'] = $grpAdmins; $user = $auth->getIdentity(); $grpData['user_is_group_admin'] = isset($user->user_id) ? $this->checkIfArrayHasKeyWithValue($grpAdmins, 'id_usr', $user->user_id) : false; // Group type $grpTypeId = $grpModel->getGroupTypeId($grpId); $grpTypeModel = new Default_Model_GroupTypes(); $grpData['is_closed'] = $grpTypeModel->isClosed($grpTypeId); // usrHasGrp models if (isset($user->user_id)) { $usrHasGrpModel = new Default_Model_UserHasGroup(); $grpData['user_has_group'] = $usrHasGrpModel->userHasGroup($grpId, $user->user_id); $usrHasGrpWaitingModel = new Default_Model_UserHasGroupWaiting(); $grpData['user_has_group_waiting'] = $usrHasGrpWaitingModel->userWaitingGroup($grpId, $user->user_id); $grpData['usr_waiting_count'] = $usrHasGrpWaitingModel->getUserCountByGroup($grpId); } else { $grpData['user_has_group'] = false; $grpData['user_has_group_waiting'] = false; } return $grpData; }
public function __construct($parent = null, $options = null) { parent::__construct($options); $parentId = 0; if ($parent != null) { $parentId = $parent; } $translate = Zend_Registry::get('Zend_Translate'); $this->setName('add_group_form'); $this->addElementPrefixPath('Oibs_Form_Decorator', 'Oibs/Form/Decorator/', 'decorator'); $clear = '<div class="clear"></div>'; // Group name (must be unique). $groupname = new Zend_Form_Element_Text('groupname'); $groupname->setLabel('Name')->setRequired(true)->setFilters(array('StringTrim'))->setValidators(array(array('NotEmpty', true, array('messages' => array('isEmpty' => 'field-empty'))), array('StringLength', false, array(1, 140, 'encoding' => 'UTF-8', 'messages' => array('stringLengthTooLong' => 'Name too long.'))), array(new Oibs_Validators_GroupExists($options), false)))->setDescription('<div id="progressbar_groupname" class="limit ok"></div>')->setDecorators(array('FieldDecorator')); $groupname_clear = new Oibs_Form_Element_Note('groupname_clear'); $groupname_clear->setValue($clear)->setDecorators(array('ViewHelper')); // Group type $groupTypes_model = new Default_Model_GroupTypes(); $groupTypes = $groupTypes_model->getAllTypes(); $grouptype = new Zend_Form_Element_Select('grouptype'); $grouptype->setLabel('Type')->setAttrib('id', 'grouptype'); foreach ($groupTypes as $type) { $grouptype->addMultiOption($type['id_gtp'], $type['name_gtp']); } $grouptype->setDecorators(array('FieldDecorator')); $grouptype_clear = new Oibs_Form_Element_Note('grouptype_clear'); $grouptype_clear->setValue($clear)->setDecorators(array('ViewHelper')); // Lead paragraph (description) $groupdesc = new Zend_Form_Element_Textarea('groupdesc'); $groupdesc->setAttrib('cols', '45')->setAttrib('rows', '6')->setLabel('Lead paragraph')->setRequired(true)->setValidators(array(array('NotEmpty', true, array('messages' => array('isEmpty' => "Description can't be empty."))), array('StringLength', false, array(1, 320, 'encoding' => 'UTF-8', 'messages' => array('stringLengthTooLong' => 'Description too long.')))))->setDescription('<div id="progressbar_groupdesc" class="limit ok"></div>')->setDecorators(array('FieldDecorator')); $groupdesc_clear = new Oibs_Form_Element_Note('groupdesc_clear'); $groupdesc_clear->setValue($clear)->setDecorators(array('ViewHelper')); // Body text. $groupbody = new Zend_Form_Element_Textarea('groupbody'); $groupbody->setAttrib('cols', '45')->setAttrib('rows', '20')->setLabel('Body')->setValidators(array(array('StringLength', false, array(1, 4000, 'encoding' => 'UTF-8', 'messages' => array('stringLengthTooLong' => 'Body text too long.')))))->setDecorators(array('FieldDecorator')); $groupbody_clear = new Oibs_Form_Element_Note('groupbody_clear'); $groupbody_clear->setValue($clear)->setDecorators(array('ViewHelper')); $weblinks_websites = new Oibs_Form_Element_Note('weblinks_websites'); $weblinks_websites->setValue('<div class="input-column-website1"><label><strong>Links to websites:</strong></label></div>'); $weblinks_name = new Oibs_Form_Element_Note('weblinks_name'); $weblinks_name->setValue('<div class="input-column-website2">Name</div>'); $weblinks_url = new Oibs_Form_Element_Note('weblinks_url'); $weblinks_url->setValue('<div class="input-column-website3">Url</div><div class="clear"></div>'); $nameTooLongText = 'Name too long (max 45)'; $urlTooLongText = 'URL too long (max 150)'; $weblinks_name_site1 = new Zend_Form_Element_Text('weblinks_name_site1'); $weblinks_name_site1->setLabel('Web site 1')->setAttrib('id', 'website1-name')->addValidators(array(array('StringLength', false, array(0, 45, 'encoding' => 'UTF-8', 'messages' => array('stringLengthTooLong' => $nameTooLongText))))); $weblinks_url_site1 = new Zend_Form_Element_Text('weblinks_url_site1'); $weblinks_url_site1->setAttrib('id', 'website1-url')->addValidators(array(new Oibs_Validators_UrlValidator(), array('StringLength', false, array(0, 150, 'encoding' => 'UTF-8', 'messages' => array('stringLengthTooLong' => $urlTooLongText))))); $weblinks_name_site2 = new Zend_Form_Element_Text('weblinks_name_site2'); $weblinks_name_site2->setLabel('Web site 2')->setAttrib('id', 'website2-name')->addValidators(array(array('StringLength', false, array(0, 45, 'encoding' => 'UTF-8', 'messages' => array('stringLengthTooLong' => $nameTooLongText))))); $weblinks_url_site2 = new Zend_Form_Element_Text('weblinks_url_site2'); $weblinks_url_site2->setAttrib('id', 'website2-url')->addValidators(array(new Oibs_Validators_UrlValidator(), array('StringLength', false, array(0, 150, 'messages' => array('stringLengthTooLong' => $urlTooLongText))))); $weblinks_name_site3 = new Zend_Form_Element_Text('weblinks_name_site3'); $weblinks_name_site3->setLabel('Web site 3')->setAttrib('id', 'website3-name')->setAttrib('id', 'website2-name')->addValidators(array(array('StringLength', false, array(0, 45, 'encoding' => 'UTF-8', 'messages' => array('stringLengthTooLong' => $nameTooLongText))))); $weblinks_url_site3 = new Zend_Form_Element_Text('weblinks_url_site3'); $weblinks_url_site3->setAttrib('id', 'website3-url')->addValidators(array(new Oibs_Validators_UrlValidator(), array('StringLength', false, array(0, 150, 'encoding' => 'UTF-8', 'messages' => array('stringLengthTooLong' => $urlTooLongText))))); $weblinks_name_site4 = new Zend_Form_Element_Text('weblinks_name_site4'); $weblinks_name_site4->setLabel('Web site 4')->setAttrib('id', 'website4-name')->setAttrib('id', 'website2-name')->addValidators(array(array('StringLength', false, array(0, 45, 'encoding' => 'UTF-8', 'messages' => array('stringLengthTooLong' => $nameTooLongText))))); $weblinks_url_site4 = new Zend_Form_Element_Text('weblinks_url_site4'); $weblinks_url_site4->setAttrib('id', 'website4-url')->addValidators(array(new Oibs_Validators_UrlValidator(), array('StringLength', false, array(0, 150, 'encoding' => 'UTF-8', 'messages' => array('stringLengthTooLong' => $urlTooLongText))))); $weblinks_name_site5 = new Zend_Form_Element_Text('weblinks_name_site5'); $weblinks_name_site5->setLabel('Web site 5')->setAttrib('id', 'website5-name')->setAttrib('id', 'website2-name')->addValidators(array(array('StringLength', false, array(0, 45, 'encoding' => 'UTF-8', 'messages' => array('stringLengthTooLong' => $nameTooLongText))))); $weblinks_url_site5 = new Zend_Form_Element_Text('weblinks_url_site5'); $weblinks_url_site5->setAttrib('id', 'website5-url')->addValidators(array(new Oibs_Validators_UrlValidator(), array('StringLength', false, array(0, 150, 'encoding' => 'UTF-8', 'messages' => array('stringLengthTooLong' => $urlTooLongText))))); $weblinks_websites->setDecorators(array('ViewHelper')); $weblinks_name->setDecorators(array('ViewHelper')); $weblinks_url->setDecorators(array('ViewHelper')); $weblinks_name_site1->setDecorators(array('InputWebsiteNameDecorator')); $weblinks_url_site1->setDecorators(array('InputWebsiteUrlDecorator')); $weblinks_name_site2->setDecorators(array('InputWebsiteNameDecorator')); $weblinks_url_site2->setDecorators(array('InputWebsiteUrlDecorator')); $weblinks_name_site3->setDecorators(array('InputWebsiteNameDecorator')); $weblinks_url_site3->setDecorators(array('InputWebsiteUrlDecorator')); $weblinks_name_site4->setDecorators(array('InputWebsiteNameDecorator')); $weblinks_url_site4->setDecorators(array('InputWebsiteUrlDecorator')); $weblinks_name_site5->setDecorators(array('InputWebsiteNameDecorator')); $weblinks_url_site5->setDecorators(array('InputWebsiteUrlDecorator')); $save = new Zend_Form_Element_Submit('save'); if (is_array($options) && $options['mode'] == 'edit') { $save->setLabel('Save'); } else { $save->setLabel('Create'); } $save->setAttrib('id', 'publish')->setAttrib('class', 'submit-button')->setAttrib('style', 'float: none;'); $this->addElements(array($groupname, $groupname_clear, $grouptype, $grouptype_clear, $groupdesc, $groupdesc_clear, $groupbody, $groupbody_clear, $weblinks_websites, $weblinks_name, $weblinks_url, $weblinks_name_site1, $weblinks_url_site1, $weblinks_name_site2, $weblinks_url_site2, $weblinks_name_site3, $weblinks_url_site3, $weblinks_name_site4, $weblinks_url_site4, $weblinks_name_site5, $weblinks_url_site5, $save)); $save->setDecorators(array('ViewHelper', array('HtmlTag', array('tag' => 'div', 'openOnly' => true, 'id' => 'submit', 'style' => 'clear: both;')))); }
function joinAction() { $auth = Zend_Auth::getInstance(); if ($auth->hasIdentity()) { // Get group id and user id. $grpId = $this->_request->getParam('groupid'); $usrId = $auth->getIdentity()->user_id; // Check group type $grpModel = new Default_Model_Groups(); $grpTypeId = $grpModel->getGroupTypeId($grpId); $grpTypeModel = new Default_Model_GroupTypes(); $isClosed = $grpTypeModel->isClosed($grpTypeId); if ($isClosed) { // Join the group waitinglist $usrHasGroupWaitingModel = new Default_Model_UserHasGroupWaiting(); $usrHasGroupWaitingModel->addUserWaitingToGroup($grpId, $usrId); $privateMessagesModel = new Default_Model_PrivateMessages(); $grpAdminsModel = new Default_Model_GroupAdmins(); $grpAdmins = $grpAdminsModel->getGroupAdmins($grpId); $grpData = $grpModel->getGroupData($grpId); foreach ($grpAdmins as $admin) { $adminmessage = array(); $adminmessage['privmsg_sender_id'] = 0; $adminmessage['privmsg_receiver_id'] = $admin['id_usr']; $adminmessage['privmsg_header'] = $grpData['group_name_grp'] . ' group has new user in waiting list'; $link = $this->_urlHelper->url(array('controller' => 'group', 'action' => 'waitinglist', 'grpid' => $grpId, 'language' => $this->view->language), 'lang_default', true); $adminmessage['privmsg_message'] = '<a href="' . $link . '">Check user(s) who want to join ' . $grpData['group_name_grp'] . ' group.</a>'; $privateMessagesModel->addMessage($adminmessage); } $usermessage = array(); $usermessage['privmsg_sender_id'] = 0; $usermessage['privmsg_receiver_id'] = $usrId; $usermessage['privmsg_header'] = $grpData['group_name_grp'] . ' waiting list'; $link = $this->_urlHelper->url(array('groupid' => $grpId, 'language' => $this->view->language), 'group_shortview', true); $usermessage['privmsg_message'] = 'You are in waiting list for <a href="' . $link . '">' . $grpData['group_name_grp'] . ' group.</a>'; $privateMessagesModel->addMessage($usermessage); } else { // Join the group. $usrHasGroupModel = new Default_Model_UserHasGroup(); $usrHasGroupModel->addUserToGroup($grpId, $usrId); } // Redirect back to the group page. $target = $this->_urlHelper->url(array('groupid' => $grpId, 'language' => $this->view->language), 'group_shortview', true); $this->_redirector->gotoUrl($target); } else { // Not logged in - can't join a group. $target = $this->_urlHelper->url(array('controller' => 'index', 'action' => 'index', 'language' => $this->view->language), 'lang_default', true); $this->_redirector->gotoUrl($target); } }