Example #1
0
 public function render($content)
 {
     $result = "<textarea {$this->getAttributes()}>{$content}</textarea>";
     $alerts = AlertManager::byField($this->name);
     foreach ($alerts as $alert) {
         $result .= $alert->render();
     }
     return $result;
 }
Example #2
0
 public function render($content)
 {
     $result = "<input {$this->getAttributes()}>";
     $alerts = AlertManager::byField($this->name);
     foreach ($alerts as $i => $alert) {
         //$result .= $alert->render();
         $result .= "<span class='help-inline'>{$alert->message()}</span>";
     }
     return $result;
 }
Example #3
0
function alerts()
{
    //$alerts = Helper::$controller->alert();
    $alerts = AlertManager::byType();
    if (count($alerts) === 0) {
        return;
    }
    foreach ($alerts as $type => $elements) {
        $result = "cognosys.alert(['";
        $result .= join("','", array_map(function ($alert) {
            return addslashes($alert->message());
        }, $elements));
        print $result . "'], '{$type}')\n";
    }
}
Example #4
0
    public function render($content)
    {
        $clear = $messages = '';
        $alerts = AlertManager::byField($this->name);
        foreach ($alerts as $i => $alert) {
            $messages .= "<span class='help-inline'>{$alert->message()}</span>";
        }
        if ($this->clear) {
            $clear = '<i class="icon-remove" style="vertical-align:middle;cursor:pointer" onclick="this.parentElement.firstElementChild.value=\'\'"></i>';
        }
        $result = <<<EOT
<{$this->wrapper} class="date" data-date="{$this->default}" data-date-format="{$this->js_format}">
\t<input type="text" id="{$this->id}" value="{$this->value}" name="{$this->name}"
\t\tclass="uneditable-input input-small {$this->class}" type="text"
\t\tstyle="vertical-align:middle;text-align:center;{$this->style}" disabled>
\t<i class="icon-calendar add-on" style="vertical-align:middle;cursor:pointer"></i>
\t{$clear}
\t{$messages}
</{$this->wrapper}>
EOT;
        return $result;
    }
Example #5
0
 public function render($content)
 {
     if ($content instanceof Closure) {
         ob_start();
         $content($this);
         $options = ob_get_clean();
     } elseif (is_array($content)) {
         $options = '';
         foreach ($content as $option) {
             if (is_array($option)) {
                 if (isset($option['text'])) {
                     $text = $option['text'];
                     $value = isset($option['value']) ? $option['value'] : $text;
                 } else {
                     throw new ApplicationError('Select option must specify in the array at' . ' least a "text" key and optionally a "value" key');
                 }
             } elseif ($option instanceof Model) {
                 if (isset($this->text)) {
                     $text = $option->{$this->text}();
                     $value = isset($this->value) ? $option->{$this->value}() : $option->id();
                 } else {
                     throw new ApplicationError('Select option must specify which field' . ' in Model that contains the text');
                 }
             } else {
                 throw new ApplicationError('Select options must be a Model or an array');
             }
             $params = $this->params();
             $selected = isset($params['selected']) && $params['selected'] == $value;
             $options .= $this->option($text, $value, $selected);
         }
     }
     unset($this->text, $this->value);
     $result = "<select {$this->getAttributes()}>{$options}</select>";
     $alerts = AlertManager::byField($this->name);
     foreach ($alerts as $alert) {
         $result .= $alert->render();
     }
     return $result;
 }
Example #6
0
 /**
  * Test the validity of a model
  * @final
  * @param Cognosys\Model $model
  * @return bool
  */
 protected final function valid(Model $model)
 {
     $model->validate();
     $errors = Validator::get();
     AlertManager::import($errors);
     $metadata = $this->getClassMetadata(get_class($model));
     foreach ($metadata->associationMappings as $assoc) {
         $method = TextUtil::camelize($assoc['fieldName']);
         if (is_numeric($model->{$method}()) && $model->{$method}() > 0) {
             // transform the identifier to the entity
             $model->{$method}($this->getReference($assoc['targetEntity'], $model->{$method}()));
             $this->persist($model->{$method}());
         }
     }
     return empty($errors);
 }