public function testIdentity() { $element2 = unserialize(serialize($this->element)); $this->assertTrue($this->element->equals($element2)); $element3 = new Element(); $this->assertTrue($element2->getID() == $element3->getID() - 1); }
private function render(\DOMDocument $doc, Element $element, $parent = null) { if ($element instanceof \tarcisio\svg\SVG) { $svgs = $doc->getElementsByTagName('svg'); $svg = $svgs->item(0); $svg->setAttribute('width', $element->width); $svg->setAttribute('height', $element->height); $svg->setAttribute('viewBox', "0 0 {$element->width} {$element->height}"); $gs = $doc->getElementsByTagName('g'); $g = $gs->item(0); foreach ($element->getChildren() as $ch) { $this->render($doc, $ch, $g); } return $doc; } if (!is_null($element->getTitle())) { $element->appendChild(new Title('', $element->getTitle())); } $e = $doc->createElement($element->getElementName()); $parent->appendChild($e); foreach ($element->getAttributes() as $k => $v) { if (!is_null($v)) { $e->setAttribute($k, $v); } } if (!is_null($element->getValue())) { $e->nodeValue = $element->getValue(); } foreach ($element->getChildren() as $ch) { $this->render($doc, $ch, $e); } return $doc; }
/** * Find list item by search * @param \Jazzee\Entity\Element $element * @param array $searchTerms * @param array $variables * @return array */ public function search(Element $element, $searchTerms, $variables = array()) { $queryBuilder = $this->_em->createQueryBuilder(); $queryBuilder->add('select', 'item')->from('Jazzee\\Entity\\ElementListItem', 'item')->leftJoin('item.variables', 'variable'); $queryBuilder->where('item.element = :elementId'); $queryBuilder->setParameter('elementId', $element->getId()); $expression = $queryBuilder->expr()->orX(); $expression2 = $queryBuilder->expr()->andX(); foreach ($searchTerms as $key => $term) { $expression2->add($queryBuilder->expr()->like("item.value", ":term{$key}")); $queryBuilder->setParameter("term{$key}", '%' . $term . '%'); } $expression->add($expression2); $expression2 = $queryBuilder->expr()->andX(); foreach ($searchTerms as $key => $term) { $expression3 = $queryBuilder->expr()->andX(); foreach ($variables as $key2 => $name) { $expression3->add($queryBuilder->expr()->eq("variable.name", ":v{$key2}")); $expression3->add($queryBuilder->expr()->like("variable.value", ":term{$key}")); $queryBuilder->setParameter('v' . $key2, $name); } $expression2->add($expression3); $queryBuilder->setParameter("term{$key}", '%' . $term . '%'); } $expression->add($expression2); $queryBuilder->andWhere($expression); return $queryBuilder->getQuery()->getResult(); }
/** * Write table * * @return string */ public function write() { $html = ''; $rows = $this->element->getRows(); $rowCount = count($rows); if ($rowCount > 0) { $html .= '<table>' . PHP_EOL; foreach ($rows as $row) { // $height = $row->getHeight(); $rowStyle = $row->getStyle(); $tblHeader = $rowStyle->getTblHeader(); $html .= '<tr>' . PHP_EOL; foreach ($row->getCells() as $cell) { $cellTag = $tblHeader ? 'th' : 'td'; $cellContents = $cell->getElements(); $html .= "<{$cellTag}>" . PHP_EOL; if (count($cellContents) > 0) { foreach ($cellContents as $content) { $writer = new Element($this->parentWriter, $content, false); $html .= $writer->write(); } } else { $writer = new Element($this->parentWriter, new \PhpOffice\PhpWord\Element\TextBreak(), false); $html .= $writer->write(); } $html .= '</td>' . PHP_EOL; } $html .= '</tr>' . PHP_EOL; } $html .= '</table>' . PHP_EOL; } return $html; }
/** * Get root element of this component. * @return Element */ private function getRoot() { if ($this->root === NULL) { $selector = reset($this->parameters); $strategy = key($this->parameters); if ($selector instanceof Element) { $this->root = $selector; } else { $this->root = $this->parent->findElement($strategy, $selector); } $expectedTagName = next($this->parameters); $expectedAttributes = next($this->parameters); if ($expectedTagName !== FALSE) { $actualTagName = $this->root->name(); if ($actualTagName !== $expectedTagName) { throw new ViewStateException("Root element of '" . get_class($this) . "' is expected to be tag '{$expectedTagName}', but is '{$actualTagName}'."); } } if ($expectedAttributes !== FALSE) { foreach ($expectedAttributes as $attributeName => $expectedAttributeValue) { $actualAttributeValue = $this->root->attribute($attributeName); if ($actualAttributeValue !== $expectedAttributeValue) { throw new ViewStateException("Root element's attribute '{$attributeName}' is expected to be '{$expectedAttributeValue}', but is '{$actualAttributeValue}'."); } } } } return $this->root; }
/** * Inserts a new element into the hash following the specified element. * * @param null|Element $before The element that precedes the new element. The element is inserted at the beginning * when this parameter is NULL. * @param string|int $key The new element's key. * @param mixed $value The new element's value. * @throws \OutOfRangeException Thrown when the key is not a string or integer. * @throws \RuntimeException Thrown when the key is not unique. */ public function add($before, $key, $value) { if (!(is_string($key) || is_int($key))) { throw new \OutOfRangeException("{$key} must be a string or an integer"); } if ($this->offsetExists($key)) { throw new \RuntimeException("{$key} must be unique"); } $after = null; $element = new Element($key, $value); $element->setBefore($before); if (is_null($before)) { // insert at the head $after = $this->head; $element->setAfter($after); $this->head = $element; } else { // insert between an element and the element that follows it $after = $before->getAfter(); $before->setAfter($element); $element->setAfter($after); } if (is_null($after)) { // it was inserted at the tail $this->tail = $element; } else { $after->setBefore($element); } $this->elements[$key] = $element; }
public function asHtml() { /* redefine html output for this page special case grabs head and tail lists and constructs entire page with doctype */ // get the head/tail before contents duplicated $page_head = $this->_get_head(); $page_tail = $this->_get_tail(); $page_ready = $this->_get_ready(); // construct ready script section $ready_script = NULL; if ($page_ready) { $scripts = implode("\n", $page_ready); $ready_script_func = implode("\n", array('$(document).ready(function(){', $scripts, '});')); $ready_script = new Element('script', array('type' => 'text/javascript', 'html' => $ready_script_func)); } // create fake body element $body = new Element('body'); $body->contents = $this->contents; $body->attributes = $this->attributes; // construct page with head and body $html = new Element('html', $this->attributes); $head = new Element('head'); $title = new Element('title', array('text' => $this->title)); $html->Add($head); $head->Add($title); $head->Add($page_head); $html->Add($body); $body->Add($page_tail); $body->Add($ready_script); return '<!DOCTYPE html>' . $html->asHtml() . "\n"; }
/** * Add an element to the tray * * @param Element $formElement Element to add * @param boolean $required true = entry required * * @return void */ public function addElement(Element $formElement, $required = false) { $this->elements[] = $formElement; if ($required) { $formElement->setRequired(); } }
public static function formTest() { $form = new Element('form'); $form->addElement(new Text(array('label' => 'Nome Completo: ', 'name' => 'nome', 'size' => '40', 'maxlength' => '80'))); $form->addElement(new Text(array('label' => 'E-mail: ', 'name' => 'E-mail', 'size' => '30', 'maxlength' => '40'))); $form->addElement(new Button(array('value' => 'Enviar', 'id' => 'cadastra'))); $form->mount(); }
/** * @param mixed $value * @param string $message * @return boolean */ public function isValid($value, &$messages = array()) { if ($value != $this->compare->getValue()) { $messages[] = $this->getErrorMessage(self::ERR_NOT_EQUAL); return false; } return true; }
/** * Add an element * @param \Foundation\Form\Element */ public function addElement(Element $element) { if (array_key_exists($element->getName(), $this->form->getElements())) { $message = 'An element with the name ' . $element->getName() . ' already exists in this form'; throw new \Foundation\Exception($message); } $this->elements[$element->getName()] = $element; }
public function show($template) { require 'views/header.php'; $chapters = $this->getAllChaptersHTML(); $slides = new Element("slides", null, $chapters); echo $slides->toHTML(); require 'views/footer.php'; }
private function _script($src) { $js = new Element('script'); $js->attr('type', 'text/javascript'); $js->attr('src', $src); $js->add(''); $this->_js = $js; return $this; }
function s_element_replace(array $matches) { if (isset($matches[1])) { $dD = new DataStore(); $o_Element = new Element($dD->get_element_data($matches[1])); $o_Element->_set_full_element($dD->o_get_full_element($matches[1])); return $o_Element->render(); } }
/** * Updates an element in cache * @param Element $element The element to update */ public static function updateElement($element) { $elementClass = $element->getElementClass(); $elementId = $element->id; // Updates element attributes if already cached if (self::isCachedElement($elementClass, $elementId)) { self::$cachedElementArray[$elementClass][$elementId] = $element; } }
/** * Determines if the Element should `read` or `decode` the value. * * @param Element $element The Element object * @param mixed $value The value to put in the Object * @param boolean $decode True to `decode`, false to `read` * * @return Element An Element object representing the value */ public function decodeOrRead($element, $value, $decode) { if ($decode) { $element->decode($value); } else { $element->read($value); } return $element; }
/** * 開始タグまたは空要素タグの共通部分を書式化します. * @param Element $element 書式化対象の要素 * @return string "<elementName ... " */ protected final function formatTagPrefix(Element $element) { $tag = "<"; $tag .= $element->getName(); foreach ($element->getAttributes() as $name => $value) { $tag .= " "; $tag .= $value === null ? $this->formatBooleanAttribute($name) : $this->formatAttribute($name, $value); } return $tag; }
/** * Update the tabIndex attribute, in case of changes to tabIndex or disabled * state. * * @return $this */ public function updateTabIndex() { $disabled = $this->isDisabled(); if ($this->tabIndex !== null) { $this->tabIndexed->setAttributes(['tabindex' => $disabled ? -1 : $this->tabIndex, 'aria-disabled' => $disabled ? 'true' : 'false']); } else { $this->tabIndexed->removeAttributes(['tabindex', 'aria-disabled']); } return $this; }
protected function renderLabel(Element $element) { $label = $element->getLabel(); if (!empty($label)) { echo '<label class="control-label" for="', $element->getAttribute("id"), '">'; if ($element->isRequired()) { echo '<span class="required">* </span>'; } echo $label, '</label>'; } }
/** Returns an {@link Element} based on a {@link \DOMElement}. * @param \DOMElement $node the source element. * @return \kwebble\hadroton\Element the resulting element. */ private function createElement(\DOMElement $domElement) { $attributes = []; foreach ($domElement->attributes as $attribute) { $attributes[$attribute->nodeName] = $attribute->nodeValue; } $element = new Element($domElement->tagName, $attributes); foreach ($domElement->childNodes as $domChild) { $element->append($this->createNode($domChild)); } return $element; }
/** * Modify the value * * @param Element $element * @param mixed $isValid * @return mixed */ public function validation(Element $element, $isValid) { if (!$isValid) { return false; } $message = null; $isValid = call_user_func($this->callback, $value, $message); if (!$isValid) { $element->setError($message); } return $isValid; }
protected function renderLabel(Element $element) { $label = $element->getLabel(); if (empty($label)) { $label = ''; } echo ' <label class="text-left-xs col-xs-12 col-md-4 control-label" for="', $element->getAttribute("id"), '">'; if (!$this->noLabel && $element->isRequired()) { echo '<span class="required">* </span>'; } echo $label, '</label> '; }
protected function renderLabel(Element $element) { $label = $element->getLabel(); if (!empty($label)) { //echo '<label class="control-label" for="', $element->getAttribute("id"), '">'; echo '<div class="rmfield" for="', $element->getAttribute("id"), '"><label>'; if ($element->isRequired()) { echo '<sup class="required">* </sup>'; } echo $label, '</label></div>'; } }
public function valueChanged(Element $element, $params) { // do nothing until the model is assigned (bound) if (!$this->form->modelAssigned()) { return; } $this->form->updateModel($element->name, $element->val()); // if value on the model has been transformed in some way, assign it back to element $modelValue = $this->form->getModel()->{$element->name}; if ($modelValue != $element->val()) { $element->val($modelValue); } }
private function encode(Element $element) { $chromosomeLength = count($element->getProperties()); $this->elementId = $element->getId(); $this->elementName = $element->getCssTag(); $newChromosome = new SplFixedArray($chromosomeLength); $chromosomeIndex = 0; foreach ($element->getProperties() as $property) { $newChromosome[$chromosomeIndex] = $property->getRandomValue(); $chromosomeIndex++; } return $newChromosome; }
/** * Set title. * * @param string|null $title Title text or null for no title * @return $this */ public function setTitle($title) { $title = $title !== '' ? $title : null; if ($this->title !== $title) { $this->title = $title; if ($title !== null) { $this->titled->setAttributes(['title' => $title]); } else { $this->titled->removeAttributes(['title']); } } return $this; }
public function startElement(Element $element) { $this->xmlWriter->startElement($element->getName()); $attr = $element->getAttr(); foreach ($attr as $k => $v) { $this->xmlWriter->startAttribute($k); $this->xmlWriter->text($v); $this->xmlWriter->endAttribute(); } if ('' !== $element->getText()) { $this->xmlWriter->text($element->getText()); } }
public function getValue(Element $element) { $result = null; $data = $element->data(); foreach ($data['option'] as $data_value) { foreach ($element->config->option as $object) { if ($object['value'] == $data_value) { $result = $object; break 2; } } } return $result; }
protected function bindAspectsToElement(Element &$obj) { $aspectIds = $this->Request->getParameter('Aspects'); $aspects = array(); foreach ((array) $aspectIds as $aspectId) { $aspect = $this->AspectService->getByID($aspectId); $aspects[] = $aspect; } $obj->setAspects($aspects); $siteSlug = $this->Request->getParameter('AnchoredSiteSlug'); $obj->setAnchoredSiteSlug($siteSlug); $obj->setAnchoredSiteSlugOverride($siteSlug); $obj->setAnchoredSite($this->SiteService->getBySlug($siteSlug)); }
public function saveBook() { $book = Input::get('book'); $chapters = Input::get('chapters'); $bookMdl = Book::find($book['id']); $bookMdl->name = iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $book['name']); $bookMdl->urlname = str_replace(' ', '-', iconv('UTF-8', 'ASCII//TRANSLIT//IGNORE', $book['name'])); $bookMdl->save(); foreach ($chapters as $key => $chapter) { if ($chapter['id']) { $chapMdl = Chapter::find($chapter['id']); } else { $chapMdl = new Chapter(); } if ($chapter['id'] && $chapter['isDeleted']) { $chapMdl->delete(); } else { $chapMdl->book_id = $chapter['book_id']; $chapMdl->title = $chapter['title']; $chapMdl->markerdata = count($chapter['markerdata']) ? json_encode($chapter['markerdata']) : null; $chapMdl->order = $chapter['order']; $chapMdl->save(); if (count($chapter['elements'])) { foreach ($chapter['elements'] as $key => $element) { if ($element['id']) { $elementMdl = Element::find($element['id']); } else { $elementMdl = new Element(); } if ($element['id'] && $element['isDeleted']) { $elementMdl->delete(); } else { $elementMdl->chapter_id = $chapMdl->id ?: $element['chapter_id']; $elementMdl->order = $element['order']; $elementMdl->type = $element['type']; if ($element['type'] == 4 || $element['type'] == 5) { $elementMdl->content = json_encode($element['content']); } else { $elementMdl->content = $element['content']; } $elementMdl->note = $element['note']; $elementMdl->save(); } } } } } echo json_encode(['ok']); }