Dołącza pliki dla danego object i id
@param string $object obiekt
@param integer $id obiektu
@param array $files tabela plików
@param array $allowedTypes
@return boolean
171942
public static function appendFiles($object, $id = null, array $files = [], array $allowedTypes = [])
    {
        //pola formularza
        foreach ($files as $fileSet) {
            //pojedynczy upload
            if ($fileSet instanceof \Mmi\Http\RequestFile) {
                if (null === self::appendFile($fileSet, $object, $id, $allowedTypes)) {
                    return false;
                }
                continue;
            }
            //pliki w polu formularza
            foreach ($fileSet as $file) {
                /* @var $file \Mmi\Http\RequestFile */
                if (null === self::appendFile($file, $object, $id, $allowedTypes)) {
                    return false;
                }
            }
        }
        return true;
    }
961273
public static function toDate($object, $objectId, $year, $month, $day)
    {
        $now = strtotime($year . '-' . $month . '-' . $day);
        $prev = strtotime('-1 month', $now);

        $raw = [];
        //uzupełnianie danych surowych poprzednim miesiącem
        foreach (self::getRows($object, $objectId, date('Y', $prev), date('m', $prev), true, null) as $stat) {
            $raw[$stat->year . '-' . $stat->month . '-' . $stat->day] = $stat->count;
        }
        //uzupełnianie danych surowych obecnym miesiącem
        foreach (self::getRows($object, $objectId, date('Y', $now), date('m', $now), true, null) as $stat) {
            $raw[$stat->year . '-' . $stat->month . '-' . $stat->day] = $stat->count;
        }
        $statArray = [];

        //uzupełnianie dni
        for ($i = 30; $i > -1; $i--) {
            $curTime = strtotime('-' . $i . ' day', $now);
            $count = 0;
            if (isset($raw[date('Y', $curTime) . '-' . ltrim(date('m', $curTime), '0') . '-' . ltrim(date('d', $curTime), '0')])) {
                $count = $raw[date('Y', $curTime) . '-' . ltrim(date('m', $curTime), '0') . '-' . ltrim(date('d', $curTime), '0')];
            }
            $statArray[date('m.d', $curTime)] = $count;
        }
        return $statArray;
    }
695157
public function persistNewObject(IObject $object)
    {
        if (!$this->contains($object)) {
            throw new NotAllowedOperationException($this->translate(
                'Cannot persist new object. Object from another collection given.'
            ));
        }

        $dataSource = $this->getMetadata()
            ->getCollectionDataSource();
        $identifyColumnName = $this->getIdentifyField()
            ->getColumnName();

        $insertBuilder = $dataSource->insert();

        // set object id
        if ($object->getId()) {
            $insertBuilder
                ->set($identifyColumnName)
                ->bindValue(
                    ':' . $identifyColumnName,
                    $object->getId(),
                    $this
                        ->getIdentifyField()
                        ->getDataType()
                );
        }

        // set type
        $typeName = $object->getTypePath();
        $objectTypeField = $this->getObjectTypeField();
        $columnName = $objectTypeField->getColumnName();
        $insertBuilder->set($columnName);
        $insertBuilder->bindValue(':' . $columnName, $typeName, $objectTypeField->getDataType());

        foreach ($object->getModifiedProperties() as $property) {
            if ($this->getMetadata()
                ->getFieldExists($property->getName())
            ) {
                $field = $this->getMetadata()
                    ->getField($property->getName());
                $field->persistProperty($object, $property, $insertBuilder);
            }
        }

        $insertBuilder->execute();
        
        if (!$object->getId()) {
            $objectId = $insertBuilder->getConnection()->lastInsertId();
            if (!$objectId) {
                throw new RuntimeException($this->translate(
                    'Cannot persist object. Cannot get last inserted id for object.'
                ));
            }
            $object->getProperty(IObject::FIELD_IDENTIFY)
                ->setInitialValue($objectId);
        }

    }
294374
public function upload($id, array $files)
    {
        if (!empty($files)) {
            $uploader = new FileUploader();

            foreach ($files as $file) {
                if (!$uploader->upload($this->getPath($id), $files)) {
                    return false;
                }
            }

            return true;
        }

        return false;
    }
791839
private function verifyElementsType(array $elements): void
    {
        $allowedType = $this->getAllowedType();
        if ($allowedType !== DTO::class
            && (!\class_exists($allowedType) || !\in_array(DTO::class, \class_implements($allowedType), true))
        ) {
            throw new InvalidCollectionTypeException(\sprintf(
                'Allowed class type for %s should be a %s, %s given',
                static::class,
                DTO::class,
                $allowedType
            ));
        }

        foreach ($elements as $element) {
            if (!\is_object($element) || !\is_a($element, $allowedType)) {
                throw new InvalidParameterException(\sprintf(
                    'All elements of %s should be instances of %s, %s given',
                    static::class,
                    $allowedType,
                    \is_object($element) ? \get_class($element) : \gettype($element)
                ));
            }
        }
    }
339890
function addAllowedType($assoc_type, $session_type = null)
    {
        if ($this->allowed_types === null) {
            $this->allowed_types = array();
        }

        if ($session_type === null) {
            $available = Auth_OpenID_getSessionTypes($assoc_type);

            if (!$available) {
                return false;
            }

            foreach ($available as $session_type) {
                $this->addAllowedType($assoc_type, $session_type);
            }
        } else {
            if (Auth_OpenID_checkSessionType($assoc_type, $session_type)) {
                $this->allowed_types[] = array($assoc_type, $session_type);
            } else {
                return false;
            }
        }

        return true;
    }
706343
public function delete(EntityDefinition $definition, array $ids, WriteContext $writeContext): DeleteResult
    {
        $this->validateWriteInput($ids);

        $commandQueue = new WriteCommandQueue();

        $fields = $definition->getPrimaryKeys();

        $resolved = [];
        foreach ($ids as $raw) {
            $mapped = [];

            /** @var Field $field */
            foreach ($fields as $field) {
                if (!($field instanceof StorageAware)) {
                    continue;
                }

                if (array_key_exists($field->getPropertyName(), $raw)) {
                    $mapped[$field->getStorageName()] = $raw[$field->getPropertyName()];
                    continue;
                }

                if ($field instanceof ReferenceVersionField) {
                    $mapped[$field->getStorageName()] = $writeContext->getContext()->getVersionId();
                    continue;
                }

                if ($field instanceof VersionField) {
                    $mapped[$field->getStorageName()] = $writeContext->getContext()->getVersionId();
                    continue;
                }

                $fieldKeys = $fields
                    ->filter(function (Field $field) {
                        return !$field instanceof VersionField && !$field instanceof ReferenceVersionField;
                    })
                    ->map(function (Field $field) {
                        return $field->getPropertyName();
                    });

                throw new IncompletePrimaryKeyException($fieldKeys);
            }

            $resolved[] = $mapped;
        }

        if (!$definition instanceof MappingEntityDefinition) {
            $restrictions = $this->foreignKeyResolver->getAffectedDeleteRestrictions($definition, $resolved, $writeContext->getContext());

            if (!empty($restrictions)) {
                $restrictions = array_map(function ($restriction) {
                    return new RestrictDeleteViolation($restriction['pk'], $restriction['restrictions']);
                }, $restrictions);

                throw new RestrictDeleteViolationException($definition, $restrictions, $this->registry);
            }
        }

        $cascades = [];
        if (!$definition instanceof MappingEntityDefinition) {
            $cascadeDeletes = $this->foreignKeyResolver->getAffectedDeletes($definition, $resolved, $writeContext->getContext());

            $cascadeDeletes = array_column($cascadeDeletes, 'restrictions');
            foreach ($cascadeDeletes as $cascadeDelete) {
                $cascades = array_merge_recursive($cascades, $cascadeDelete);
            }

            foreach ($cascades as $affectedDefinitionClass => &$cascade) {
                $affectedDefinition = $this->registry->get($affectedDefinitionClass);

                $cascade = array_map(function ($key) use ($affectedDefinition) {
                    $payload = $key;

                    if (!\is_array($key)) {
                        $payload = ['id' => $key];
                    }

                    return new EntityWriteResult($key, $payload, $affectedDefinition, null);
                }, $cascade);
            }
        }

        $skipped = [];
        foreach ($resolved as $mapped) {
            $mappedBytes = array_map(function ($id) {
                return Uuid::fromHexToBytes($id);
            }, $mapped);

            $existence = $this->gateway->getExistence($definition, $mappedBytes, [], $commandQueue);

            if (!$existence->exists()) {
                $skipped[$definition->getClass()][] = new EntityWriteResult($mapped, $mapped, $definition, $existence);
                continue;
            }

            $commandQueue->add(
                $definition,
                new DeleteCommand(
                    $definition,
                    $mappedBytes,
                    $existence
                )
            );
        }

        $writeContext->setLanguages($this->languageLoader->loadLanguages());
        $identifiers = $this->getWriteResults($commandQueue);
        $this->gateway->execute($commandQueue->getCommandsInOrder(), $writeContext);

        return new DeleteResult(
            array_merge_recursive($identifiers, $cascades),
            $skipped
        );
    }
485862
private static function DaftObjectIdPropertiesFromType(string $type, $id) : array
    {
        /**
        * @var array<int, string>
        */
        $idProps = array_values($type::DaftObjectIdProperties());

        if (is_scalar($id) && 1 === count($idProps)) {
            $id = [$id];
        }

        /**
        * @var array<string, mixed>
        */
        $idkv = [];

        if (is_array($id)) {
            foreach ($idProps as $i => $prop) {
                /**
                * @var scalar|array|object|null
                */
                $propVal = $id[$i] ?? null;

                $idkv[$prop] = $propVal;
            }
        }

        return $idkv;
    }
232039
protected function file(array &$files, $type, $index)
    {
        if (is_array($files[$type]))
        {
            return $files[$type][$index];
        }

        return $files[$type];
    }
813627
private function checkFileTypeIsAllowed()
	{
		if(count($this->allowedMimeTypes) > 0)
		{
			if(! in_array($this->file->getMimeType(), $this->allowedMimeTypes))
			{
				throw new InvalidFileTypeException("Invalid File Type: " . $this->file->getMimeType() . " has not been allowed");
			}
		}
	}
511386
public function hasMany($id, \JSONSimpleStorage $object, array $foreignIds) {
        // set has one on foreign data
        foreach ($foreignIds as $foreignId) {
            $object->hasOne($foreignId, $this, $id);
        }
    }
987146
public function currentAction()
    {
        $objectId = !empty($this->getPost()->objectId) ? $this->getPost()->objectId : null;
        switch ($this->getPost()->fileTypes) {
            case 'images' :
                //zapytanie o obrazki
                $query = CmsFileQuery::imagesByObject($this->getPost()->object, $objectId);
                break;
            case 'notImages' :
                //wszystkie pliki bez obrazków
                $query = CmsFileQuery::notImagesByObject($this->getPost()->object, $objectId);
                break;
            default :
                //domyślne zapytanie o wszystkie pliki
                $query = CmsFileQuery::byObject($this->getPost()->object, $objectId);
        }

        $records = $query->find();
        foreach ($records as $record) {
            $record->data = $record->data->toArray();
        }

        //zwrot json'a z plikami
        return json_encode([
            'result' => 'OK',
            'files' => $records->toArray()
        ]);
    }
81164
public function getFileObjects()
    {
        $fileObjects = [];
        //iteracja po unikalnych obiektach
        foreach ((new \Cms\Orm\CmsFileQuery)->findUnique('object') as $object) {
            //pominięcie plików tymczasowych
            if ('tmp-' == substr($object, 0, 4)) {
                continue;
            }
            //dodanie pliku
            $fileObjects[$object] = $object;
        }
        return $fileObjects;
    }
722299
public function delete_wp_object( $object_type, $id, $force_delete = true ) {

		if ( in_array( $object_type, array( 'post_type', 'media' ) ) ) {
			$object_type = 'post';
		}

		if ( 'taxonomy' === $object_type ) {
			$object_type = 'term';
		}

		if ( empty( $id ) ) {
			return false;
		}

		if ( in_array( $object_type, array( 'post' ) ) ) {
			return wp_delete_post( $id, $force_delete );
		}

		if ( function_exists( 'wp_delete_' . $object_type ) ) {
			return call_user_func( 'wp_delete_' . $object_type, $id );
		}

		return false;
	}
458129
public function populateManyRelationByIDs(DataObject $object, $field, $ids = [])
    {
        // Define Relation:
        
        if (!empty($ids)) {
            $this->getRelationList($object, $field)->setByIDList($ids);
        }
        
        // Answer Object:
        
        return $object;
    }
360861
private function _validateDataType($data)
  {
    if(empty($this->allowed_file_types))
      return true;

    $finfo = new \finfo(FILEINFO_MIME_TYPE);

    if(!in_array($finfo->file($data['tmp_name']), $this->allowed_file_types))
      throw new FileTypeNotAllowedException();

    return true;
  }
821186
public static function filter(&$object, array $fields, $mode = 'allow')
    {
        if('allow' === $mode)
        {
            $unsetKeys = [];
            foreach($object as $field => $value)
            {
                if(!in_array($field, $fields))
                {
                    $unsetKeys[] = $field;
                }
            }
            foreach($unsetKeys as $key)
            {
                static::remove($object, $key);
            }
        }
        else if('deny' === $mode)
        {
            foreach($fields as $field)
            {
                static::remove($object, $field);
            }
        }
        else
        {
            throw new \InvalidArgumentException(sprintf('Unknow mode %s', $mode));
        }
    }