File indexing completed on 2024-05-12 05:58:47

0001 <?php
0002 
0003 /**
0004  *  ocs-webserver
0005  *
0006  *  Copyright 2016 by pling GmbH.
0007  *
0008  *    This file is part of ocs-webserver.
0009  *
0010  *    This program is free software: you can redistribute it and/or modify
0011  *    it under the terms of the GNU Affero General Public License as
0012  *    published by the Free Software Foundation, either version 3 of the
0013  *    License, or (at your option) any later version.
0014  *
0015  *    This program is distributed in the hope that it will be useful,
0016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0018  *    GNU Affero General Public License for more details.
0019  *
0020  *    You should have received a copy of the GNU Affero General Public License
0021  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0022  **/
0023 class Default_Model_ProjectModeration extends Default_Model_DbTable_ProjectModeration
0024 {
0025 
0026 
0027     const M_TYPE_GET_HOT_NEW_STUFF_EXCLUDED = 1;
0028 
0029     public function createModeration($project_id,$project_moderation_type_id, $is_set, $userid,$note)
0030     {              
0031             $sql = '
0032                               SELECT
0033                               p.*
0034                               FROM project_moderation AS p
0035                               WHERE 
0036                               p.project_id = :project_id
0037                               AND p.is_deleted = :is_deleted                             
0038                               and p.project_moderation_type_id = :project_moderation_type_id
0039                       ';
0040             $row = $this->_db->fetchRow($sql, array(
0041                 'project_id'  => $project_id,
0042                 'is_deleted' => 0,
0043                 'project_moderation_type_id'        => $project_moderation_type_id
0044             ));
0045 
0046             if($row!=null)
0047             {                
0048                  $row = $this->generateRowClass($row);
0049                  $updateValues = array(
0050                       'is_deleted'     =>1                                      
0051                   );
0052                
0053                 $this->update($updateValues,  ' project_id=' . $row->project_id .' and project_moderation_type_id='.$row->project_moderation_type_id);
0054 
0055                  $insertValues = array(
0056                     'project_moderation_type_id' =>$row->project_moderation_type_id,
0057                     'project_id' => $row->project_id,                    
0058                     'value' => $is_set,
0059                     'created_by' =>$userid,                                     
0060                     'note' => $note                                      
0061                 );                
0062 
0063                 $this->_db->insert($this->_name, $insertValues);
0064             }else
0065             {                            
0066                   $this->insertModeration($project_moderation_type_id,$project_id, $is_set,$userid,$note);                             
0067             }                         
0068     }
0069 
0070   
0071 
0072     public function getTotalCount($filter)
0073     {
0074         $sql = "select count(1)  as cnt
0075                     FROM project_moderation m
0076                     join project_moderation_type t on m.project_moderation_type_id = t.project_moderation_type_id
0077                     join stat_projects p on m.project_id = p.project_id and p.status=100
0078                     where m.is_deleted= 0  and m.value = 1             
0079         ";
0080         if($filter && $filter['member_id'])
0081         {      
0082            $sql = $sql.' and m.created_by = '.$filter['member_id'];
0083         }
0084         $result = $this->getAdapter()->query($sql, array())->fetchAll();      
0085         return  $result[0]['cnt'];
0086     }
0087 
0088      public function getList($member_id=null, $orderby='created_at desc',$limit = null, $offset  = null)
0089     {            
0090             $sql = "
0091                         SELECT 
0092                        m.*
0093                        ,t.tag_id
0094                        ,t.name as type_name
0095                        , p.title
0096                        , p.count_comments
0097                        , p.count_dislikes
0098                        ,p.count_likes
0099                        ,p.laplace_score
0100                        ,p.image_small
0101                        ,p.version
0102                        ,p.member_id
0103                        ,p.username
0104                        ,p.created_at  as project_created_at
0105                        ,p.changed_at as project_changed_at
0106                        ,p.cat_title
0107                        ,(select username from member mm where mm.member_id = m.created_by) as exclude_member_name                       
0108                        FROM project_moderation m
0109                        join project_moderation_type t on m.project_moderation_type_id = t.project_moderation_type_id
0110                        join stat_projects p on m.project_id = p.project_id and p.status=100
0111                        where m.is_deleted= 0  and m.value = 1                   
0112              ";
0113 
0114              if(isset($member_id) && $member_id!=''){
0115                 $sql = $sql.' and m.created_by = '.$member_id;
0116              }
0117 
0118             
0119 
0120              if(isset($orderby)){
0121                 $sql = $sql.'  order by '.$orderby;
0122              }
0123 
0124              if (isset($limit)) {
0125                  $sql .= ' limit ' . (int)$limit;
0126              }
0127 
0128              if (isset($offset)) {
0129                  $sql .= ' offset ' . (int)$offset;
0130              }
0131              
0132 
0133             $resultSet = $this->getAdapter()->fetchAll($sql);
0134 
0135             $image = new Default_View_Helper_Image();
0136             foreach ($resultSet as &$value) {
0137                $value['image_small']= $image->Image($value['image_small'],array('height' => 120, 'width' => 120));
0138             }
0139             //return$this->generateRowClass($resultSet);;        
0140             return $resultSet;
0141     }  
0142 
0143      public function getMembers()
0144     {            
0145             $sql = "
0146                        SELECT 
0147                            distinct m.created_by as member_id                    
0148                           ,(select username from member mm where mm.member_id = m.created_by) as username
0149                           FROM project_moderation m                       
0150                           join stat_projects p on m.project_id = p.project_id and p.status=100
0151                           where m.is_deleted= 0   and m.value = 1                                                            
0152              ";
0153 
0154             
0155             $resultSet = $this->getAdapter()->fetchAll($sql);
0156 
0157          
0158             //return$this->generateRowClass($resultSet);;        
0159             return $resultSet;
0160     }
0161 
0162     
0163      /**
0164      * @return Zend_Db_Adapter_Abstract
0165      */
0166     public function getAdapter()
0167     {
0168         return Zend_Db_Table::getDefaultAdapter();
0169     }
0170    
0171 }