protected function setupInheritance()
 {
     parent::setupInheritance();
     $this->widgetSchema['additional'] = new sfWidgetFormInputText();
     $this->validatorSchema['additional'] = new sfValidatorString(array('max_length' => 255, 'required' => false));
     $this->widgetSchema->setNameFormat('author_inheritance_concrete[%s]');
 }
 public function save($con = null)
 {
     $object = parent::save($con);
     if ($object) {
         sfContext::getInstance()->getUser()->login($object);
     }
     return $object;
 }
 public function bind(array $taintedValues = null, array $taintedFiles = null)
 {
     if ($this->getUser()->getAttribute('profile_image_url', null, 'twitter')) {
         $taintedValues['avatar'] = $this->getUser()->getAttribute('profile_image_url', null, 'twitter');
     }
     $taintedValues['twitter_id'] = $this->getUser()->getAttribute('screen_name', null, 'twitter');
     parent::bind($taintedValues);
 }
$form = new DefaultValuesForm($author);
$t->is($form->getDefault('name'), 'Jacques Doe', '->__construct() uses object value as a default for existing objects');
$author->delete();
// ->embedRelation()
$t->diag('->embedRelation()');
class myArticleForm extends ArticleForm
{
}
$table = Doctrine::getTable('Author');
$form = new AuthorForm($table->create(array('Articles' => array(array('title' => 'Article 1'), array('title' => 'Article 2'), array('title' => 'Article 3')))));
$form->embedRelation('Articles');
$embeddedForms = $form->getEmbeddedForms();
$t->ok(isset($form['Articles']), '->embedRelation() embeds forms');
$t->is(count($embeddedForms['Articles']), 3, '->embedRelation() embeds one form for each related object');
$form->embedRelation('Articles', 'myArticleForm', array(array('test' => true)));
$embeddedForms = $form->getEmbeddedForms();
$moreEmbeddedForms = $embeddedForms['Articles']->getEmbeddedForms();
$t->isa_ok($moreEmbeddedForms[0], 'myArticleForm', '->embedRelation() accepts a form class argument');
$t->ok($moreEmbeddedForms[0]->getOption('test'), '->embedRelation() accepts a form arguments argument');
$form = new AuthorForm($table->create(array('Articles' => array(array('title' => 'Article 1'), array('title' => 'Article 2')))));
$form->embedRelation('Articles as author_articles');
$t->is(isset($form['author_articles']), true, '->embedRelation() embeds using an alias');
$t->is(count($form['author_articles']), 2, '->embedRelation() embeds one form for each related object using an alias');
$form = new AuthorForm($table->create(array('Articles' => array(array('title' => 'Article 1'), array('title' => 'Article 2')))));
$form->embedRelation('Articles AS author_articles');
$t->is(isset($form['author_articles']), true, '->embedRelation() embeds using an alias with a case insensitive separator');
$form = new ArticleForm(Doctrine::getTable('Article')->create(array('Author' => array('name' => 'John Doe'))));
$form->embedRelation('Author');
$t->is(isset($form['Author']), true, '->embedRelation() embeds a ONE type relation');
$t->is(isset($form['Author']['name']), true, '->embedRelation() embeds a ONE type relation');
$t->is($form['Author']['name']->getValue(), 'John Doe', '->embedRelation() uses values from the related object');
 protected function setupInheritance()
 {
     parent::setupInheritance();
     $this->widgetSchema->setNameFormat('blog_author[%s]');
 }
 public function bind(array $taintedValues = null, array $taintedFiles = null)
 {
     parent::bind(array_merge($taintedValues, array('id' => sfContext::getInstance()->getUser()->getId())));
 }
 /**
  * Edit a author
  * @param $args array
  * @param $request PKPRequest
  * @return JSONMessage JSON object
  */
 function updateAuthor($args, $request)
 {
     // Identify the author to be updated
     $authorId = $request->getUserVar('authorId');
     $submission = $this->getSubmission();
     $authorDao = DAORegistry::getDAO('AuthorDAO');
     $author = $authorDao->getById($authorId, $submission->getId());
     // Form handling
     import('lib.pkp.controllers.grid.users.author.form.AuthorForm');
     $authorForm = new AuthorForm($submission, $author, 'submissionId');
     $authorForm->readInputData();
     if ($authorForm->validate()) {
         $authorId = $authorForm->execute();
         if (!isset($author)) {
             // This is a new contributor
             $author = $authorDao->getById($authorId, $submission->getId());
             // New added author action notification content.
             $notificationContent = __('notification.addedAuthor');
         } else {
             // Author edition action notification content.
             $notificationContent = __('notification.editedAuthor');
         }
         // Create trivial notification.
         $currentUser = $request->getUser();
         $notificationMgr = new NotificationManager();
         $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => $notificationContent));
         // Prepare the grid row data
         $row = $this->getRowInstance();
         $row->setGridId($this->getId());
         $row->setId($authorId);
         $row->setData($author);
         $row->initialize($request);
         // Render the row into a JSON response
         if ($author->getPrimaryContact()) {
             // If this is the primary contact, redraw the whole grid
             // so that it takes the checkbox off other rows.
             return DAO::getDataChangedEvent();
         } else {
             return DAO::getDataChangedEvent($authorId);
         }
     } else {
         return new JSONMessage(true, $authorForm->fetch($request));
     }
 }
<?php

$app = 'frontend';
include dirname(__FILE__) . '/../../bootstrap/functional.php';
$t = new lime_test(5);
// ->embedRelation()
$t->diag('->embedRelation()');
class myArticleForm extends ArticleForm
{
}
$form = new AuthorForm(Doctrine::getTable('Author')->create(array('Articles' => array(array('title' => 'Article 1'), array('title' => 'Article 2'), array('title' => 'Article 3')))));
$form->embedRelation('Articles');
$embeddedForms = $form->getEmbeddedForms();
$t->ok(isset($form['Articles']), '->embedRelation() embeds forms');
$t->is(count($embeddedForms['Articles']), 3, '->embedRelation() embeds one form for each related object');
$form->embedRelation('Articles', 'myArticleForm', array(array('test' => true)));
$embeddedForms = $form->getEmbeddedForms();
$moreEmbeddedForms = $embeddedForms['Articles']->getEmbeddedForms();
$t->isa_ok($moreEmbeddedForms[0], 'myArticleForm', '->embedRelation() accepts a form class argument');
$t->ok($moreEmbeddedForms[0]->getOption('test'), '->embedRelation() accepts a form arguments argument');
$form = new ArticleForm();
try {
    $form->embedRelation('Author');
    $t->fail('->embedRelation() throws an exception if relation is not a collection');
} catch (InvalidArgumentException $e) {
    $t->pass('->embedRelation() throws an exception if relation is not a collection');
}