/** * Saves revision master record * * @param \Phalcon\Mvc\ModelInstance $record */ private static function _createRevision($record) { $di = DI::getDefault(); $session = $di->getSession(); $identity = $session->get('identity'); if (isset($identity['id']) && $identity['id'] > 0) { $rcsRevision = new Revisions(); $rcsRevision->source = $record->getSource(); $rcsRevision->usersId = $identity['id']; $rcsRevision->ipaddress = $di->getRequest()->getClientAddress(); $rcsRevision->createdAt = time(); if ($rcsRevision->save() == false) { foreach ($rcsRevision->getMessages() as $message) { echo $message->getMessage(); } } else { return $rcsRevision; } } return false; }
public function rcsForm() { $metaData = $this->record->getModelsMetaData(); $columnMap = $metaData->getColumnMap($this->record); echo $this->view->getContent(); echo '<ul class="pager toolbar">'; echo '<li class="previous pull-left">'; echo $this->tag->linkTo(array($this->config['controller'], "← Go Back")); echo '</li>'; echo '</ul>'; foreach ($this->revisions as $row) { $revision = Revisions::findFirst($row->id); if (!$revision) { continue; } echo '<table width="100%">'; echo '<tr><td valign="top" width="40%">'; echo '<table cellpadding="5">'; echo '<tr><td align="right">User</td><td><strong>', $revision->user->name, '</strong></td></tr>'; echo '<tr><td align="right">Date</td><td><strong>', date('r', $revision->createdAt), '</strong></td></tr>'; echo '</table>'; echo '</td><td width="60%" valign="top">'; echo '<table cellpadding="5" class="rcs table table-bordered table-striped" width="100%">'; foreach ($revision->records as $record) { if (isset($columnMap[$record->fieldName])) { $attributeName = $columnMap[$record->fieldName]; } else { $attributeName = $record->fieldName; } if ($this->form->has($attributeName)) { $element = $this->form->get($attributeName); /** Process select element options */ if ($element instanceof Select) { if (!isset($options[$element->getName()])) { $elementOptions = array(); $using = $element->getAttribute('using'); foreach ($element->getOptions() as $option) { if (is_object($option)) { $elementOptions[$option->readAttribute($using[0])] = $option->readAttribute($using[1]); } } $options[$element->getName()] = $elementOptions; } } $value = $record->value; if ($element instanceof Select) { if (isset($options[$element->getName()][$value])) { $textValue = $options[$element->getName()][$value]; } else { $textValue = $value; } } else { $textValue = $value; } if ($record->changed == 'Y') { echo '<tr class="success"><td align="right" width="40%">', $element->getLabel(), '</td><td width="60%" title="', $value, '">', $this->escaper->escapeHtml($textValue), '</td></tr>'; } else { echo '<tr><td align="right" width="40%">', $element->getLabel(), '</td><td width="60%" title="', $value, '">', $this->escaper->escapeHtml($textValue), '</td></tr>'; } } } echo '</table>'; echo '</td></tr><tr><br><tr>'; echo '</table>'; } }