/**
  * 
  * Creating a report footer
  * 
  * @param array $modelFooter  // array params 
  * keys:
  * - 'footer_colspan' (joint number of columns in the table)
  * - 'rows' (an array of values for the report records)
  * - 'column_model' (parameters of table columns)
  * - 'footers' (options footer, key - the column name value - an act or expression of a text)
  *
  * @return array
  */
 protected function _footerForReport($modelFooter)
 {
     $resultActions = array('count', 'sum', 'max', 'min', 'average');
     $rows_footer = array();
     $row_footer = array();
     $footer_colspan = $modelFooter['footer_colspan'];
     $rows = $modelFooter['rows'];
     $column_model = $modelFooter['column_model'];
     $footers = $modelFooter['footers'];
     $index = 0;
     //-----------------------------------------------------
     foreach ($footers as $footer) {
         foreach ($column_model as $key => $column) {
             if (isset($footer[$key])) {
                 $footer_value = $footer[$key];
                 if (in_array($footer_value, $resultActions)) {
                     $ArrayBox = new Default_Plugin_ArrayBox($rows);
                     $arrValues = $ArrayBox->slice($key);
                     switch ($footer_value) {
                         case 'count':
                             $row_footer[$index] = $arrValues->count();
                             break;
                         case 'sum':
                             $row_footer[$index] = $arrValues->sum();
                             break;
                         case 'max':
                             $arrResult = $arrValues->max();
                             $row_footer[$index] = $arrResult['value'];
                             break;
                         case 'min':
                             $arrResult = $arrValues->min();
                             $row_footer[$index] = $arrResult['value'];
                             break;
                         case 'average':
                             $row_footer[$index] = $arrValues->avg();
                             break;
                         default:
                             break;
                     }
                 } else {
                     $row_footer[$index] = $footer[$key];
                 }
             } else {
                 if ($footer_colspan > 1) {
                     $footer_colspan = $footer_colspan - 1;
                 } else {
                     $row_footer[$index] = '';
                 }
             }
             $index++;
         }
         $index = 0;
         $rows_footer[] = $row_footer;
     }
     return $rows_footer;
 }
Example #2
0
 /**
  * Get text markdown markup file
  * file is selected according to the localization
  * 
  * @param array $params Set params for [filename, content, type]
  * @return string
  */
 public function getMarkdown($params)
 {
     $arBox = new Default_Plugin_ArrayBox();
     $strBox = new Default_Plugin_String();
     $filename = isset($params['filename']) ? $params['filename'] : '';
     $strFile = isset($params['content']) ? $params['content'] : '';
     $type = isset($params['type']) ? $params['type'] : 'github';
     //Type of Markdown: traditional, github, extra
     $title = '';
     $locale = Default_Plugin_SysBox::getTranslateLocale();
     $locale = $locale == 'uk' ? 'ru' : $locale;
     $title = "";
     $filename = trim($filename);
     $filename = str_replace('\\', '/', $filename);
     //-------------------------------------------
     if ($filename) {
         if (is_file($filename)) {
             $lastFilename = $arBox->set($filename, "/")->getLast();
             // Set title
             $title = $lastFilename;
             // Check word in uppercase
             $upperFilename = $strBox->set($lastFilename)->toUpper()->get();
             $isUpper = $arBox->set($lastFilename, ".")->get(0) == $arBox->set($upperFilename, ".")->get(0);
             if ($isUpper) {
                 $locale = strtoupper($locale);
             }
             // Get the name of the file to a different locale
             $lastFilename = $arBox->set($lastFilename, ".")->get(0) . "-{$locale}.md";
             $localeFilename = $arBox->set($filename, "/")->pop()->join('/') . "/{$lastFilename}";
             // Get file content
             if (is_file($localeFilename)) {
                 // Set title
                 $title = $lastFilename;
                 $strFile = file_get_contents($localeFilename);
             } else {
                 $strFile = file_get_contents($filename);
             }
         } else {
             // Get file name
             $filename = APPLICATION_TEMPLATES . "/{$this->_params['controller']}/{$filename}";
             if (!is_file($filename)) {
                 throw new Exception("File '{$filename}' does not exist.");
             }
             $lastFilename = $arBox->set($filename, "/")->getLast();
             // Set title
             $title = $lastFilename;
             // Check word in uppercase
             $upperFilename = $strBox->set($lastFilename)->toUpper()->get();
             $isUpper = $arBox->set($lastFilename, ".")->get(0) == $arBox->set($upperFilename, ".")->get(0);
             if ($isUpper) {
                 $locale = strtoupper($locale);
             }
             // Get the name of the file to a different locale
             $lastFilename = $arBox->set($lastFilename, ".")->get(0) . "-{$locale}.md";
             $localeFilename = $arBox->set($filename, "/")->pop()->join('/') . "/{$lastFilename}";
             // Get file content
             if (is_file($localeFilename)) {
                 // Set title
                 $title = $lastFilename;
                 $strFile = file_get_contents($localeFilename);
             } else {
                 $strFile = file_get_contents($filename);
             }
         }
     }
     switch ($type) {
         case 'traditional':
             $markdown = new \cebe\markdown\Markdown();
             break;
         case 'github':
             $markdown = new \cebe\markdown\GithubMarkdown();
             break;
         case 'extra':
             $markdown = new \cebe\markdown\MarkdownExtra();
             break;
         default:
             break;
     }
     // Get markdown parser text
     $text = $markdown->parse($strFile);
     // Get content
     $content = array('title' => $title, 'text' => "<div class=\"markdown-body\">{$text}</div>");
     return $content;
 }
Example #3
0
 /**
  * Get the data to build a tree Comments
  *
  * @param Zend_Db_Adapter_Abstract $db
  * @param int $post_id
  * @return array
  */
 public static function getTreeComments($db, $user_id, $params)
 {
     $sortcomm = array();
     $newComments = array();
     //-----------------------------------------
     // Получим комментарии
     $comments = self::GetComments_Array($db, $params);
     // Получим не повторяющийся массив Ids пользователей
     $arrBox = new Default_Plugin_ArrayBox($comments);
     if ($arrBox->count() == 0) {
         return $sortcomm;
     }
     $arrUser_ids = $arrBox->slice('user_id', TRUE);
     // Добавим в массив Ids пользователей id автора, если его там нет
     if (!$arrUser_ids->isValue($user_id)) {
         $arrUser_ids = $arrUser_ids->push($user_id);
     }
     $arrUser_ids = $arrUser_ids->get();
     // Получим массив пользователей из их Ids
     $options = array('user_id' => $arrUser_ids);
     $users = Default_Model_DbTable_User::GetUsers($db, $options);
     foreach ($comments as $comment) {
         if (isset($comment['user_id']) && isset($users[$comment['user_id']])) {
             $user = $users[$comment['user_id']];
             // Установим имя пользователя
             $comment['username'] = $user->username;
             // Установим дату создания комментария
             $date = new Zend_Date($comment['ts'], 'U');
             $dtFormat = $date->get('dd MMMM YYYY, HH:mm');
             $comment['date'] = $dtFormat;
             // Установим признак авторства
             $isAutor = $user_id == $comment['user_id'];
             $comment['is_autor'] = $isAutor;
             // Установим изображение пользователя
             if ($user->profile->user_img) {
                 $user_img = $user->profile->user_img;
             } else {
                 if ($comment['is_autor']) {
                     $user_img = "/images/system/user_new.png";
                 } else {
                     if ($user->profile->sex) {
                         if ($user->profile->sex == 'male') {
                             $user_img = "/images/system/user_male.png";
                         } else {
                             $user_img = "/images/system/user_female.png";
                         }
                     } else {
                         $user_img = "/images/system/user_message.png";
                     }
                 }
             }
             $comment['user_img'] = $user_img;
             // Установим URL пользователя
             $comment['user_url'] = "/user/{$user->username}";
             // Добавим в новый массив
             $newComments[] = $comment;
         }
     }
     //------ Создадим дерево комментариев ------
     if (count($newComments) > 0) {
         // subcomments
         foreach ($newComments as $item) {
             if ($item['reply_id'] == 0) {
                 $sortcomm[$item['id']]['parent'] = $item;
             }
             if ($item['reply_id'] > 0) {
                 if (isset($path[$item['reply_id']])) {
                     $str = '$sortcomm';
                     foreach ($path[$item['reply_id']] as $pitem) {
                         $rep = $item['reply_id'];
                         $str .= "[{$pitem}][sub]";
                     }
                     $str .= "[{$item['reply_id']}][sub]";
                     $str .= "[{$item['id']}]['parent']";
                     $str .= '=$item;';
                     eval($str);
                     foreach ($path[$item['reply_id']] as $pitem) {
                         $path[$item['id']][] = $pitem;
                     }
                     $path[$item['id']][] = $item['reply_id'];
                 } else {
                     $sortcomm[$item['reply_id']]['sub'][$item['id']]['parent'] = $item;
                     $path[$item['id']][] = $item['reply_id'];
                 }
             }
         }
     }
     return $sortcomm;
 }
Example #4
0
 /**
  * Action - videos
  * Actions with the videos. Get a list of videos.
  *
  * Access to the action is possible in the following paths:
  * router pattern - user/:username/post/:post_id/videos/*
  * 
  * - /user/user1/post/27/videos
  *
  * @return void
  */
 public function videosAction()
 {
     $playlist = array();
     //-----------------------
     // Получим файл конфигурации
     $ini = Zend_Registry::get('config');
     $adapter = $ini['http']['adapter'];
     $proxy_host = $ini['proxy']['host'];
     // Получим обьект запроса
     $request = $this->getRequest();
     $params = $request->getParams();
     $type_action = $params['type_action'];
     $username = trim($request->getUserParam('username'));
     $post_id = (int) $request->getUserParam('post_id');
     if ($type_action == 'playlist') {
         // Получим файлы видео для сообщения
         $videos = Default_Model_DbTable_BlogPostVideo::GetVideo($this->db, array('post_id' => $post_id));
         // Получим список видео данных для статьи
         foreach ($videos as $video) {
             // Получим URL ресурса
             $type = $video->type;
             $arrType = explode('-', $type);
             if ($arrType[0] == 'file') {
                 $url = $video->getFullUrl_Res($username);
             } else {
                 $url = $video->identifier;
             }
             $path = $video->GetUploadPath($username) . '/' . $video->getId() . '.json';
             if (is_file($path)) {
                 $strJson = file_get_contents($path);
                 $strJson = stripslashes($strJson);
                 try {
                     // Получим пути к изобржаениям и флеш для пользователя
                     $pathImages = Default_Model_DbTable_BlogPostImage::GetUploadUrl($username);
                     $pathFlash = Default_Model_DbTable_BlogPostVideo::GetUploadUrlForFlash($username);
                     // Преобразуем Json в PHP массив
                     $itemPlaylist = Zend_Json::decode($strJson);
                     // Изменим данные в массиве
                     $itemPlaylist['clip_id'] = $video->getId();
                     $itemPlaylist['clip_type'] = $video->type;
                     $itemPlaylist['url'] = $url;
                     $itemPlaylist['title'] = $video->name;
                     if (isset($itemPlaylist['cuepoints'])) {
                         $cuepoints = $itemPlaylist['cuepoints'];
                         $newCuepoints = array();
                         foreach ($cuepoints as $cuepoint) {
                             if (isset($cuepoint['image'])) {
                                 $cuepoint['image'] = $this->getUrlRes($pathImages . '/' . ltrim($cuepoint['image'], '/'));
                             }
                             if (isset($cuepoint['flash'])) {
                                 $cuepoint['flash'] = $this->getUrlRes($pathFlash . '/' . ltrim($cuepoint['flash'], '/'));
                             }
                             $newCuepoints[] = $cuepoint;
                         }
                         $itemPlaylist['cuepoints'] = $newCuepoints;
                     }
                 } catch (Exception $exc) {
                     $jsons = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка получения видео') . '</em>', Default_Plugin_SysBox::getMessageError($exc)));
                     $this->sendJson($jsons);
                     return;
                 }
             } else {
                 $itemPlaylist = array();
                 $itemPlaylist['clip_id'] = $video->getId();
                 $itemPlaylist['clip_type'] = $video->type;
                 $itemPlaylist['url'] = $url;
                 $itemPlaylist['title'] = $video->name;
                 $itemPlaylist['description'] = $video->comment;
             }
             $playlist[] = $itemPlaylist;
         }
         if ($this->_isAjaxRequest) {
             $this->sendJson($playlist);
         }
     } elseif ($type_action == 'godtv_url') {
         // Получим параметры клипа
         $clip_name = $params['clip_name'];
         $clip_id = $params['clip_id'];
         // Получим файлы видео для сообщения
         $videos = Default_Model_DbTable_BlogPostVideo::GetVideo($this->db, array('post_id' => $post_id));
         // Найдем нужное видео и обновим "identifier"
         foreach ($videos as $video) {
             if ($video->getId() == $clip_id) {
                 // Получим уникальный URL для фильма
                 $arrBox = new Default_Plugin_ArrayBox();
                 $url_video = $arrBox->set($video->identifier, '/')->getLast();
                 // Получим новый URL для этого видео
                 $new_url = $this->_getGodtvURL($clip_name, $url_video);
                 if ($new_url === FALSE) {
                     $jsons = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка URL') . '</em>', $this->Translate('Ошибка получения URL для видео')));
                     $this->sendJson($jsons);
                     return;
                 }
                 $video->identifier = $new_url;
                 if ($video->save()) {
                     $json = array('url' => $new_url);
                 } else {
                     $json = array('class_message' => 'warning', 'messages' => array('<em>' . $this->Translate('Ошибка при сохранении данных') . '</em>'));
                 }
                 $this->sendJson($json);
                 return;
             }
         }
     } elseif ($type_action == 'play') {
         $json = array('result' => 'OK');
         $this->sendJson($json);
         return;
     }
 }