Since: 2.2.0
Author: Henry Ruhs
Author: Sven Weingartner
Inheritance: implements Redaxscript\Validator\ValidatorInterface
 /**
  * testAccess
  *
  * @since 2.2.0
  *
  * @param string $access
  * @param string $groups
  * @param integer $expect
  *
  * @dataProvider providerAccess
  */
 public function testAccess($access = null, $groups = null, $expect = null)
 {
     /* setup */
     $validator = new Validator\Access();
     /* actual */
     $actual = $validator->validate($access, $groups);
     /* compare */
     $this->assertEquals($expect, $actual);
 }
 /**
  * render
  *
  * @since 2.2.0
  *
  * @return string
  */
 public static function render()
 {
     $output = null;
     $outputItem = null;
     /* html elements */
     $titleElement = new Html\Element();
     $titleElement->init('h3', array('class' => self::$_config['className']['title']));
     $linkElement = new Html\Element();
     $linkElement->init('a');
     $listElement = new Html\Element();
     $listElement->init('ul', array('class' => self::$_config['className']['list']));
     /* fetch articles */
     $articles = Db::forTablePrefix('articles')->where('status', 1)->whereIn('language', array(Registry::get('language'), ''))->orderByDesc('category')->findArray();
     /* process articles */
     if (!$articles) {
         $error = Language::get('article_no') . Language::get('point');
     } else {
         $accessValidator = new Validator\Access();
         $accessDeny = 0;
         $lastCategory = 0;
         foreach ($articles as $value) {
             if ($accessValidator->validate($value['access'], Registry::get('myGroups')) === Validator\ValidatorInterface::PASSED) {
                 $currentCategory = $value['category'];
                 /* collect output */
                 if ($lastCategory != $currentCategory) {
                     if ($lastCategory > 0) {
                         $output .= $listElement->html($outputItem);
                         $outputItem = null;
                     }
                     $output .= $titleElement->text($currentCategory < 1 ? Language::get('uncategorized') : Db::forTablePrefix('categories')->whereIdIs($currentCategory)->findOne()->title);
                 }
                 /* collect item output */
                 $outputItem .= '<li>';
                 $outputItem .= $linkElement->attr(array('href' => $value['category'] < 1 ? $value['alias'] : build_route('articles', $value['id']), 'title' => $value['description'] ? $value['description'] : $value['title']))->text($value['title']);
                 $outputItem .= '</li>';
                 /* collect list output */
                 if (end($articles) === $value) {
                     $output .= $listElement->html($outputItem);
                     $outputItem = null;
                 }
                 $lastCategory = $currentCategory;
             } else {
                 $accessDeny++;
             }
         }
         /* handle access */
         if (count($articles) === $accessDeny) {
             $error = Language::get('access_no') . Language::get('point');
         }
     }
     /* handle error */
     if ($error) {
         $output = $listElement->html('<li>' . $error . '</li>');
     }
     return $output;
 }
 /**
  * render
  *
  * @since 2.2.0
  *
  * @return string
  */
 public static function render()
 {
     $output = '';
     $outputItem = '';
     /* html elements */
     $titleElement = new Element('h3', array('class' => self::$_config['className']['title']));
     $linkElement = new Element('a');
     $listElement = new Element('ul', array('class' => self::$_config['className']['list']));
     /* fetch articles */
     $articles = Db::forTablePrefix('articles')->selectExpr('*, YEAR(date) as year, MONTH(date) as month')->where('status', 1)->whereIn('language', array(Registry::get('language'), ''))->orderByDesc('date')->findArray();
     /* process articles */
     if (empty($articles)) {
         $error = Language::get('article_no') . Language::get('point');
     } else {
         $accessValidator = new Validator\Access();
         $accessDeny = 0;
         $lastDate = 0;
         foreach ($articles as $value) {
             if ($accessValidator->validate($value['access'], Registry::get('myGroups')) === Validator\ValidatorInterface::PASSED) {
                 $currentDate = $value['month'] + $value['year'];
                 /* collect output */
                 if ($lastDate != $currentDate) {
                     if ($lastDate > 0) {
                         $output .= $listElement->html($outputItem);
                         $outputItem = '';
                     }
                     $output .= $titleElement->text(Language::get($value['month'] - 1, '_month') . ' ' . $value['year']);
                 }
                 /* collect item output */
                 $outputItem .= '<li>';
                 $outputItem .= $linkElement->attr(array('href' => $value['category'] < 1 ? $value['alias'] : build_route('articles', $value['id']), 'title' => $value['description'] ? $value['description'] : $value['title']))->text($value['title']);
                 $outputItem .= '</li>';
                 /* collect list output */
                 if (end($articles) === $value) {
                     $output .= $listElement->html($outputItem);
                     $outputItem = '';
                 }
                 $lastDate = $currentDate;
             } else {
                 $accessDeny++;
             }
         }
         /* handle access */
         if (count($articles) === $accessDeny) {
             $error = Language::get('access_no') . Language::get('point');
         }
     }
     /* handle error */
     if ($error) {
         $output = $listElement->html('<li>' . $error . '</li>');
     }
     return $output;
 }
Exemple #4
0
 /**
  * render
  *
  * @since 2.2.0
  *
  * @return string
  */
 public static function render()
 {
     $output = null;
     /* html elements */
     $titleElement = new Html\Element();
     $titleElement->init('h3', ['class' => self::$_configArray['className']['title']]);
     $linkElement = new Html\Element();
     $linkElement->init('a');
     $listElement = new Html\Element();
     $listElement->init('ul', ['class' => self::$_configArray['className']['list']]);
     /* query articles */
     $articles = Db::forTablePrefix('articles')->where('status', 1)->whereLanguageIs(Registry::get('language'))->orderByDesc('date')->findMany();
     /* process articles */
     if (!$articles) {
         $error = Language::get('article_no') . Language::get('point');
     } else {
         $accessValidator = new Validator\Access();
         $accessDeny = 0;
         $lastDate = 0;
         foreach ($articles as $value) {
             if ($accessValidator->validate($value->access, Registry::get('myGroups')) === Validator\ValidatorInterface::PASSED) {
                 $month = date('n', strtotime($value->date));
                 $year = date('Y', strtotime($value->date));
                 $currentDate = $month + $year;
                 /* collect output */
                 if ($lastDate != $currentDate) {
                     $output .= $titleElement->text(Language::get($month - 1, '_month') . ' ' . $year);
                 }
                 $lastDate = $currentDate;
                 /* collect item output */
                 $outputItem = '<li>';
                 $outputItem .= $linkElement->attr(['href' => Registry::get('parameterRoute') . build_route('articles', $value->id), 'title' => $value->description ? $value->description : $value->title])->text($value->title);
                 $outputItem .= '</li>';
                 /* collect list output */
                 $output .= $listElement->html($outputItem);
             } else {
                 $accessDeny++;
             }
         }
         /* handle access */
         if (count($articles) === $accessDeny) {
             $error = Language::get('access_no') . Language::get('point');
         }
     }
     /* handle error */
     if ($error) {
         $output = $listElement->html('<li>' . $error . '</li>');
     }
     return $output;
 }
 /**
  * render the view
  *
  * @since 3.0.0
  *
  * @param array $resultArray array for the result
  *
  * @return string
  */
 public function render($resultArray = [])
 {
     $output = Hook::trigger('resultListStart');
     $accessValidator = new Validator\Access();
     /* html elements */
     $titleElement = new Html\Element();
     $titleElement->init('h2', ['class' => 'rs-title-result']);
     $listElement = new Html\Element();
     $listElement->init('ol', ['class' => 'rs-list-result']);
     $itemElement = new Html\Element();
     $itemElement->init('li');
     $linkElement = new Html\Element();
     $linkElement->init('a', ['class' => 'rs-link-result']);
     $textElement = new Html\Element();
     $textElement->init('span', ['class' => 'rs-text-result-date']);
     /* process result */
     foreach ($resultArray as $table => $result) {
         $outputItem = null;
         if ($result) {
             /* collect item output */
             foreach ($result as $value) {
                 if ($accessValidator->validate($result->access, $this->_registry->get('myGroups')) === Validator\ValidatorInterface::PASSED) {
                     $textDate = date(Db::getSetting('date'), strtotime($value->date));
                     $linkElement->attr('href', $this->_registry->get('parameterRoute') . build_route($table, $value->id))->text($value->title ? $value->title : $value->author);
                     $textElement->text($textDate);
                     $outputItem .= $itemElement->html($linkElement . $textElement);
                 }
             }
             /* collect output */
             if ($outputItem) {
                 $titleElement->text($this->_language->get($table));
                 $listElement->html($outputItem);
                 $output .= $titleElement . $listElement;
             }
         }
     }
     $output .= Hook::trigger('resultListEnd');
     return $output;
 }