Esempio n. 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;
 }
Esempio n. 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);
     }
 }
Esempio n. 3
0
 /**
  *
  * Duplicate widget action. This function is executed after the widget is being duplicated.
  * All widget data is duplicated automatically. This method is used only in case a widget
  * needs to do some maintenance tasks on duplication.
  * @param int $oldId old widget id
  * @param int $newId duplicated widget id
  * @param array $data data that has been duplicated from old widget to the new one
  * @return array
  */
 public function duplicate($oldId, $newId, $data)
 {
     if (!isset($data['images']) || !is_array($data['images'])) {
         return null;
     }
     foreach ($data['images'] as $image) {
         if (!is_array($image)) {
             return null;
         }
         if (isset($image['imageOriginal']) && $image['imageOriginal']) {
             \Ip\Internal\Repository\Model::bindFile($image['imageOriginal'], 'Content', $newId);
         }
     }
     return $data;
 }
Esempio n. 4
0
 /**
  *
  * Duplicate widget action. This function is executed after the widget is being duplicated.
  * All widget data is duplicated automatically. This method is used only in case a widget
  * needs to do some maintenance tasks on duplication.
  * @param int $oldId old widget id
  * @param int $newId duplicated widget id
  * @param array $data data that has been duplicated from old widget to the new one
  * @return array
  */
 public function duplicate($oldId, $newId, $data)
 {
     if (!is_array($data)) {
         return $data;
     }
     if (isset($data['imageOriginal']) && $data['imageOriginal']) {
         \Ip\Internal\Repository\Model::bindFile($data['imageOriginal'], 'Content', $newId);
     }
     return $data;
 }
Esempio n. 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);
}
Esempio n. 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());
             }
         }
     }
 }