예제 #1
0
 /**
  * Возвращает обязательное поле коллекции.
  * @param $fieldName
  * @throws NonexistentEntityException если поле не существует
  * @return IField
  */
 protected function getRequiredField($fieldName)
 {
     if (!$this->metadata->getFieldExists($fieldName)) {
         throw new NonexistentEntityException($this->translate('Collection "{collection}" does not contain required field "{name}".', ['collection' => $this->name, 'name' => $fieldName]));
     }
     return $this->metadata->getField($fieldName);
 }
예제 #2
0
 /**
  * {@inheritdoc}
  */
 public function getField($fieldName)
 {
     if (!$this->getFieldExists($fieldName) || !($field = $this->fields[$fieldName])) {
         throw new NonexistentEntityException($this->translate('Field "{name}" does not exist in "{collection}.{type}".', ['name' => $fieldName, 'collection' => $this->metadata->getCollectionName(), 'type' => $this->name]));
     }
     return $field;
 }
예제 #3
0
 /**
  * Возвращает имена типов, которые должны присутствовать в выборке
  * @throws InvalidArgumentException если заданы невозможные условия выборки
  * @return array
  */
 protected function getSelectionTypes()
 {
     if (!count($this->usedFields)) {
         return array_keys($this->types);
     }
     $fields = array_keys($this->usedFields);
     if (!count($this->types)) {
         $types = $this->metadata->getTypesByFields($fields);
         if (!count($types)) {
             throw new InvalidArgumentException($this->translate('The selection is not possible. Conditions do not match metadata types.'));
         }
         if (!count(array_diff($this->metadata->getTypesList(), $types))) {
             $types = [];
         }
         return $types;
     }
     $types = array_keys($this->types);
     $typesCount = count($types);
     if (count(array_intersect($this->metadata->getTypesByFields($fields), $types)) != $typesCount) {
         throw new InvalidArgumentException($this->translate('The selection is not possible. Conditions do not match metadata types.'));
     }
     return $types;
 }