/**
  * indexFieldNow
  * @param GenericElementField $objField
  * @param string $strField
  * @param integer $intFieldType
  * @param string|array|object $mixedFieldValue
  * @param Zend_Search_Lucene_Document $objDoc
  * @return void
  * @author Thomas Schedler <*****@*****.**>
  */
 protected final function indexFieldNow($objField, $strField, $intFieldType, $mixedFieldValue, Zend_Search_Lucene_Document &$objDoc)
 {
     try {
         $strValue = '';
         $strValueIds = '';
         if ($objField->typeId == GenericSetup::FIELD_TYPE_ID_TAG) {
             $mixedValue = $mixedFieldValue;
             if (is_object($mixedValue) || is_array($mixedValue)) {
                 foreach ($mixedValue as $objTag) {
                     $strValue .= $objTag->title . ', ';
                     $strValueIds .= '[' . $objTag->id . ']';
                 }
                 $strValue = rtrim($strValue, ', ');
             }
         } elseif (!is_object($mixedFieldValue) && $objField->sqlSelect != '') {
             $sqlSelect = $objField->sqlSelect;
             $arrIds = array();
             if (is_array($mixedFieldValue)) {
                 $arrIds = $mixedFieldValue;
             } else {
                 if ($mixedFieldValue != '') {
                     if (strpos($mixedFieldValue, '[') !== false) {
                         $mixedFieldValue = trim($mixedFieldValue, '[]');
                         $arrIds = explode('][', $mixedFieldValue);
                     } else {
                         $arrIds = array($mixedFieldValue);
                     }
                 }
             }
             if (is_array($arrIds)) {
                 if (count($arrIds) > 0) {
                     $strReplaceWhere = '';
                     foreach ($arrIds as $strId) {
                         $strReplaceWhere .= $strId . ',';
                     }
                     $strReplaceWhere = trim($strReplaceWhere, ',');
                     $objReplacer = new Replacer();
                     $sqlSelect = $objReplacer->sqlReplacer($sqlSelect, $this->setup->getLanguageId(), $this->setup->getRootLevelId(), ' AND tbl.id IN (' . $strReplaceWhere . ')');
                     $objCategoriesData = $this->core->dbh->query($sqlSelect)->fetchAll(Zend_Db::FETCH_OBJ);
                     if (count($objCategoriesData) > 0) {
                         foreach ($objCategoriesData as $objCategories) {
                             $strValue .= $objCategories->title . ', ';
                             $strValueIds .= '[' . $objCategories->id . ']';
                         }
                         $strValue = rtrim($strValue, ', ');
                     }
                 }
             }
         } else {
             $strValue = html_entity_decode($mixedFieldValue, ENT_COMPAT, $this->core->sysConfig->encoding->default);
         }
         if (is_string($strValue) && $strValue != '') {
             if ($intFieldType == GenericSetup::FILE_FIELD) {
                 $objFiles = $this->getModelFiles()->loadFilesById($strValue);
                 $arrValues = array();
                 if (count($objFiles) > 0) {
                     foreach ($objFiles as $objFile) {
                         $arrValues[] = array('path' => $objFile->path, 'filename' => $objFile->filename, 'version' => $objFile->version);
                     }
                 }
                 $strValueIds = $strValue;
                 $strValue = serialize($arrValues);
             }
             if ($strValueIds != '') {
                 $objDoc->addField(Zend_Search_Lucene_Field::unIndexed($strField . 'Ids', $strValueIds, $this->core->sysConfig->encoding->default));
             }
             $this->core->logger->debug($strField . ': ' . $strValue);
             switch ($objField->idSearchFieldTypes) {
                 case Search::FIELD_TYPE_KEYWORD:
                     $objDoc->addField(Zend_Search_Lucene_Field::keyword($strField, $strValue, $this->core->sysConfig->encoding->default));
                     break;
                 case Search::FIELD_TYPE_UNINDEXED:
                     $objDoc->addField(Zend_Search_Lucene_Field::unIndexed($strField, $strValue, $this->core->sysConfig->encoding->default));
                     break;
                 case Search::FIELD_TYPE_BINARY:
                     $objDoc->addField(Zend_Search_Lucene_Field::binary($strField, $strValue, $this->core->sysConfig->encoding->default));
                     break;
                 case Search::FIELD_TYPE_TEXT:
                     $objDoc->addField(Zend_Search_Lucene_Field::text($strField, $strValue, $this->core->sysConfig->encoding->default));
                     break;
                 case Search::FIELD_TYPE_UNSTORED:
                     $objDoc->addField(Zend_Search_Lucene_Field::unStored($strField, strip_tags($strValue), $this->core->sysConfig->encoding->default));
                     break;
             }
         }
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
     }
 }
 /**
  * addToIndex
  * @param string $strIndexPath
  * @param string $strKey
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.0
  */
 protected final function addToIndex($strIndexPath, $strKey)
 {
     try {
         if (!is_object($this->objIndex) || !$this->objIndex instanceof Zend_Search_Lucene) {
             if (count(scandir($strIndexPath)) > 2) {
                 $this->objIndex = Zend_Search_Lucene::open($strIndexPath);
             } else {
                 $this->objIndex = Zend_Search_Lucene::create($strIndexPath);
             }
         }
         $objDoc = new Zend_Search_Lucene_Document();
         $objDoc->addField(Zend_Search_Lucene_Field::keyword('key', $strKey));
         $objDoc->addField(Zend_Search_Lucene_Field::unIndexed('date', $this->setup->getPublishDate('d.m.Y')));
         $objDoc->addField(Zend_Search_Lucene_Field::unIndexed('rootLevelId', $this->setup->getRootLevelId()));
         /**
          * index fields
          */
         foreach ($this->setup->FieldNames() as $strField => $intFieldType) {
             $objField = $this->setup->getField($strField);
             if (is_object($objField) && $objField->idSearchFieldTypes != Search::FIELD_TYPE_NONE) {
                 $strValue = '';
                 if (is_array($objField->getValue()) && $objField->sqlSelect != '') {
                     $arrIds = $objField->getValue();
                     $sqlSelect = $objField->sqlSelect;
                     if (is_array($arrIds)) {
                         if (count($arrIds) > 0) {
                             $strReplaceWhere = '';
                             foreach ($arrIds as $strId) {
                                 $strReplaceWhere .= $strId . ',';
                             }
                             $strReplaceWhere = trim($strReplaceWhere, ',');
                             $objReplacer = new Replacer();
                             $sqlSelect = $objReplacer->sqlReplacer($sqlSelect, $this->setup->getLanguageId(), $this->setup->getRootLevelId(), ' AND tbl.id IN (' . $strReplaceWhere . ')');
                             $objCategoriesData = $this->core->dbh->query($sqlSelect)->fetchAll(Zend_Db::FETCH_OBJ);
                             if (count($objCategoriesData) > 0) {
                                 foreach ($objCategoriesData as $objCategories) {
                                     $strValue .= $objCategories->title . ', ';
                                 }
                                 $strValue = rtrim($strValue, ', ');
                             }
                         }
                     }
                 } else {
                     $strValue = $objField->getValue();
                 }
                 if ($strValue != '') {
                     switch ($objField->idSearchFieldTypes) {
                         case Search::FIELD_TYPE_KEYWORD:
                             $objDoc->addField(Zend_Search_Lucene_Field::keyword($strField, $strValue, $this->core->sysConfig->encoding->default));
                             break;
                         case Search::FIELD_TYPE_UNINDEXED:
                             $objDoc->addField(Zend_Search_Lucene_Field::unIndexed($strField, $strValue, $this->core->sysConfig->encoding->default));
                             break;
                         case Search::FIELD_TYPE_BINARY:
                             $objDoc->addField(Zend_Search_Lucene_Field::binary($strField, $strValue, $this->core->sysConfig->encoding->default));
                             break;
                         case Search::FIELD_TYPE_TEXT:
                             $objDoc->addField(Zend_Search_Lucene_Field::text($strField, $strValue, $this->core->sysConfig->encoding->default));
                             break;
                         case Search::FIELD_TYPE_UNSTORED:
                             $objDoc->addField(Zend_Search_Lucene_Field::unStored($strField, strip_tags($strValue), $this->core->sysConfig->encoding->default));
                             break;
                     }
                 }
             }
         }
         // Add document to the index.
         $this->objIndex->addDocument($objDoc);
         $this->objIndex->optimize();
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
     }
 }
Exemplo n.º 3
0
 /**
  * add
  * @param GenericSetup $objGenericSetup
  * @return stdClass Page
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.0
  */
 public function add(GenericSetup &$objGenericSetup)
 {
     $this->core->logger->debug('cms->models->Model_Pages->add()');
     $objPage = new stdClass();
     $objPage->pageId = uniqid();
     $objPage->version = 1;
     $objPage->sortPosition = GenericSetup::DEFAULT_SORT_POSITION;
     $objPage->parentId = $objGenericSetup->getParentId();
     $objPage->rootLevelId = $objGenericSetup->getRootLevelId();
     $objPage->isStartElement = $objGenericSetup->getIsStartElement();
     $intUserId = Zend_Auth::getInstance()->getIdentity()->id;
     /**
      * check if parent element is rootlevel or folder and get sort position
      */
     if ($objPage->parentId != '' && $objPage->parentId > 0) {
         $objPage->parentTypeId = $this->core->sysConfig->parent_types->folder;
         $objData = $this->getModelFolders()->countChilds($objPage->parentId);
     } else {
         if ($objPage->rootLevelId != '' && $objPage->rootLevelId > 0) {
             $objPage->parentId = $objPage->rootLevelId;
         } else {
             $this->core->logger->err('zoolu->modules->cms->models->Model_Pages->add(): intRootLevelId is empty!');
         }
         $objPage->parentTypeId = $this->core->sysConfig->parent_types->rootlevel;
         $objData = $this->getModelFolders()->countRootChilds($objPage->rootLevelId);
     }
     if (count($objData) == 1) {
         $objPage->sortPosition = current($objData)->counter;
     }
     /**
      * insert main data
      */
     $arrMainData = array('idParent' => $objPage->parentId, 'idParentTypes' => $objPage->parentTypeId, 'isStartPage' => $objPage->isStartElement, 'idUsers' => $intUserId, 'sortPosition' => $objPage->sortPosition, 'sortTimestamp' => date('Y-m-d H:i:s'), 'pageId' => $objPage->pageId, 'version' => $objPage->version, 'creator' => $objGenericSetup->getCreatorId(), 'created' => date('Y-m-d H:i:s'));
     $objPage->id = $this->getPageTable()->insert($arrMainData);
     /**
      * insert language specific properties
      */
     $arrProperties = array('pageId' => $objPage->pageId, 'version' => $objPage->version, 'idLanguages' => $this->intLanguageId, 'idGenericForms' => $objGenericSetup->getGenFormId(), 'idTemplates' => $objGenericSetup->getTemplateId(), 'idPageTypes' => $objGenericSetup->getElementTypeId(), 'showInNavigation' => $objGenericSetup->getShowInNavigation(), 'idDestination' => $objGenericSetup->getDestinationId(), 'idUsers' => $intUserId, 'creator' => $objGenericSetup->getCreatorId(), 'publisher' => $intUserId, 'created' => date('Y-m-d H:i:s'), 'published' => $objGenericSetup->getPublishDate(), 'idStatus' => $objGenericSetup->getStatusId());
     $this->getPagePropertyTable()->insert($arrProperties);
     return $objPage;
 }
Exemplo n.º 4
0
 /**
  * add
  * @param GenericSetup $objGenericSetup
  * @return stdClass Folder
  * @author Thomas Schedler <*****@*****.**>   
  */
 public function add(GenericSetup &$objGenericSetup)
 {
     $this->core->logger->debug('cms->models->Model_Folders->add()');
     $objFolder = new stdClass();
     $objFolder->folderId = uniqid();
     $objFolder->version = 1;
     $objFolder->sortPosition = GenericSetup::DEFAULT_SORT_POSITION;
     $objFolder->parentId = $objGenericSetup->getParentId();
     $objFolder->rootLevelId = $objGenericSetup->getRootLevelId();
     $intUserId = Zend_Auth::getInstance()->getIdentity()->id;
     /**
      * check if parent element is rootlevel or folder and get sort position
      */
     if ($objGenericSetup->getParentId() != '' && $objGenericSetup->getParentId() > 0) {
         $objData = $this->countChilds($objFolder->parentId);
     } else {
         $objData = $this->countRootChilds($objFolder->rootLevelId);
     }
     if (count($objData) == 1) {
         $objFolder->sortPosition = current($objData)->counter;
     }
     /**
      * insert main data
      */
     $arrMainData = array('folderId' => $objFolder->folderId, 'version' => $objFolder->version, 'sortPosition' => $objFolder->sortPosition, 'sortTimestamp' => date('Y-m-d H:i:s'), 'idUsers' => $intUserId, 'creator' => $objGenericSetup->getCreatorId(), 'created' => date('Y-m-d H:i:s'));
     /**
      * add folder node to the "Nested Set Model"
      */
     $objFolder->id = $this->addFolderNode($objFolder->rootLevelId, $objFolder->parentId, $arrMainData);
     /**
      * insert language specific properties
      */
     $arrProperties = array('folderId' => $objFolder->folderId, 'version' => $objFolder->version, 'idLanguages' => $this->intLanguageId, 'idGenericForms' => $objGenericSetup->getGenFormId(), 'idFolderTypes' => $this->core->sysConfig->folder_types->folder, 'idUsers' => $intUserId, 'creator' => $objGenericSetup->getCreatorId(), 'publisher' => $intUserId, 'created' => date('Y-m-d H:i:s'), 'published' => $objGenericSetup->getPublishDate(), 'idStatus' => $objGenericSetup->getStatusId(), 'isUrlFolder' => $objGenericSetup->getUrlFolder(), 'showInNavigation' => $objGenericSetup->getShowInNavigation());
     $this->getFolderPropertyTable()->insert($arrProperties);
     return $objFolder;
 }
 /**
  * addField
  * @param GenericElementField $objField
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.2
  */
 protected function addField(GenericElementField &$objField, $intRegionId, $strNameExtension = '', $intRegionInstanceId = null, $blnEmpty = false)
 {
     try {
         $sqlStmt = array();
         $arrOptions = array();
         /**
          * get array options for select output if sqlSelect is in database
          */
         if ($objField->sqlSelect != '' && $objField->sqlSelect) {
             $objReplacer = new Replacer();
             $sqlSelect = $objReplacer->sqlReplacer($objField->sqlSelect, $this->setup->getLanguageId(), $this->setup->getRootLevelId());
             $sqlStmt = $this->core->dbh->query($sqlSelect)->fetchAll();
             if ($objField->idFieldTypeGroup == GenericSetup::FIELD_TYPE_SELECT_ID) {
                 $arrOptions[''] = 'Bitte wählen';
             }
             foreach ($sqlStmt as $arrSql) {
                 if (array_key_exists('depth', $arrSql)) {
                     $arrOptions[$arrSql['id']] = array('title' => $arrSql['title'], 'depth' => $arrSql['depth']);
                 } else {
                     $arrOptions[$arrSql['id']] = $arrSql['title'];
                 }
             }
         }
         if ($objField->type == GenericSetup::FIELD_TYPE_TEMPLATE) {
             $objField->defaultValue = $this->setup->getTemplateId();
         }
         if (!is_null($intRegionInstanceId)) {
             $mixedValue = $objField->getInstanceValue($intRegionInstanceId);
         } else {
             $mixedValue = $objField->getValue();
         }
         if ($blnEmpty == true) {
             $mixedValue = null;
         }
         $strCssClass = '';
         if ($objField->isKeyField) {
             $strCssClass = ' keyfield';
         }
         /**
          * add field to form
          */
         $this->addElement($objField->type, $objField->name . $strNameExtension, array('value' => $mixedValue, 'label' => $objField->title, 'description' => $objField->description, 'decorators' => array($objField->decorator), 'fieldId' => $objField->id, 'columns' => $objField->columns, 'class' => $objField->type . $strCssClass, 'height' => $objField->height, 'isGenericSaveField' => $objField->isSaveField, 'isCoreField' => $objField->isCoreField, 'MultiOptions' => $arrOptions, 'LanguageId' => $this->setup->getLanguageId(), 'isEmptyField' => $blnEmpty == true ? 1 : 0, 'required' => $objField->isKeyField == 1 ? true : false));
         $this->getElement($objField->name . $strNameExtension)->regionId = $intRegionId;
         $this->getElement($objField->name . $strNameExtension)->regionExtension = $strNameExtension;
         $this->getElement($objField->name . $strNameExtension)->formTypeId = $this->setup->getFormTypeId();
         if (count($objField->getProperties()) > 0) {
             foreach ($objField->getProperties() as $strProperty => $mixedPropertyValue) {
                 if (in_array($strProperty, self::$FIELD_PROPERTIES_TO_IMPART)) {
                     $this->getElement($objField->name . $strNameExtension)->{$strProperty} = $mixedPropertyValue;
                 }
             }
         }
         /**
          * template specific addons
          */
         if ($objField->type == GenericSetup::FIELD_TYPE_TEMPLATE) {
             $this->getElement($objField->name . $strNameExtension)->isStartPage = $this->Setup()->getIsStartElement(false);
             $this->getElement($objField->name . $strNameExtension)->intElementTypeId = $this->Setup()->getElementTypeId();
             $this->getElement($objField->name . $strNameExtension)->intParentTypeId = $this->Setup()->getParentTypeId();
         }
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
     }
 }
Exemplo n.º 6
0
 /**
  * add
  * @param GenericSetup $objGenericSetup
  * @return stdClass Global
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.0
  */
 public function add(GenericSetup &$objGenericSetup)
 {
     $this->core->logger->debug('global->models->Model_Globals->add()');
     $objGlobal = new stdClass();
     $objGlobal->globalId = uniqid();
     $objGlobal->version = 1;
     $objGlobal->sortPosition = GenericSetup::DEFAULT_SORT_POSITION;
     $intUserId = Zend_Auth::getInstance()->getIdentity()->id;
     if ($objGenericSetup->getRootLevelGroupId() == $this->core->sysConfig->root_level_groups->product) {
         $objGlobal->parentId = $this->core->sysConfig->product->rootLevels->list->id;
         $objGlobal->parentTypeId = $this->core->sysConfig->parent_types->rootlevel;
     } else {
         /**
          * check if parent element is rootlevel or folder and get sort position
          */
         if ($objGenericSetup->getParentId() != '' && $objGenericSetup->getParentId() > 0) {
             $objGlobal->parentId = $objGenericSetup->getParentId();
             $objGlobal->parentTypeId = $this->core->sysConfig->parent_types->folder;
             $objData = $this->getModelFolders()->countChilds($objGlobal->parentId);
         } else {
             if ($objGenericSetup->getRootLevelId() != '' && $objGenericSetup->getRootLevelId() > 0) {
                 $objGlobal->parentId = $objGenericSetup->getRootLevelId();
             } else {
                 $this->core->logger->err('zoolu->modules->global->models->Model_Globals->add(): intRootLevelId is empty!');
             }
             $objGlobal->parentTypeId = $this->core->sysConfig->parent_types->rootlevel;
             $objData = $this->getModelFolders()->countGlobalRootChilds($objGlobal->parentId);
         }
         if (count($objData) == 1) {
             $objGlobal->sortPosition = current($objData)->counter;
         }
     }
     /**
      * insert main data
      */
     $arrMainData = array('idParent' => $objGlobal->parentId, 'idParentTypes' => $objGlobal->parentTypeId, 'isStartGlobal' => $objGenericSetup->getIsStartElement(), 'idUsers' => $intUserId, 'sortPosition' => $objGlobal->sortPosition, 'sortTimestamp' => date('Y-m-d H:i:s'), 'globalId' => $objGlobal->globalId, 'version' => $objGlobal->version, 'creator' => $objGenericSetup->getCreatorId(), 'created' => date('Y-m-d H:i:s'));
     $objGlobal->id = $this->getGlobalTable()->insert($arrMainData);
     /**
      * insert language specific properties
      */
     $arrProperties = array('globalId' => $objGlobal->globalId, 'version' => $objGlobal->version, 'idLanguages' => $this->intLanguageId, 'idLanguageFallbacks' => $objGenericSetup->getLanguageFallbackId(), 'idGenericForms' => $objGenericSetup->getGenFormId(), 'idTemplates' => $objGenericSetup->getTemplateId(), 'idGlobalTypes' => $objGenericSetup->getElementTypeId(), 'showInNavigation' => $objGenericSetup->getShowInNavigation(), 'idUsers' => $intUserId, 'creator' => $objGenericSetup->getCreatorId(), 'publisher' => $intUserId, 'created' => date('Y-m-d H:i:s'), 'published' => $objGenericSetup->getPublishDate(), 'idStatus' => $objGenericSetup->getStatusId());
     $this->getGlobalPropertyTable()->insert($arrProperties);
     /**
      * if is tree add, make alis now
      */
     if ($objGenericSetup->getRootLevelId() == $this->core->sysConfig->product->rootLevels->tree->id) {
         $objGlobal->parentId = $objGenericSetup->getParentId();
         $objGlobal->rootLevelId = $objGenericSetup->getRootLevelId();
         $objGlobal->rootLevelGroupId = $objGenericSetup->getRootLevelGroupId();
         $objGlobal->isStartElement = $objGenericSetup->getIsStartElement();
         $this->addLink($objGlobal);
     }
     return $objGlobal;
 }