Esempio n. 1
0
 public function delete($con = null)
 {
     foreach (sfMixer::getCallables('BaseTemplateRecord:delete:pre') as $callable) {
         $ret = call_user_func($callable, $this, $con);
         if ($ret) {
             return;
         }
     }
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(TemplateRecordPeer::DATABASE_NAME);
     }
     try {
         $con->begin();
         TemplateRecordPeer::doDelete($this, $con);
         $this->setDeleted(true);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollback();
         throw $e;
     }
     foreach (sfMixer::getCallables('BaseTemplateRecord:delete:post') as $callable) {
         call_user_func($callable, $this, $con);
     }
 }
Esempio n. 2
0
 /**
  * Edit
  */
 public function executeEdit()
 {
     if ($this->isGET()) {
         return $this->renderJson(array("success" => false, "info" => "POST Only."));
     } else {
         $template = $this->template;
         $template->setName($this->getRequestParameter('name'));
         $template->setType($this->getRequestParameter('type'));
         $template->save();
         $ids = array();
         foreach ($this->getRequestParameter('record') as $data) {
             if (!($record = TemplateRecordPeer::retrieveByPK($data['id']))) {
                 $record = new TemplateRecord();
                 $record->setTemplateId($template->getId());
             }
             $record->setName($data['name']);
             $record->setType($data['type']);
             $record->setContent($data['content']);
             $record->setTtl($data['ttl']);
             if ($data['type'] == 'MX') {
                 $record->setPrio($data['prio']);
             }
             $record->save();
             $ids[] = $record->getId();
         }
         $c = new Criteria();
         $c->add(TemplateRecordPeer::TEMPLATE_ID, $template->getId());
         $c->add(TemplateRecordPeer::ID, $ids, Criteria::NOT_IN);
         TemplateRecordPeer::doDelete($c);
         return $this->renderJson(array("success" => true, "info" => "Template updated."));
     }
 }