Companies: edit user's data web page
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 27 May 2012 12:18:18 +0000 (14:18 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Sun, 27 May 2012 12:18:18 +0000 (14:18 +0200)
apps/companyfront/modules/user/actions/actions.class.php [new file with mode: 0644]
apps/companyfront/modules/user/templates/_form.php [new file with mode: 0644]
apps/companyfront/modules/user/templates/editSuccess.php [new file with mode: 0644]
apps/companyfront/modules/user/templates/indexSuccess.php [new file with mode: 0644]
apps/companyfront/modules/user/templates/newSuccess.php [new file with mode: 0644]
apps/companyfront/modules/user/templates/showSuccess.php [new file with mode: 0644]
apps/companyfront/templates/layout.php
lib/form/doctrine/sfDoctrineGuardPlugin/sfGuardUserForm.class.php
test/functional/companyfront/userActionsTest.php [new file with mode: 0644]

diff --git a/apps/companyfront/modules/user/actions/actions.class.php b/apps/companyfront/modules/user/actions/actions.class.php
new file mode 100644 (file)
index 0000000..34263db
--- /dev/null
@@ -0,0 +1,90 @@
+<?php
+
+/**
+ * user actions.
+ *
+ * @package    mobiads
+ * @subpackage user
+ * @author     Gustavo Martin Morcuende
+ * @version
+ */
+class userActions extends sfActions
+{
+  public function executeIndex(sfWebRequest $request)
+  {
+    //Get user Id
+    $userId = $this->getUser()->getGuardUser()->getId();
+
+    $this->sf_guard_user = sfGuardUserTable::getInstance()->findOneById($userId);
+  }
+
+  public function executeShow(sfWebRequest $request)
+  {
+    $this->sf_guard_user = Doctrine_Core::getTable('sfGuardUser')->find(array($request->getParameter('id')));
+    $this->forward404Unless($this->sf_guard_user);
+  }
+
+  public function executeNew(sfWebRequest $request)
+  {
+    $this->form = new sfGuardUserForm();
+  }
+
+  public function executeCreate(sfWebRequest $request)
+  {
+    $this->forward404Unless($request->isMethod(sfRequest::POST));
+
+    $this->form = new sfGuardUserForm();
+
+    $this->processForm($request, $this->form);
+
+    $this->setTemplate('new');
+  }
+
+  public function executeEdit(sfWebRequest $request)
+  {
+    //Get user Id
+    $userId = $this->getUser()->getGuardUser()->getId();
+
+    $sf_guard_user = sfGuardUserTable::getInstance()->findOneById($userId);
+    $this->form = new sfGuardUserForm($sf_guard_user);
+  }
+
+  public function executeUpdate(sfWebRequest $request)
+  {
+    $this->forward404Unless($request->isMethod(sfRequest::POST) || $request->isMethod(sfRequest::PUT));
+    $this->forward404Unless($sf_guard_user = Doctrine_Core::getTable('sfGuardUser')->find(array($request->getParameter('id'))), sprintf('Object sf_guard_user does not exist (%s).', $request->getParameter('id')));
+
+    //Get user Id
+    $userId = $this->getUser()->getGuardUser()->getId();
+    //Never trust data coming from users
+    $this->forward404Unless($userId == $sf_guard_user->getId(), sprintf('User does not exist'));
+
+    $this->form = new sfGuardUserForm($sf_guard_user);
+
+    $this->processForm($request, $this->form);
+
+    $this->setTemplate('edit');
+  }
+
+  public function executeDelete(sfWebRequest $request)
+  {
+    $request->checkCSRFProtection();
+
+    $this->forward404Unless($sf_guard_user = Doctrine_Core::getTable('sfGuardUser')->find(array($request->getParameter('id'))), sprintf('Object sf_guard_user does not exist (%s).', $request->getParameter('id')));
+    $sf_guard_user->delete();
+
+    $this->redirect('user/index');
+  }
+
+  protected function processForm(sfWebRequest $request, sfForm $form)
+  {
+    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
+    if ($form->isValid())
+    {
+      $sf_guard_user = $form->save();
+
+      $this->redirect('user/edit?id='.$sf_guard_user->getId());
+    }
+  }
+}
diff --git a/apps/companyfront/modules/user/templates/_form.php b/apps/companyfront/modules/user/templates/_form.php
new file mode 100644 (file)
index 0000000..926b112
--- /dev/null
@@ -0,0 +1,25 @@
+<?php use_stylesheets_for_form($form) ?>
+<?php use_javascripts_for_form($form) ?>
+
+<form action="<?php echo url_for('user/update?id='.$form->getObject()->getId()) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
+<?php if (!$form->getObject()->isNew()): ?>
+<input type="hidden" name="sf_method" value="put" />
+<?php endif; ?>
+  <table>
+    <tfoot>
+      <tr>
+        <td colspan="2">
+          <?php echo $form->renderHiddenFields(false) ?>
+          &nbsp;<a href="<?php echo url_for('user/index') ?>"><?php echo __('Back') ?></a>
+          <input type="submit" value="<?php echo __('Save') ?>" />
+        </td>
+      </tr>
+    </tfoot>
+    <tbody>
+      <?php echo $form->renderGlobalErrors() ?>
+      <tr>
+          <?php echo $form ?>
+      </tr>
+    </tbody>
+  </table>
+</form>
diff --git a/apps/companyfront/modules/user/templates/editSuccess.php b/apps/companyfront/modules/user/templates/editSuccess.php
new file mode 100644 (file)
index 0000000..ac23570
--- /dev/null
@@ -0,0 +1,4 @@
+<h2><?php echo __('Edit Your Personal Data') ?></h2>
+
+
+<?php include_partial('form', array('form' => $form)) ?>
diff --git a/apps/companyfront/modules/user/templates/indexSuccess.php b/apps/companyfront/modules/user/templates/indexSuccess.php
new file mode 100644 (file)
index 0000000..28249a8
--- /dev/null
@@ -0,0 +1,29 @@
+<h2><?php echo __('Your Personal Data') ?></h2>
+
+<table id="rounded-corner">
+  <tbody>
+    <tr>
+      <td><?php echo __('First Name: ') ?></td>
+      <td><?php echo $sf_guard_user->getFirstName() ?></td>
+    </tr>
+    <tr>
+      <td><?php echo __('Last Name: ') ?></td>
+      <td><?php echo $sf_guard_user->getLastName() ?></td>
+    </tr>
+    <tr>
+      <td><?php echo __('Email Address: ') ?></td>
+      <td><?php echo $sf_guard_user->getEmailAddress() ?></td>
+    </tr>
+    <tr>
+      <td><?php echo __('Last Login') ?></td>
+      <td><?php echo $sf_guard_user->getLastLogin() ?></td>
+    </tr>
+    <tr>
+      <td><?php echo __('Language') ?></td>
+      <td><?php echo $sf_guard_user->getLanguage()->getLanguageName() ?></td>
+    </tr>
+  </tbody>
+</table>
+
+  <a href="<?php echo url_for('user/edit') ?>" class="bt_green"><span class="bt_green_lft"></span><strong><?php echo __('Edit Your Data') ?></strong><span class="bt_green_r"></span></a>
+
diff --git a/apps/companyfront/modules/user/templates/newSuccess.php b/apps/companyfront/modules/user/templates/newSuccess.php
new file mode 100644 (file)
index 0000000..480f447
--- /dev/null
@@ -0,0 +1,3 @@
+<h1>New Sf guard user</h1>
+
+<?php include_partial('form', array('form' => $form)) ?>
diff --git a/apps/companyfront/modules/user/templates/showSuccess.php b/apps/companyfront/modules/user/templates/showSuccess.php
new file mode 100644 (file)
index 0000000..d85fee1
--- /dev/null
@@ -0,0 +1,66 @@
+<table>
+  <tbody>
+    <tr>
+      <th>Id:</th>
+      <td><?php echo $sf_guard_user->getId() ?></td>
+    </tr>
+    <tr>
+      <th>First name:</th>
+      <td><?php echo $sf_guard_user->getFirstName() ?></td>
+    </tr>
+    <tr>
+      <th>Last name:</th>
+      <td><?php echo $sf_guard_user->getLastName() ?></td>
+    </tr>
+    <tr>
+      <th>Email address:</th>
+      <td><?php echo $sf_guard_user->getEmailAddress() ?></td>
+    </tr>
+    <tr>
+      <th>Username:</th>
+      <td><?php echo $sf_guard_user->getUsername() ?></td>
+    </tr>
+    <tr>
+      <th>Algorithm:</th>
+      <td><?php echo $sf_guard_user->getAlgorithm() ?></td>
+    </tr>
+    <tr>
+      <th>Salt:</th>
+      <td><?php echo $sf_guard_user->getSalt() ?></td>
+    </tr>
+    <tr>
+      <th>Password:</th>
+      <td><?php echo $sf_guard_user->getPassword() ?></td>
+    </tr>
+    <tr>
+      <th>Is active:</th>
+      <td><?php echo $sf_guard_user->getIsActive() ?></td>
+    </tr>
+    <tr>
+      <th>Is super admin:</th>
+      <td><?php echo $sf_guard_user->getIsSuperAdmin() ?></td>
+    </tr>
+    <tr>
+      <th>Last login:</th>
+      <td><?php echo $sf_guard_user->getLastLogin() ?></td>
+    </tr>
+    <tr>
+      <th>Language:</th>
+      <td><?php echo $sf_guard_user->getLanguageId() ?></td>
+    </tr>
+    <tr>
+      <th>Created at:</th>
+      <td><?php echo $sf_guard_user->getCreatedAt() ?></td>
+    </tr>
+    <tr>
+      <th>Updated at:</th>
+      <td><?php echo $sf_guard_user->getUpdatedAt() ?></td>
+    </tr>
+  </tbody>
+</table>
+
+<hr />
+
+<a href="<?php echo url_for('user/edit?id='.$sf_guard_user->getId()) ?>">Edit</a>
+&nbsp;
+<a href="<?php echo url_for('user/index') ?>">List</a>
index f62cac1..4ad66ea 100644 (file)
@@ -90,7 +90,7 @@
                     <li><a href="<?php echo url_for('category/new') ?>"><?php echo __('Create New Category') ?></a></li>
                     </ul>
                 </div>
-                <a class="menuitem submenuheader" href=""><?php echo __('Ads Index') ?></a>
+                <a class="menuitem submenuheader" href=""><?php echo __('Ads') ?></a>
                 <div class="submenu">
                     <ul>
                     <li><a href="<?php echo url_for('ad/index') ?>"><?php echo __('Ads Index') ?></a></li>
@@ -98,7 +98,7 @@
                     </ul>
                 </div>
                 
-                <a class="menuitem_green" href="<?php echo url_for('company/index') ?>"><?php echo __('Your Personal Data') ?></a>
+                <a class="menuitem_green" href="<?php echo url_for('user/index') ?>"><?php echo __('Your Personal Data') ?></a>
                 
                 <a class="menuitem_red" href="<?php echo url_for('company/index') ?>"><?php echo __('Your Company') ?></a>
                     
index 1ad828f..79cd4a7 100644 (file)
@@ -5,12 +5,21 @@
  *
  * @package    mobiads
  * @subpackage form
- * @author     Your name here
- * @version    SVN: $Id: sfDoctrinePluginFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
+ * @author     Gustavo Martin Morcuende
+ * @version
  */
 class sfGuardUserForm extends PluginsfGuardUserForm
 {
   public function configure()
   {
+    $this->useFields(array('first_name', 'last_name', 'email_address', 'language_id'));
+
+
+    $this->widgetSchema['language_id'] = new sfWidgetFormDoctrineChoice(array('model'     => $this->getRelatedModelName('Language'),
+                                                                              'add_empty' => false));
+
+
+    $this->validatorSchema['language_id'] = new sfValidatorDoctrineChoice(array('model'    => $this->getRelatedModelName('Language'),
+                                                                                'required' => true));
   }
 }
diff --git a/test/functional/companyfront/userActionsTest.php b/test/functional/companyfront/userActionsTest.php
new file mode 100644 (file)
index 0000000..a8156ff
--- /dev/null
@@ -0,0 +1,19 @@
+<?php
+
+include(dirname(__FILE__).'/../../bootstrap/functional.php');
+
+$browser = new sfTestFunctional(new sfBrowser());
+
+$browser->
+  get('/user/index')->
+
+  with('request')->begin()->
+    isParameter('module', 'user')->
+    isParameter('action', 'index')->
+  end()->
+
+  with('response')->begin()->
+    isStatusCode(200)->
+    checkElement('body', '!/This is a temporary page/')->
+  end()
+;