dmBridge PHP API
DMObjectCommentForm.php
00001 <?php
00002 #
00003 # dmBridge: a data access framework for CONTENTdm(R)
00004 #
00005 # Copyright © 2009, 2010, 2011 Board of Regents of the Nevada System of Higher
00006 # Education, on behalf of the University of Nevada, Las Vegas
00007 #
00008 
00013 class DMObjectCommentForm extends DMAbstractForm {
00014 
00015    protected function init() {
00016       $f = new DMTextField('name');
00017       $f->addAttribute('id', 'dmCommentName');
00018       $f->setMinLength(2);
00019       $f->setMaxLength(50);
00020       $f->setLabel('Name');
00021       $this->addField($f);
00022 
00023       $f = new DMTextField('email');
00024       $f->addAttribute('id', 'dmCommentEmail');
00025       $f->setMinLength(0);
00026       $f->setMaxLength(100);
00027       $f->setType(DMFormFieldType::EMAIL);
00028       $f->setLabel('Email');
00029       $this->addField($f);
00030 
00031       $f = new DMTextareaField('text');
00032       $f->addAttribute('id', 'dmCommentText');
00033       $f->setNumRows(5);
00034       $f->setNumColumns(5);
00035       $f->setMinLength(5);
00036       $f->setMaxLength(10000);
00037       $f->setLabel('Comment text');
00038       $this->addField($f);
00039 
00040       $f = new DMHiddenField('fauxcomment');
00041       $f->setMaxLength(0);
00042       $f->setRequired(false);
00043       $this->addField($f);
00044 
00045       $f = new DMHiddenField('answer');
00046       $f->setType(DMFormFieldType::INTEGER);
00047       $f->setMin(0);
00048       $f->setMax(20);
00049       $f->setValue(array_sum(DMAbstractForm::getCaptchaOperands()));
00050       $this->addField($f);
00051 
00052       $f = new DMTextField('response');
00053       $f->addAttribute('id', 'dmResponse');
00054       $f->setSize(2);
00055       $f->setMaxLength(2);
00056       $f->setLabel('Math response');
00057       $f->setStaticValidationMessage(
00058          DMLocalizedString::getString('INCORRECT_MATH_RESPONSE'));
00059       $this->addField($f);
00060 
00061       $f = new DMHiddenField('alias');
00062       $f->setMinLength(2);
00063       $f->setMaxLength(30);
00064       $f->setLabel('Alias');
00065       $this->addField($f);
00066 
00067       $f = new DMHiddenField('ptr');
00068       $f->setType(DMFormFieldType::INTEGER);
00069       $f->setMin(0);
00070       $f->setMax(9999999);
00071       $f->setLabel('Pointer');
00072       $this->addField($f);
00073    }
00074 
00075    protected function loadFromPOSTData(array $data) {
00076       parent::loadFromPOSTData($data);
00077       $this->getFieldByName('response')->addAllowedValue(
00078          $this->getFieldByName('answer')->getValue());
00079       $this->getFieldByName('answer')->setValue(
00080          array_sum(DMAbstractForm::getCaptchaOperands()));
00081    }
00082 
00083 
00089    public function doAction() {
00090       $col = DMCollectionFactory::getCollection(
00091             $this->getFieldByName('alias')->getValue());
00092       // the DMObject that has been commented on
00093       $obj = DMObjectFactory::getObject($col,
00094             $this->getFieldByName('ptr')->getValue());
00095 
00096       $c = new DMComment();
00097       $c->setEmail($this->getFieldByName('email')->getValue());
00098       $c->setName($this->getFieldByName('name')->getValue());
00099       $c->setValue($this->getFieldByName('text')->getValue());
00100 
00101       $obj->addComment($c);
00102       if (DMConfigXML::getInstance()->isCommentNotificationEnabled()) {
00103          $mailer = new DMMailer();
00104          $mailer->sendNotificationOfNewComment($c);
00105       }
00106       DMHTTPRequest::getCurrent()->getSession()->addHasCommented($obj);
00107    }
00108 
00109 }
 All Data Structures Functions Variables