HCE Project DC service web UI  0.2
Hierarchical Cluster Engine DC service web UI
 All Classes Namespaces Files Functions Variables Pages
YFormatter.php
Go to the documentation of this file.
1 <?php
2 class YFormatter extends CFormatter {
13  public function formatShortText($value, $shortTextLimit = 100, $defaultValue = '-') {
14  if(strlen($value)>$shortTextLimit) {
15  $a = mb_substr($value,0,$shortTextLimit-3,Yii::app()->charset);
16  $retval=CHtml::tag('span',array('title'=>$value),CHtml::encode($a.'...'));
17  } else {
18  $retval=CHtml::encode($value);
19  }
20  return (!empty($retval) ? $retval : $defaultValue);
21  }
22 
29  public function createLinkForEachUrlInString($urlsString, $splitter = ',') {
30  if (empty($urlsString)) {
31  return '';
32  }
33  $urlsArray = explode($splitter, $urlsString);
34  foreach ($urlsArray as &$url) {
35  $url = CHtml::encode($url);
36  $url = CHtml::link($url, $url);
37  }
38  return implode($splitter, $urlsArray);
39  }
40 
49  public function arrayUrlsToStringUrls($urls, $arrayKey = 'url', $limit = 64, $splitter = ',') {
50  $urlsString = '';
51  if (empty($urls)) {
52  return $urlsString;
53  }
54  foreach ($urls as $url) {
55  $break = false;
56  $url = (!empty($url[$arrayKey]) ? $url[$arrayKey] : $url);
57  $urlsString .= $url . $splitter;
58  $urlsStringLen = mb_strlen($urlsString);
59  if ($urlsStringLen == $limit) {
60  $break = true;
61  } elseif ($urlsStringLen > ($limit + 1)) {
62  $urlsArray = explode($splitter, $urlsString);
63  array_pop($urlsArray);
64  array_pop($urlsArray);
65  $urlsString = implode($splitter, $urlsArray);
66  $break = true;
67  }
68  if ($break) {
69  break;
70  }
71  }
72  if ($break) {
73  $urlsString = YFormatter::createLinkForEachUrlInString($urlsString) . '...';
74  } else {
75  $urlsString = mb_substr($urlsString, 0, (mb_strlen($urlsString) - 1));
76  $urlsString = YFormatter::createLinkForEachUrlInString($urlsString);
77  }
78  return $urlsString;
79  }
80 }