Example #1
0
 public function updateImage($widgetId, $postData, $currentData)
 {
     // var_dump($postData);
     $var = $postData['varName'];
     $newImg = $postData['fileName'];
     $newCrop = $postData['crop'];
     // do we have old data?
     if (isset($currentData[$var])) {
         $oldImg = $currentData[$var]['fileName'];
         $oldCrop = $currentData[$var]['crop'];
     } else {
         $oldImg = false;
         $oldCrop = false;
     }
     // unbind/bind file
     if ($newImg != $oldImg) {
         if ($oldImg) {
             \Ip\Internal\Repository\Model::unbindFile($oldImg, 'CustomSection', $widgetId);
         }
         \Ip\Internal\Repository\Model::bindFile($newImg, 'CustomSection', $widgetId);
     }
     // handle cropping
     if ($newCrop != $oldCrop) {
         // ????
     }
     $currentData[$var] = array('fileName' => $newImg, 'crop' => $newCrop);
     return $currentData;
 }
Example #2
0
 public function afterUpdate($recordId, $oldData, $newData)
 {
     if (!isset($oldData[$this->field])) {
         $oldData[$this->field] = '';
     }
     if (!isset($newData[$this->field])) {
         $newData[$this->field] = '';
     }
     if (!empty($oldData[$this->field]) && $oldData[$this->field] != $newData[$this->field]) {
         \Ip\Internal\Repository\Model::unbindFile($oldData[$this->field], $this->repositoryBindKey, $recordId);
     }
     if (!empty($newData[$this->field]) && $oldData[$this->field] != $newData[$this->field]) {
         \Ip\Internal\Repository\Model::bindFile($newData[$this->field][0], $this->repositoryBindKey, $recordId);
     }
 }
Example #3
0
 private function _deleteOneImage($image, $widgetId)
 {
     if (!is_array($image)) {
         return;
     }
     if (isset($image['imageOriginal']) && $image['imageOriginal']) {
         \Ip\Internal\Repository\Model::unbindFile($image['imageOriginal'], 'Content', $widgetId);
     }
 }
Example #4
0
 public function delete($widgetId, $data)
 {
     if (!isset($data['files']) || !is_array($data['files'])) {
         return;
     }
     foreach ($data['files'] as $file) {
         if (isset($file['fileName']) && $file['fileName']) {
             \Ip\Internal\Repository\Model::unbindFile($file['fileName'], 'Content', $widgetId);
         }
     }
 }
Example #5
0
/**
 * Release file binding. See ipBindFile for more details.
 *
 * @param string $file file name relative to file/repository/. Eg. 'im-naked-in-the-shower.jpg'
 * @param string $plugin plugin name that uses the asset.
 * @param int $id single plugin might bind to the same file several times. In that case plugin might differentiate those bind by $id.
 * @param string $baseDir by default repository locate files in 'file/repository/'. If you work with 'file/secure/' dir, pass this value here.
 */
function ipUnbindFile($file, $plugin, $id, $baseDir = 'file/repository/')
{
    \Ip\Internal\Repository\Model::unbindFile($file, $plugin, $id, $baseDir);
}
Example #6
0
 /**
  * @param Entity\Image $image
  * @param string $key
  * @param \Ip\Internal\InlineValue\Entity\Scope $scope
  */
 private function removeImageRecord($image, $key, $scope)
 {
     if ($scope) {
         switch ($scope->getType()) {
             case Scope::SCOPE_PAGE:
             case Scope::SCOPE_PARENT_PAGE:
                 $this->dao->deletePageValue(Dao::PREFIX_IMAGE, $key, $scope->getPageId());
                 break;
             case Scope::SCOPE_LANGUAGE:
                 $this->dao->deleteLanguageValue(Dao::PREFIX_IMAGE, $key, $scope->getLanguageId());
                 break;
             case Scope::SCOPE_GLOBAL:
                 $this->dao->deleteGlobalValue(Dao::PREFIX_IMAGE, $key);
                 break;
         }
         if ($image) {
             if ($image->getImageOrig() && is_file(ipFile($image->getImageOrig()))) {
                 \Ip\Internal\Repository\Model::unbindFile($image->getImageOrig(), 'developer/inline_management', $image->getId());
             }
         }
     }
 }