Пример #1
0
 /**
  * For checking the photo specific limits
  *
  * @param  array       info about the photo that needs to be added
  *
  * @return bool|string either true if all the tests passed or throws exception
  */
 protected function verify_limits($data)
 {
     parent::verify_limits($data);
     $usercontext = vB::getUserContext();
     $albumChannelId = $this->nodeApi->fetchAlbumChannel();
     $parentData = vB_Api::instance('node')->getNode($data['parentid']);
     // These check are only valid when posting to the album channel
     if ($albumChannelId == $parentData['parentid']) {
         if (empty($data['options']['isnewgallery'])) {
             $albummaxpics = $usercontext->getLimit('albummaxpics');
             if ($albummaxpics > 0) {
                 $numalbumpics = $this->assertor->getField('vBForum:getNumberAlbumPhotos', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'albumid' => $data['parentid'], 'contenttypeid' => vB_Types::instance()->getContentTypeID($this->contenttype)));
                 $overcount = $numalbumpics + 1 - $albummaxpics;
                 if ($overcount > 0) {
                     throw new vB_Exception_Api('upload_album_pics_countfull_x', array($overcount));
                 }
             }
         }
         $albummaxsize = $usercontext->getLimit('albummaxsize');
         if ($albummaxsize) {
             $totalsize = $this->assertor->getField('vBForum:getUserPhotosSize', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'channelid' => $albumChannelId, 'userid' => $data['userid'], 'contenttypeid' => $photoType = vB_Types::instance()->getContentTypeID($this->contenttype)));
             $filedata = vB::getDbAssertor()->getRow('filedata', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_SELECT, 'filedataid' => $data['filedataid']));
             $newsize = $filedata['filesize'] + $totalsize;
             $size_overage = $newsize - $albummaxsize;
             if ($size_overage > 0) {
                 throw new vB_Exception_Api('upload_album_sizefull', array($size_overage));
             }
         }
     } else {
         // Channel  permission for allowed attachemtns per node
         $maxattachments = vB::getUserContext()->getChannelLimitPermission('forumpermissions', 'maxattachments', $parentData['parentid']);
         // Check max allowed attachments per post
         if ($maxattachments) {
             $numpostPhotos = $this->assertor->getField('vBForum:getNumberPosthotos', array(vB_dB_Query::TYPE_KEY => vB_dB_Query::QUERY_STORED, 'nodeid' => $data['parentid'], 'contenttypeid' => vB_Types::instance()->getContentTypeID($this->contenttype)));
             $overcount = $numpostPhotos + 1 - $maxattachments;
             if ($overcount > 0) {
                 throw new vB_Exception_Api('you_may_only_attach_x_files_per_post', array($maxattachments));
             }
         }
     }
     return true;
 }