summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.zfproject.xml9
-rw-r--r--application/modules/dev/controllers/PersonController.php20
-rw-r--r--application/modules/user/controllers/PersonController.php169
-rw-r--r--application/modules/user/forms/GroupRequest.php49
-rw-r--r--application/modules/user/forms/PersonEdit.php117
-rw-r--r--application/modules/user/views/scripts/person/edit.phtml4
-rw-r--r--application/modules/user/views/scripts/person/index.phtml61
-rw-r--r--application/modules/user/views/scripts/person/request.phtml6
8 files changed, 424 insertions, 11 deletions
diff --git a/.zfproject.xml b/.zfproject.xml
index 94272cd..da3638e 100644
--- a/.zfproject.xml
+++ b/.zfproject.xml
@@ -109,6 +109,9 @@
</controllerFile>
<controllerFile controllerName="Person">
<actionMethod actionName="index"/>
+ <actionMethod actionName="edit"/>
+ <actionMethod actionName="request"/>
+ <actionMethod actionName="leave"/>
</controllerFile>
<controllerFile controllerName="Group">
<actionMethod actionName="index"/>
@@ -260,6 +263,12 @@
<viewControllerScriptsDirectory forControllerName="Filter">
<viewScriptFile forActionName="removefilterentry"/>
</viewControllerScriptsDirectory>
+ <viewControllerScriptsDirectory forControllerName="Person">
+ <viewScriptFile forActionName="edit"/>
+ </viewControllerScriptsDirectory>
+ <viewControllerScriptsDirectory forControllerName="Person">
+ <viewScriptFile forActionName="request"/>
+ </viewControllerScriptsDirectory>
</viewScriptsDirectory>
<viewHelpersDirectory/>
<viewFiltersDirectory/>
diff --git a/application/modules/dev/controllers/PersonController.php b/application/modules/dev/controllers/PersonController.php
index e422870..40e51af 100644
--- a/application/modules/dev/controllers/PersonController.php
+++ b/application/modules/dev/controllers/PersonController.php
@@ -90,11 +90,29 @@ class dev_PersonController extends Zend_Controller_Action
foreach($allgroups as $group) {
foreach($groupRequests as $groupRequest) {
if($groupRequest['groupID'] == $group->getID()) {
- unset($allgroups[$count]);
+ $groupsFound[$count] = true;
+ } else {
+ $groupsFound[$count] = false;
+ }
+ }
+ foreach($this->memberships as $membership) {
+ if($membership['groupID'] == $group->getID()) {
+ $groupsFound[$count] = true;
+ } else {
+ if($groupsFound[$count] != true) {
+ $groupsFound[$count] = false;
+ }
}
}
$count++;
}
+ if(count($groupsFound) > 0) {
+ foreach($groupsFound as $k => $v) {
+ if($v == true) {
+ unset($allgroups[$k]);
+ }
+ }
+ }
if (!isset($_POST["request"])){
if(count($allgroups) <= 0) {
echo "No Groups to choose.";
diff --git a/application/modules/user/controllers/PersonController.php b/application/modules/user/controllers/PersonController.php
index f43989a..59ce707 100644
--- a/application/modules/user/controllers/PersonController.php
+++ b/application/modules/user/controllers/PersonController.php
@@ -1,18 +1,169 @@
<?php
-class User_PersonController extends Zend_Controller_Action
+class user_PersonController extends Zend_Controller_Action
{
+ protected $person;
+ protected $personmapper;
+ protected $membershipMapper;
+ protected $memberships;
+ protected $groupMapper;
+ protected $groups;
+ protected $groupRequestMapper;
- public function init()
- {
- /* Initialize action controller here */
- }
+ public function init() {
+ if (Zend_Auth::getInstance()->hasIdentity()) {
+ $this->personmapper = new Application_Model_PersonMapper();
+ $result = $this->personmapper->findBy('email', Zend_Auth::getInstance()->getIdentity());
+ $this->person = new Application_Model_Person($result[0]);
+ $this->person->setID($result[0]['personID']);
+ $this->groupMapper = new Application_Model_GroupMapper();
+ $this->groupRequestMapper = new Application_Model_GroupRequestMapper();
+ $this->membershipMapper = new Application_Model_MembershipMapper();
+ $this->memberships = $this->membershipMapper->findBy("personID",$this->person->getID());
+ if(isset($this->memberships)) {
+ foreach($this->memberships as $membership) {
+ $group = $this->groupMapper->find($membership['groupID']);
+ $this->groups[] = array (
+ 'groupID' => $group->getID(),
+ 'title' => $group->getTitle(),
+ 'description' => $group->getDescription(),
+ 'membershipID' => $membership['membershipID']
+ );
+ }
+ }
+ } else {
+ $this->_helper->redirector('login', 'auth');
+ return;
+ }
+ }
- public function indexAction()
- {
- // action body
- }
+ public function indexAction()
+ {
+ $this->view->person = $this->person;
+ $this->view->groups = $this->groups;
+ }
+ public function editAction()
+ {
+ $this->view->person = $this->person;
+ if (!isset($_POST["save"])){
+ $editForm = new user_Form_PersonEdit();
+ } else {
+ $editForm = new user_Form_PersonEdit($_POST);
+ if ($editForm->isValid($_POST)) {
+ if(isset($_POST['newpassword'])) {
+ $date = new DateTime();
+ $this->person->setPassword($_POST['newpassword']);
+ $this->person->setPasswordSalt(MD5($date->getTimestamp()));
+ $this->person->setPassword(MD5($this->person->getPassword() . $this->person->getPasswordSalt()));
+ }
+ $this->person->setOptions($_POST);
+ try {
+ $this->personmapper->save($this->person);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ echo "Email Address already existing.";
+ return;
+ }
+ $this->_helper->redirector('', 'person');
+ return;
+ }
+ }
+ $this->view->editForm = $editForm;
+ }
+ public function requestAction()
+ {
+ $this->view->person = $this->person;
+ $allgroups = $this->groupMapper->fetchAll();
+ $groupRequests = $this->groupRequestMapper->findBy('personID', $this->person->getID());
+ $count = 0;
+ foreach($allgroups as $group) {
+ foreach($groupRequests as $groupRequest) {
+ if($groupRequest['groupID'] == $group->getID()) {
+ $groupsFound[$count] = true;
+ } else {
+ $groupsFound[$count] = false;
+ }
+ }
+ foreach($this->memberships as $membership) {
+ if($membership['groupID'] == $group->getID()) {
+ $groupsFound[$count] = true;
+ } else {
+ if($groupsFound[$count] != true) {
+ $groupsFound[$count] = false;
+ }
+ }
+ }
+ $count++;
+ }
+ if(count($groupsFound) > 0) {
+ foreach($groupsFound as $k => $v) {
+ if($v == true) {
+ unset($allgroups[$k]);
+ }
+ }
+ }
+ if (!isset($_POST["request"])){
+ if(count($allgroups) <= 0) {
+ echo "No Groups to choose.";
+ }
+ $requestForm = new user_Form_GroupRequest(array('grouplist' => $allgroups));
+ } else {
+ $requestForm = new user_Form_GroupRequest(array('grouplist' => $allgroups), $_POST);
+ if ($requestForm->isValid($_POST)) {
+ $groupRequestMapper = new Application_Model_GroupRequestMapper();
+ $groupRequest = new Application_Model_GroupRequest();
+ $groupRequest->setGroupID($_POST['groupID']);
+ $date = new DateTime();
+ $groupRequest->setTime($date->getTimestamp());
+ $groupRequest->setPersonID($this->person->getID());
+ try {
+ $groupRequestMapper->save($groupRequest);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ $this->_helper->redirector('', 'person');
+ return;
+ }
+ }
+ $this->view->requestForm = $requestForm;
+ }
+
+ public function leaveAction()
+ {
+ $this->_helper-> viewRenderer-> setNoRender();
+ $this->view->person = $this->person;
+ $membershipID = $this->_request->getParam('membershipID');
+ if(isset($membershipID)) {
+ $membership = $this->membershipMapper->find($membershipID);
+ try {
+ $this->membershipMapper->delete($membership);
+ } catch(Zend_Exception $e)
+ {
+ echo "Caught exception: " . get_class($e) . "<br/>";
+ echo "Message: " . $e->getMessage() . "<br/>";
+ return;
+ }
+ $this->_helper->redirector('', 'person');
+ return;
+ }
+ }
}
+
+
+
+
+
+
+
+
+
+
+
diff --git a/application/modules/user/forms/GroupRequest.php b/application/modules/user/forms/GroupRequest.php
new file mode 100644
index 0000000..2cdada0
--- /dev/null
+++ b/application/modules/user/forms/GroupRequest.php
@@ -0,0 +1,49 @@
+<?php
+
+class user_Form_GroupRequest extends Zend_Form
+{
+ private $grouplist;
+
+ public function setGrouplist($grouplist){
+ $this->grouplist = $grouplist;
+
+ }
+
+ public function getGrouplist(){
+ return $this->grouplist;
+ }
+
+ public function init()
+ {
+ $this->setName("GroupRequest");
+ $this->setMethod('post');
+
+ $groupfield = $this->createElement('select','groupID');
+ $groupfield ->setLabel('Group:');
+
+ if(count($this->grouplist)>0){
+ foreach($this->grouplist as $group => $g){
+ $groupfield->addMultiOption($g->getID(), $g->getTitle());
+ }
+ }
+
+ $groupfield->setRegisterInArrayValidator(false);
+ $this->addElement($groupfield);
+
+ $this->addElement('submit', 'request', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Request Membership',
+ ));
+
+ $this->addElement('button', 'cancel', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Cancel',
+ 'onclick' => 'location.href="/user/person/"',
+ ));
+
+ }
+
+}
+
diff --git a/application/modules/user/forms/PersonEdit.php b/application/modules/user/forms/PersonEdit.php
new file mode 100644
index 0000000..d6c68e7
--- /dev/null
+++ b/application/modules/user/forms/PersonEdit.php
@@ -0,0 +1,117 @@
+<?php
+
+class user_Form_PersonEdit extends Zend_Form
+{
+
+ public function init()
+ {
+ $this->setName("PersonEdit");
+ $this->setMethod('post');
+
+ $this->addElement('text', 'title', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Title:',
+ 'value' => $this->getView()->person->getTitle(),
+ ));
+
+
+ $this->addElement('text', 'name', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Name:',
+ 'value' => $this->getView()->person->getName(),
+ ));
+
+ $this->addElement('text', 'firstname', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Firstname:',
+ 'value' => $this->getView()->person->getFirstname(),
+ ));
+
+ $this->addElement('text', 'street', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Street:',
+ 'value' => $this->getView()->person->getStreet(),
+ ));
+
+ $this->addElement('text', 'housenumber', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Housenumber:',
+ 'value' => $this->getView()->person->getHousenumber(),
+ ));
+
+ $this->addElement('text', 'city', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'City:',
+ 'value' => $this->getView()->person->getCity(),
+ ));
+
+ $this->addElement('text', 'postalcode', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Postalcode:',
+ 'value' => $this->getView()->person->getPostalcode(),
+ ));
+
+ $this->addElement('text', 'email', array(
+ 'filters' => array('StringTrim', 'StringToLower'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => true,
+ 'label' => 'Email:',
+ 'value' => $this->getView()->person->getEmail(),
+ ));
+
+ $this->addElement('password', 'newpassword', array(
+ 'filters' => array('StringTrim'),
+ 'validators' => array(
+ array('StringLength', false, array(0, 50)),
+ ),
+ 'required' => false,
+ 'label' => 'Neues Password:',
+ ));
+
+ $this->addElement('submit', 'save', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Save',
+ ));
+
+ $this->addElement('button', 'cancel', array(
+ 'required' => false,
+ 'ignore' => true,
+ 'label' => 'Cancel',
+ 'onclick' => 'location.href="/user/person/"',
+ ));
+ }
+
+
+}
+
diff --git a/application/modules/user/views/scripts/person/edit.phtml b/application/modules/user/views/scripts/person/edit.phtml
new file mode 100644
index 0000000..955ed35
--- /dev/null
+++ b/application/modules/user/views/scripts/person/edit.phtml
@@ -0,0 +1,4 @@
+<?php
+$this->editForm->setAction($this->url());
+echo $this->editForm;
+?> \ No newline at end of file
diff --git a/application/modules/user/views/scripts/person/index.phtml b/application/modules/user/views/scripts/person/index.phtml
index 7a96e97..3826d25 100644
--- a/application/modules/user/views/scripts/person/index.phtml
+++ b/application/modules/user/views/scripts/person/index.phtml
@@ -1 +1,60 @@
-<br /><br /><center>View script for controller <b>Person</b> and script/action name <b>index</b></center> \ No newline at end of file
+<h1>Person</h1>
+<?php echo $this->formButton('editperson', 'Edit', array(
+ 'onclick' => 'self.location="/user/person/edit/"',
+ 'class' => 'rightbutton'))?>
+<br />
+<br />
+<div class="personColorDiv"><span class="bold">Title:</span>&nbsp;<?php echo $this->person->getTitle(); ?></div>
+<div class="personDiv"><span class="bold">Name:</span>&nbsp;<?php echo $this->person->getName(); ?></div>
+<div class="personColorDiv"><span class="bold">Firstname:</span>&nbsp;<?php echo $this->person->getFirstname(); ?></div>
+<div class="personDiv"><span class="bold">Street:</span>&nbsp;<?php echo $this->person->getStreet(); ?></div>
+<div class="personColorDiv"><span class="bold">Housenumber:</span>&nbsp;<?php echo $this->person->getHousenumber(); ?></div>
+<div class="personDiv"><span class="bold">City:</span>&nbsp;<?php echo $this->person->getCity(); ?></div>
+<div class="personColorDiv"><span class="bold">Postalcode:</span>&nbsp;<?php echo $this->person->getPostalcode(); ?></div>
+<div class="personDiv"><span class="bold">Email:</span>&nbsp;<?php echo $this->person->getEmail(); ?></div>
+<div class="personColorDiv"><span class="bold">Last Login Date:</span>&nbsp;<?php if( $this->person->getLogindate()) echo date ('d. F Y - H:i', $this->person->getLogindate()) . " Uhr"; ?></div>
+<div class="personDiv"><span class="bold">Register Date:</span>&nbsp;<?php echo date ('d. F Y - H:i', $this->person->getRegisterdate()) . ' Uhr'; ?></div>
+<?php
+if(isset($this->groups)) {
+ ?>
+<br />
+<h2>Member in the following Groups:</h2>
+<table>
+<?php
+foreach($this->groups as $group) {
+ ?>
+ <tr>
+ <th>Title</th>
+ <th>Description</th>
+ <th>Leave</th>
+ </tr>
+ <tr>
+ <td><?php echo $group['title']; ?></td>
+ <td><?php echo $group['description']; ?></td>
+ <td class='action'><a
+ href="<?php echo $this->url(
+ array(
+ 'module' => 'user',
+ 'controller' => 'person',
+ 'action' => 'leave',
+ 'membershipID' => $group['membershipID']
+ ),
+ 'default',
+ true) ?>"> <img src='/media/img/delete.png' alt='Delete Group' /></a>
+ </td>
+ </tr>
+ <?php
+}
+}
+?>
+</table>
+<?php echo $this->formButton('addtogroup', 'Add to additional
+Groups', array(
+ 'onclick' => 'self.location="/user/person/request/"',
+ 'class' => 'addbutton'));
+?>
+<br />
+<br />
+<br />
+<br />
+<br />
diff --git a/application/modules/user/views/scripts/person/request.phtml b/application/modules/user/views/scripts/person/request.phtml
new file mode 100644
index 0000000..2da570f
--- /dev/null
+++ b/application/modules/user/views/scripts/person/request.phtml
@@ -0,0 +1,6 @@
+<?php
+if(count($this->requestForm->getGrouplist())>0) {
+ $this->requestForm->setAction($this->url());
+ echo $this->requestForm;
+}
+?> \ No newline at end of file