/**
  * 
  * 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;
 }
Beispiel #2
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;
 }