/**
  * 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);
     }
 }
 /**
  * addField
  * @param GenericElementField $objField
  * @author Thomas Schedler <*****@*****.**>
  * @version 1.2
  */
 public 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, array('LANGUAGE_ID' => $this->objGenericForm->Setup()->getFormLanguageId(), 'ROOTLEVEL_LANGUAGE_ID' => $this->objGenericForm->Setup()->getLanguageId()), $this->objGenericForm->Setup()->getRootLevelId());
             $sqlStmt = $this->core->dbh->query($sqlSelect)->fetchAll();
             if ($objField->idFieldTypeGroup == GenericSetup::FIELD_TYPE_SELECT_ID) {
                 $arrOptions[''] = $this->core->translate->_('Please_choose', false);
             }
             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->objGenericForm->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->objGenericForm->Setup()->getLanguageId(), 'FormLanguageId' => $this->objGenericForm->Setup()->getFormLanguageId(), '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->objGenericForm->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;
                 }
             }
         }
         if (!is_null($intRegionInstanceId)) {
             if (count($objField->getInstanceProperties($intRegionInstanceId)) > 0) {
                 foreach ($objField->getInstanceProperties($intRegionInstanceId) 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)->isStartElement = $this->objGenericForm->Setup()->getIsStartElement(false);
             $this->getElement($objField->name . $strNameExtension)->intFormTypeId = $this->objGenericForm->Setup()->getFormTypeId();
             $this->getElement($objField->name . $strNameExtension)->intElementTypeId = $this->objGenericForm->Setup()->getElementTypeId();
             $this->getElement($objField->name . $strNameExtension)->intParentTypeId = $this->objGenericForm->Setup()->getParentTypeId();
         }
         $this->objGenericForm->fieldAddedToSubform($this->intId, $objField->name);
     } 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.º 4
0
 /**
  * getCategoriesValues
  * @param string $strFieldName
  * @return object $objCategoriesData
  * @author Cornelius Hansjakob <*****@*****.**>
  * @version 1.0
  */
 public function getCategoriesValues($strFieldName)
 {
     try {
         if (!array_key_exists($strFieldName, $this->arrCategoriesData)) {
             $this->arrCategoriesData[$strFieldName] = null;
             $mixedIds = self::getFieldValue($strFieldName);
             $sqlSelect = $this->objGenericData->Setup()->getField($strFieldName)->sqlSelect;
             if (is_array($mixedIds)) {
                 if (count($mixedIds) > 0) {
                     $strReplaceWhere = '';
                     foreach ($mixedIds as $strValue) {
                         $strReplaceWhere .= $strValue . ',';
                     }
                     $strReplaceWhere = trim($strReplaceWhere, ',');
                     $objReplacer = new Replacer();
                     $sqlSelect = $objReplacer->sqlReplacer($sqlSelect, $this->intLanguageId, $this->objGenericData->Setup()->getRootLevelId(), ' AND tbl.id IN (' . $strReplaceWhere . ')');
                     $this->arrCategoriesData[$strFieldName] = $this->core->dbh->query($sqlSelect)->fetchAll(Zend_Db::FETCH_OBJ);
                 }
             } else {
                 if ($mixedIds != '') {
                     $objReplacer = new Replacer();
                     $sqlSelect = $objReplacer->sqlReplacer($sqlSelect, $this->intLanguageId, $this->objGenericData->Setup()->getRootLevelId(), ' AND tbl.id = ' . $mixedIds);
                     $this->arrCategoriesData[$strFieldName] = $this->core->dbh->query($sqlSelect)->fetchAll(Zend_Db::FETCH_OBJ);
                 }
             }
         }
         return $this->arrCategoriesData[$strFieldName];
     } catch (Exception $exc) {
         $this->core->logger->err($exc);
     }
 }