Beispiel #1
0
 function __construct($data)
 {
     $languageProxy = __ObjectFactory::createObject('org.glizycms.languages.models.proxy.LanguagesProxy');
     $index = null;
     if (is_array($data[self::DOCUMENT_DETAIL_STATUS])) {
         $index = array_search('PUBLISHED', $data[self::DOCUMENT_DETAIL_STATUS]);
         $this->hasPublishedVersion = $index !== FALSE;
         $indexDraft = array_search('DRAFT', $data[self::DOCUMENT_DETAIL_STATUS]);
         $this->hasDraftVersion = $indexDraft !== FALSE;
         if (!$this->hasPublishedVersion) {
             $index = $indexDraft;
         }
     }
     if ($index && $data['document_detail_FK_language_id'][$index] != $languageProxy->getLanguageId()) {
         $data['document_detail_FK_language_id'][$index] = $languageProxy->getLanguageId();
         $data['document_detail_translated'][$index] = 0;
     }
     foreach ($data as $k => $v) {
         if (is_array($v)) {
             $this->data[$k] = $v[$index];
         } else {
             $this->data[$k] = $v;
         }
     }
 }
 protected function initQueryBuilder()
 {
     if ($this->options['type'] == 'PUBLISHED_DRAFT') {
         $options = array('type' => 'PUBLISHED_DRAFT', 'tableAlias' => self::DOCUMENT_TABLE_ALIAS, 'tableDetailPublishedAlias' => self::DOCUMENT_DETAIL_TABLE_PUBLISHED_ALIAS, 'tableDetailDraftAlias' => self::DOCUMENT_DETAIL_TABLE_DRAFT_ALIAS);
         $this->qb = $this->ar->createQueryBuilder($options);
         $languageProxy = __ObjectFactory::createObject('org.glizycms.languages.models.proxy.LanguagesProxy');
         $defaultLanguageId = $languageProxy->getDefaultLanguageId();
         if ($defaultLanguageId != $this->ar->getLanguageId()) {
             $this->qb->select(self::DOCUMENT_TABLE_ALIAS . '.*', self::DOCUMENT_DETAIL_TABLE_PUBLISHED_ALIAS . '.*', self::DOCUMENT_DETAIL_TABLE_DRAFT_ALIAS . '.*', self::DOCUMENT_DETAIL_TABLE_PUBLISHED_ALIAS . '_defaultLanguage.*', self::DOCUMENT_DETAIL_TABLE_DRAFT_ALIAS . '_defaultLanguage.*');
         } else {
             $this->qb->select(self::DOCUMENT_TABLE_ALIAS . '.*', self::DOCUMENT_DETAIL_TABLE_PUBLISHED_ALIAS . '.*', self::DOCUMENT_DETAIL_TABLE_DRAFT_ALIAS . '.*');
         }
         $this->statusSet = true;
         $this->languageSet = true;
     } else {
         $options = array('type' => 'PUBLISHED', 'tableAlias' => self::DOCUMENT_TABLE_ALIAS, 'tableDetailAlias' => self::DOCUMENT_DETAIL_TABLE_ALIAS);
         $this->qb = $this->ar->createQueryBuilder($options);
         $this->qb->select(self::DOCUMENT_TABLE_ALIAS . '.*', self::DOCUMENT_DETAIL_TABLE_ALIAS . '.*');
         $this->statusSet = false;
         $this->languageSet = false;
     }
     $this->hasSelect = true;
     $this->hasLimit = false;
     $this->typeSet = false;
     $this->visibilitySet = false;
     $this->conditionsMap = array();
 }
Beispiel #3
0
 /**
  * Read the content for a menu
  *
  * NOTA: per velocizzare non viene controllato se il menù esiste
  * quindi se il menù non esiste oppure se non ci sono contenuti
  * ritorna un oggetto nullo
  *
  * @param  int  $menuId     Menu id
  * @param  int  $languageId Language id
  * @return org_glizycms_contents_models_Content   Content
  */
 public function readRawContentFromMenu($menuId, $languageId)
 {
     $it = org_glizy_objectFactory::createModelIterator('org.glizycms.core.models.Content');
     $it->setOptions(array('type' => 'PUBLISHED_DRAFT'));
     $menuDocument = $it->where('id', $menuId)->first();
     if (!$menuDocument) {
         $languageProxy = __ObjectFactory::createObject('org.glizycms.languages.models.proxy.LanguagesProxy');
         $it = org_glizy_objectFactory::createModelIterator('org.glizycms.core.models.Content')->setOptions(array('type' => 'PUBLISHED_DRAFT'))->whereLanguageIs($languageProxy->getDefaultLanguageId())->where('id', $menuId);
         $menuDocument = $it->first(true);
     }
     return $menuDocument;
 }
 public function saveContent($data, $publish = true)
 {
     $recordId = $data->__id;
     $model = $data->__model;
     $document = org_glizy_objectFactory::createModel($model);
     $result = $document->load($recordId, 'LAST_MODIFIED');
     if (!$result) {
         $languageProxy = __ObjectFactory::createObject('org.glizycms.languages.models.proxy.LanguagesProxy');
         $defaultLanguageId = $languageProxy->getDefaultLanguageId();
         $document->load($recordId, 'LAST_MODIFIED', $defaultLanguageId);
         $document->setLanguage($languageProxy->getLanguageId());
     }
     if (property_exists($data, 'title')) {
         $document->title = $data->title;
     }
     if (property_exists($data, 'url')) {
         $document->url = $data->url;
     }
     $document->fulltext = org_glizycms_core_helpers_Fulltext::make($data, $document, true);
     try {
         if ($publish) {
             $id = $document->publish();
         } else {
             if (__Config::get('glizycms.content.history')) {
                 $id = $document->saveHistory();
             } else {
                 $id = $document->save();
             }
         }
         if (__Config::get('ACL_MODULES')) {
             // gestione acl record
             $ar = org_glizy_objectFactory::createModel('org.glizycms.contents.models.DocumentACL');
             $ar->load($id);
             $ar->__aclEdit = $data->__aclEdit;
             $ar->__aclView = $data->__aclView;
             $ar->save();
         }
     } catch (org_glizy_validators_ValidationException $e) {
         return $e->getErrors();
     }
     return array('__id' => $id);
 }
 public function createQueryBuilder($options)
 {
     $qb = $this->connection->createQueryBuilder();
     if ($options['type'] == 'PUBLISHED') {
         $tableAlias = self::DOCUMENT_TABLE_ALIAS;
         $tableDetailAlias = self::DOCUMENT_DETAIL_TABLE_ALIAS;
         $qb->from($this->getDocumentTableName(), $tableAlias)->join($tableAlias, $this->getDocumentDetailTableName(), $tableDetailAlias, $qb->expr()->eq($tableAlias . '.' . self::DOCUMENT_ID, $tableDetailAlias . '.' . self::DOCUMENT_DETAIL_FK_DOCUMENT));
     } else {
         if ($options['type'] == 'PUBLISHED_DRAFT') {
             $tableAlias = $options['tableAlias'];
             $tableDetailPublishedAlias = $options['tableDetailPublishedAlias'];
             $tableDetailDraftAlias = $options['tableDetailDraftAlias'];
             $this->queryBuilderJoinDetail($qb, $tableAlias, $tableDetailPublishedAlias, self::STATUS_PUBLISHED, ':language');
             $this->queryBuilderJoinDetail($qb, $tableAlias, $tableDetailDraftAlias, self::STATUS_DRAFT, ':language');
             $qb->setParameter(':language', $this->getLanguageId());
             $languageProxy = __ObjectFactory::createObject('org.glizycms.languages.models.proxy.LanguagesProxy');
             $defaultLanguageId = $languageProxy->getDefaultLanguageId();
             if ($defaultLanguageId != $this->getLanguageId()) {
                 $this->queryBuilderJoinDetail($qb, $tableAlias, $tableDetailPublishedAlias . '_defaultLanguage', self::STATUS_PUBLISHED, ':defaultLanguage');
                 $this->queryBuilderJoinDetail($qb, $tableAlias, $tableDetailDraftAlias . '_defaultLanguage', self::STATUS_DRAFT, ':defaultLanguage');
                 $qb->setParameter(':defaultLanguage', $defaultLanguageId);
             }
         }
     }
     return $qb;
 }
Beispiel #6
0
 /**
  * @return GlizyObject|mixed|null|StdClass
  */
 public function &current()
 {
     if ($this->data == NULL) {
         $this->rewind();
     }
     // se non ci sono record
     if ($this->EOF) {
         return null;
     }
     if (!$this->returnClass) {
         $r = new StdClass();
         foreach ($this->data as $k => $v) {
             $r->{$k} = $v;
         }
     } else {
         $r = __ObjectFactory::createObject($this->returnClass, $this->data);
     }
     return $r;
 }
Beispiel #7
0
 function _render_html()
 {
     if (!empty($this->mediaUrl)) {
         $attributes = $this->_content;
         if (is_string($this->mediaUrl) && (!is_null($this->getAttribute('width')) || !is_null($this->getAttribute('height')))) {
             if (strpos($this->mediaUrl, 'http://') === 0) {
                 $extension = pathinfo(parse_url($this->mediaUrl, PHP_URL_PATH), PATHINFO_EXTENSION);
                 $cacheFileName = 'external_' . md5($this->mediaUrl) . '.' . $extension;
                 $cacheFilePath = __Paths::get('CACHE') . $cacheFileName;
                 // scarica il file e lo mette in cache
                 if (!file_exists($cacheFilePath)) {
                     @file_put_contents($cacheFilePath, @file_get_contents($this->mediaUrl));
                 }
                 $params = array('media_id' => 0, 'media_fileName' => $cacheFilePath);
                 $this->media = __ObjectFactory::createObject('org.glizycms.mediaArchive.media.Image', $params);
             }
             $this->media->allowDownload = true;
             $thumbnail = $this->media->getResizeImage($this->getAttribute('width'), $this->getAttribute('height'), $this->getAttribute('crop'), $this->getAttribute('cropOffset'), false, false);
             $attributes['src'] = $thumbnail['fileName'];
             $attributes['width'] = $thumbnail['width'];
             $attributes['height'] = $thumbnail['height'];
             $this->_content['src'] = $thumbnail['fileName'];
             $this->_content['width'] = $thumbnail['width'];
             $this->_content['height'] = $thumbnail['height'];
         }
         unset($attributes['mediaUrl']);
         unset($attributes['zoom']);
         unset($attributes['size']);
         unset($attributes['mediaType']);
         $this->_content['__html__'] = '<img ' . $this->_renderAttributes($attributes) . '/>';
         if ($this->getAttribute('zoom') || $useZoom) {
             $this->_application->addLightboxJsCode();
             $attributes = array();
             $attributes['title'] = $this->_content['title'];
             $thumbnail = $this->media->getResizeImage(__Config::get('IMG_WIDTH_ZOOM'), __Config::get('IMG_HEIGHT_ZOOM'));
             $attributes['href'] = $thumbnail['fileName'];
             $attributes['rel'] = 'milkbox' . ($this->getAttribute('group') != '' ? '[' . $this->getAttribute('group') . ']' : '');
             $attributes['class'] = $zoomCssClass;
             $this->_content['__html__'] = org_glizy_helpers_Html::renderTag('a', $attributes, true, $this->_content['__html__']);
         }
     } else {
         $this->_content['__html__'] = '';
     }
 }
Beispiel #8
0
 /**
  * @param $className
  *
  * @return GlizyObject|mixed
  */
 function retrieveService($className)
 {
     $classObj = __ObjectFactory::createObject($className, $this);
     return $classObj;
 }
Beispiel #9
0
 public function saveContent($data, $publish = true)
 {
     $entityTypeId = $data->entityTypeId;
     $entityId = $data->entityId;
     $document = org_glizy_objectFactory::createObject('org.glizy.dataAccessDoctrine.ActiveRecordDocument');
     $document->setType('entity' . $entityTypeId);
     $result = $document->load($entityId, 'LAST_MODIFIED');
     if (!$result) {
         $languageProxy = __ObjectFactory::createObject('org.glizycms.languages.models.proxy.LanguagesProxy');
         $defaultLanguageId = $languageProxy->getDefaultLanguageId();
         $document->load($entityId, 'LAST_MODIFIED', $defaultLanguageId);
         $document->setLanguage($languageProxy->getLanguageId());
     }
     $document->setVisible($data->__isVisible);
     $document->addField(new org_glizy_dataAccessDoctrine_DbField('title', Doctrine\DBAL\Types\Type::STRING, 255, false, null, '', false));
     $document->title = $data->title;
     $document->addField(new org_glizy_dataAccessDoctrine_DbField('subtitle', Doctrine\DBAL\Types\Type::STRING, 255, false, null, '', false));
     $document->subtitle = $data->subtitle;
     $document->addField(new org_glizy_dataAccessDoctrine_DbField('url', Doctrine\DBAL\Types\Type::STRING, 255, false, null, '', false, false, '', org_glizy_dataAccessDoctrine_DbField::NOT_INDEXED));
     $originalUrl = $document->url;
     $document->url = $data->url;
     $document->addField(new org_glizy_dataAccessDoctrine_DbField('profile', Doctrine\DBAL\Types\Type::TARRAY, 255, false, null, '', false));
     $document->profile = $data->profile;
     $application = org_glizy_ObjectValues::get('org.glizy', 'application');
     $fieldTypeService = $application->retrieveProxy('movio.modules.ontologybuilder.service.FieldTypeService');
     $entityTypeService = $application->retrieveProxy('movio.modules.ontologybuilder.service.EntityTypeService');
     $entityTypeProperties = $entityTypeService->getEntityTypeProperties($entityTypeId);
     $fulltext = $document->title . org_glizycms_Glizycms::FULLTEXT_DELIMITER;
     if ($document->subtitle) {
         $fulltext .= $document->subtitle . org_glizycms_Glizycms::FULLTEXT_DELIMITER;
     }
     foreach ((array) $entityTypeProperties as $entityTypeProperty) {
         $attribute = $entityTypeService->getAttributeIdByProperties($entityTypeProperty);
         // se l'attributo non è una relazione
         if (is_null($entityTypeProperty['entity_properties_target_FK_entity_id'])) {
             $type = $fieldTypeService->getTypeMapping($entityTypeProperty['entity_properties_type']);
             // TODO permettere di definire in fieldTypes.xml altri validatori per ogni tipo
             if ($entityTypeProperty['entity_properties_required']) {
                 $validator = new org_glizy_validators_NotNull();
             } else {
                 $validator = null;
             }
             if ($fieldTypeService->isTypeIndexed($entityTypeProperty['entity_properties_type']) == true) {
                 $document->addField(new org_glizy_dataAccessDoctrine_DbField($attribute, $type, 255, false, $validator, '', false));
             } else {
                 $document->addField(new org_glizy_dataAccessDoctrine_DbField($attribute, $type, 255, false, $validator, '', false, false, '', org_glizy_dataAccessDoctrine_DbField::NOT_INDEXED));
             }
         } else {
             $document->addField(new org_glizy_dataAccessDoctrine_DbField($attribute, Doctrine\DBAL\Types\Type::TEXT, 1000, false, null, '', false, false, '', org_glizy_dataAccessDoctrine_DbField::INDEXED));
         }
         if (property_exists($data, $attribute)) {
             $value = $data->{$attribute};
             $document->{$attribute} = $value;
         } else {
             // se l'attributo non è nei dati può essere dovuto
             // ad un component custom (es phtogallery) che ha più valori da salvare
             $value = array('__restore' => new StdClass());
             foreach ($data as $k => $v) {
                 if (strpos($k, $attribute) === 0) {
                     $value['__restore']->{$k} = $v;
                 }
             }
             $document->{$attribute} = $value;
         }
         if ($fieldTypeService->isTypeIndexed($entityTypeProperty['entity_properties_type'])) {
             $stripped = trim(strip_tags($value));
             if (!is_numeric($value) && strlen($stripped) > org_glizycms_Glizycms::FULLTEXT_MIN_CHAR) {
                 $fulltext .= $stripped . org_glizycms_Glizycms::FULLTEXT_DELIMITER;
             }
         }
     }
     $document->addField(new org_glizy_dataAccessDoctrine_DbField('fulltext', Doctrine\DBAL\Types\Type::TEXT, 1000, false, null, '', false, false, '', org_glizy_dataAccessDoctrine_DbField::FULLTEXT));
     $document->fulltext = $fulltext;
     try {
         if ($publish) {
             $id = $document->publish();
         } else {
             if (__Config::get('glizycms.content.history')) {
                 $id = $document->saveHistory();
             } else {
                 $id = $document->save();
             }
         }
         $speakingUrlProxy = __Config::get('glizycms.speakingUrl') ? org_glizy_ObjectFactory::createObject('org.glizycms.speakingUrl.models.proxy.SpeakingUrlProxy') : null;
         if ($speakingUrlProxy) {
             $languageId = org_glizy_ObjectValues::get('org.glizy', 'editingLanguageId');
             if ($originalUrl != $document->url) {
                 //valida l'url
                 if (!$speakingUrlProxy->validate($document->url, $languageId, $id, 'movio.modules.ontologybuilder.content')) {
                     throw new org_glizy_validators_ValidationException(array('Url non valido perché già utilizzato'));
                 } else {
                     $options = array('entityTypeId' => $entityTypeId);
                     // aggiorna l'url parlante
                     $speakingUrlProxy->addUrl($document->url, $languageId, $id, 'movio.modules.ontologybuilder.content', $options);
                     org_glizy_cache_CacheFile::cleanPHP('../cache/');
                 }
             }
         }
     } catch (org_glizy_validators_ValidationException $e) {
         return $e->getErrors();
     }
     return $id;
 }