Example #1
0
 /**
  *
  * @param unknown_type $template
  * @param unknown_type $data
  * @return string
  */
 protected function includeTemplate($template, $data = null)
 {
     $view = new self();
     $view->setTemplate($template);
     $view->copyAll($data);
     return $view->render();
 }
Example #2
0
 /**
  * Process partial render
  */
 public static function process($nodeList, $template)
 {
     $renderer = new self();
     // @todo: use getInstance() ?
     $renderer->addNodes($nodeList);
     $renderer->setTemplate($template);
     return $renderer->render();
 }
 /**
  * @param string $template
  * @param string $title
  * @param int $requiredCols
  * @param null|array|\Traversable $variables
  * @param null $newGroup
  * @return DashboardWidget
  */
 public static function initialize($template, $title, $requiredCols, $variables = null, $newGroup = null)
 {
     Assertion::string($template);
     Assertion::string($title);
     Assertion::integer($requiredCols);
     Assertion::min($requiredCols, 1);
     Assertion::max($requiredCols, 12);
     $options = ['required_cols' => $requiredCols, 'title' => $title, 'new_group' => $newGroup];
     $model = new self($variables, $options);
     $model->setTemplate($template);
     return $model;
 }
Example #4
0
 /**
  * @param array $array
  * @param bool $strict
  * @return Document
  * @throws FromArrayCompilationException
  */
 public static function fromArray(array $array, $strict = true)
 {
     $document = new self();
     if (array_key_exists('collection', $array)) {
         if (!is_array($array['collection'])) {
             throw new ExpectedArrayException('collection', gettype($array['collection']));
         }
         try {
             $document->setCollection(Collection::fromArray($array['collection'], $strict));
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('collection', $e->getMessage());
         }
     }
     if (array_key_exists('error', $array)) {
         if (!is_array($array['error'])) {
             throw new ExpectedArrayException('error', gettype($array['error']));
         }
         try {
             $document->setError(Error::fromArray($array['error']));
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('error', $e->getMessage());
         }
     }
     if (array_key_exists('template', $array)) {
         if (!is_array($array['template'])) {
             throw new ExpectedArrayException('template', gettype($array['template']));
         }
         try {
             $document->setTemplate(Template::fromArray($array['template'], $strict));
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('template', $e->getMessage());
         }
     }
     if (array_key_exists('queries', $array)) {
         if (!is_array($array['queries'])) {
             throw new ExpectedArrayException('queries', gettype($array['queries']));
         }
         try {
             foreach ($array['queries'] as $key => $queryArray) {
                 if (!is_array($queryArray)) {
                     throw new ExpectedArrayException($key, gettype($queryArray));
                 }
                 try {
                     $document->getQueries()->add(Query::fromArray($queryArray, $strict));
                 } catch (FromArrayCompilationException $e) {
                     throw new FromArrayCompilationException($key, $e->getMessage());
                 }
             }
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('queries', $e->getMessage());
         }
     }
     return $document;
 }
Example #5
0
 /** @return Am_Mail_Template */
 static function createFromEmailTemplate(EmailTemplate $et)
 {
     $t = new self();
     $t->setTemplate($et->format, $et->subject, $et->plain_txt, $et->txt, $et->attachments, $et->email_template_id . '-' . $et->name . '-' . $et->lang, $et->name, $et->getLayout());
     $t->admins = array_filter(explode(',', $et->recipient_admins));
     $rec = Am_Mail_TemplateTypes::getInstance()->find($et->name);
     if ($rec) {
         $t->setMailPeriodic($rec['mailPeriodic']);
     }
     $bcc = $et->bcc ? array_map('trim', explode(',', $et->bcc)) : array();
     if ($bcc) {
         $t->getMail()->addBcc($bcc);
     }
     if ($et->reply_to && ($admin = $et->getDi()->adminTable->load($et->reply_to, false))) {
         $t->getMail()->setReplyTo($admin->email, $admin->getName());
     }
     return $t;
 }
Example #6
0
 /**
  * Create a new template instance using path and extension from current instance
  *
  * @param string  $template   Template name
  * @param array   $variables  Template variables
  *
  * @return $this
  */
 public function template($template, $variables = [])
 {
     $instance = new self();
     $instance->setPath($this->path);
     $instance->setExtension($this->extension);
     $instance->setTemplate($template);
     $instance->setVariables($variables);
     return $instance;
 }
Example #7
0
 /**
  * @param array $array
  * @param bool $strict
  * @return Collection
  * @throws FromArrayCompilationException
  */
 public static function fromArray(array $array, $strict = true)
 {
     $href = '';
     $version = '1.0';
     if (array_key_exists('href', $array)) {
         $href = $array['href'];
     } elseif ($strict) {
         throw new MissingArgumentException('href');
     }
     if (array_key_exists('version', $array)) {
         $version = $array['version'];
     }
     $collection = new self($href, $version);
     if (array_key_exists('links', $array)) {
         if (!is_array($array['links'])) {
             throw new ExpectedArrayException('links', gettype($array['links']));
         }
         try {
             foreach ($array['links'] as $key => $linkArray) {
                 if (!is_array($linkArray)) {
                     throw new ExpectedArrayException($key, gettype($linkArray));
                 }
                 try {
                     $collection->getLinks()->add(Link::fromArray($linkArray, $strict));
                 } catch (FromArrayCompilationException $e) {
                     throw new FromArrayCompilationException($key, $e->getMessage());
                 }
             }
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('links', $e->getMessage());
         }
     }
     if (array_key_exists('items', $array)) {
         if (!is_array($array['items'])) {
             throw new ExpectedArrayException('items', gettype($array['items']));
         }
         try {
             foreach ($array['items'] as $key => $itemArray) {
                 if (!is_array($itemArray)) {
                     throw new ExpectedArrayException($key, gettype($itemArray));
                 }
                 try {
                     $collection->getItems()->add(Item::fromArray($itemArray, $strict));
                 } catch (FromArrayCompilationException $e) {
                     throw new FromArrayCompilationException($key, $e->getMessage());
                 }
             }
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('items', $e->getMessage());
         }
     }
     if (array_key_exists('queries', $array)) {
         if (!is_array($array['queries'])) {
             throw new ExpectedArrayException('queries', gettype($array['queries']));
         }
         try {
             foreach ($array['queries'] as $key => $queryArray) {
                 if (!is_array($queryArray)) {
                     throw new ExpectedArrayException($key, gettype($queryArray));
                 }
                 try {
                     $collection->getQueries()->add(Query::fromArray($queryArray, $strict));
                 } catch (FromArrayCompilationException $e) {
                     throw new FromArrayCompilationException($key, $e->getMessage());
                 }
             }
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('queries', $e->getMessage());
         }
     }
     if (array_key_exists('template', $array)) {
         if (!is_array($array['template'])) {
             throw new ExpectedArrayException('template', gettype($array['template']));
         }
         try {
             $collection->setTemplate(Template::fromArray($array['template'], $strict));
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('template', $e->getMessage());
         }
     }
     if (array_key_exists('error', $array)) {
         if (!is_array($array['error'])) {
             throw new ExpectedArrayException('error', gettype($array['error']));
         }
         try {
             $collection->setError(Error::fromArray($array['error']));
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('error', $e->getMessage());
         }
     }
     if (array_key_exists('paging', $array)) {
         if (!is_array($array['paging'])) {
             throw new ExpectedArrayException('paging', gettype($array['paging']));
         }
         try {
             $collection->setPaging(Paging::fromArray($array['paging'], $strict));
         } catch (FromArrayCompilationException $e) {
             throw new FromArrayCompilationException('paging', $e->getMessage());
         }
     }
     return $collection;
 }
Example #8
0
 /** @return Am_Mail_Template */
 static function createFromEmailTemplate(EmailTemplate $et)
 {
     $t = new self();
     $t->setTemplate($et->format, $et->subject, $et->plain_txt, $et->txt, $et->attachments, $et->email_template_id . '-' . $et->name . '-' . $et->lang, $et->name);
     $t->admins = $et->recipient_admins;
     $rec = Am_Mail_TemplateTypes::getInstance()->find($et->name);
     if ($rec) {
         $t->setMailPeriodic($rec['mailPeriodic']);
     }
     $bcc = $et->bcc ? array_map('trim', explode(',', $et->bcc)) : array();
     if ($bcc) {
         $t->getMail()->addBcc($bcc);
     }
     return $t;
 }
Example #9
0
 /**
  * @param Template|string $template
  * @param array $data
  * @return Response
  */
 public static function template($template, $data = array())
 {
     $in = new self();
     if (!$template instanceof Template) {
         $template = new Template($template);
     }
     foreach ($data as $k => $v) {
         $template->set($k, $v);
     }
     $in->setTemplate($template);
     return $in;
 }
Example #10
0
 /** @return Am_Mail_Template */
 static function createFromEmailTemplate(EmailTemplate $et)
 {
     $t = new self();
     $t->setTemplate($et->format, $et->subject, $et->plain_txt, $et->txt, $et->attachments, $et->email_template_id . '-' . $et->name . '-' . $et->lang);
     $rec = Am_Mail_TemplateTypes::getInstance()->find($et->name);
     if ($rec) {
         $t->setMailPeriodic($rec['mailPeriodic']);
     }
     return $t;
 }