Beispiel #1
0
 /**
  * Get current entity identifiers collection by relation identifier ans its value.
  *
  * @param string $relationID Relation entity identifier
  * @param mixed|Condition $relationValue Relation entity value or relation condition
  * @param array $filteringIDs Collection of entity identifiers for filtering query
  * @param string $locale Locale for requests
  * @return array Collection of entity identifiers filtered by navigation identifier.
  */
 public function idsByRelationID($relationID, $relationValue = null, array $filteringIDs = array(), $locale = null)
 {
     $return = array();
     /** @var Field $fieldRecord We need to have field record */
     $fieldRecord = null;
     if (Field::byID($this->query, $relationID, $fieldRecord)) {
         // Get material identifiers by field
         $this->query->entity($this->relationIdentifier)->where(\samsoncms\api\MaterialField::F_DELETION, 1)->where($this->relationPrimary, $relationID);
         if ($relationValue instanceof ConditionInterface) {
             $this->query->whereCondition($relationValue);
         } else {
             $this->query->where($fieldRecord->valueFieldName(), $relationValue);
         }
         // Add material identifier filter if passed
         if (count($filteringIDs)) {
             $this->query->where($this->primaryField, $filteringIDs);
         }
         // If field is localized
         if ((int) $fieldRecord->local === 1) {
             // Add localization filter
             $this->query->where(\samsoncms\api\MaterialField::F_LOCALE, $locale);
         }
         // Perform database query and get only material identifiers collection
         $return = $this->query->fields($this->primaryField);
     }
     return $return;
 }
Beispiel #2
0
 /**
  * Virtual entity additional field analyzer.
  *
  * @param \samsoncms\api\generator\metadata\VirtualMetadata $metadata Metadata instance for filling
  * @param int                                               $fieldID  Additional field identifier
  * @param array                                             $fieldRow Additional field database row
  */
 public function analyzeFieldRecord(&$metadata, $fieldID, array $fieldRow)
 {
     // Get camelCase and transliterated field name
     $fieldName = $this->fieldName($fieldRow['Name']);
     // TODO: Set default for additional field storing type accordingly.
     // Store field metadata
     $metadata->realNames[$fieldRow['Name']] = $fieldName;
     $metadata->fields[$fieldID] = $fieldName;
     $metadata->fieldNames[$fieldName] = $fieldID;
     $metadata->allFieldValueColumns[$fieldID] = Field::valueColumn($fieldRow[Field::F_TYPE]);
     $metadata->types[$fieldID] = Field::phpType($fieldRow['Type']);
     $metadata->allFieldCmsTypes[$fieldID] = (int) $fieldRow['Type'];
     $metadata->fieldDescriptions[$fieldID] = $fieldRow['Description'] . ', ' . $fieldRow['Name'] . '#' . $fieldID;
     $metadata->fieldRawDescriptions[$fieldID] = $fieldRow['Description'];
 }
Beispiel #3
0
 /**
  * Get collection of images for material by gallery additional field selector. If none is passed
  * all images from gallery table would be returned for this material entity.
  *
  * @param string|null $fieldSelector Additional field selector value
  * @param string $selector Additional field field name to search for
  * @return \samsonframework\orm\RecordInterface[] Collection of images in this gallery additional field for material
  */
 public function &gallery($fieldSelector = null, $selector = 'FieldID')
 {
     /** @var \samsonframework\orm\RecordInterface[] $images Get material images for this gallery */
     $images = array();
     $this->query->entity(CMS::MATERIAL_FIELD_RELATION_ENTITY);
     /* @var Field Get field object if we need to search it by other fields */
     $field = null;
     if ($selector != 'FieldID' && Field::oneByColumn($this->query, $selector, $fieldSelector)) {
         $fieldSelector = $field->id;
     }
     // Add field filter if present
     if (isset($fieldSelector)) {
         $this->query->where("FieldID", $fieldSelector);
     }
     /** @var \samson\activerecord\materialfield $dbMaterialField Find material field gallery record */
     $dbMaterialField = null;
     if ($this->query->where('MaterialID', $this->id)->first($dbMaterialField)) {
         // Get material images for this materialfield
         $images = $this->query->entity(CMS::MATERIAL_IMAGES_RELATION_ENTITY)->where('materialFieldId', $dbMaterialField->id)->exec();
     }
     return $images;
 }