コード例 #1
1
ファイル: AbstractCollection.php プロジェクト: skukit/mobac
 /**
  * Removes documents from collection
  *
  * @param array $query
  *
  * @return Result
  */
 public function remove($query)
 {
     $result = new Result();
     $bulk = new BulkWrite();
     $bulk->delete($query, ['limit' => 0]);
     $dbResult = $this->executeBulkWrite($bulk);
     if ($dbResult->getDeletedCount() === 0) {
         $result->setError(Result::ERROR_CANNOT_DELETE_RECORD, implode('. ', $dbResult->getWriteErrors()));
     }
     return $result;
 }
コード例 #2
0
ファイル: Unit.php プロジェクト: skukit/mobac
 /**
  * Removes document.
  *
  * @return Result
  */
 public function delete()
 {
     $result = new Result();
     if ($this->existsInProductCharacteristics() === true) {
         return $result->setError(Result::ERROR_CANNOT_UPDATE_RECORD, 'Unit present in product specifications');
     }
     if ($this->existsInPropertyCollection() === true) {
         return $result->setError(Result::ERROR_CANNOT_UPDATE_RECORD, 'Unit has related properties');
     }
     return parent::delete();
 }
コード例 #3
0
ファイル: AbstractType.php プロジェクト: skukit/mobac
 /**
  * Validate Specification.
  *
  * @param Specification $specification
  *
  * @return Result
  */
 public function validateSpecification(Specification $specification)
 {
     $result = new Result();
     if (empty($specification->getAttribute('value'))) {
         return $result->setError(Result::ERROR_VALIDATION_FAILED, 'Specification value empty');
     }
     if ($specification->getAttribute('unit_id') !== null && $specification->getUnit() === null) {
         return $result->setError(Result::ERROR_VALIDATION_FAILED, 'Specification unit invalid');
     }
     return $result;
 }
コード例 #4
0
ファイル: AbstractDocument.php プロジェクト: skukit/mobac
 /**
  * Saves document
  *
  * @param bool $validationNeeded
  *
  * @return Result
  */
 public function save($validationNeeded = true)
 {
     $result = new Result();
     /** @var AbstractCollection $collection */
     $collection = $this->getCollection();
     if ($validationNeeded) {
         $validatorResult = $collection->validate($this->toArray());
         if ($validatorResult->isValid() === false) {
             return $result->setError(Result::ERROR_VALIDATION_FAILED, $validatorResult->getErrorMessage());
         }
     }
     return $collection->update(['_id' => $this->getId()], ['$set' => $this->toArray()]);
 }
コード例 #5
0
ファイル: Category.php プロジェクト: skukit/mobac
 /**
  * Tries to unassign property from Category
  *
  * If property exists in Products ot this Category then fails
  *
  * @param ObjectID $propertyId
  *
  * @return Result
  */
 public function removeProperty(ObjectID $propertyId)
 {
     $result = new Result();
     $existsInProducts = (bool) $this->getClient()->getCollection('Product')->countByAttributes(['specifications' => ['$elemMatch' => ['property_id' => $propertyId]]]);
     return $existsInProducts ? $result->setError(Result::ERROR_CANNOT_UPDATE_RECORD, 'Property exists in specifications in products') : $this->getCollection()->update(['_id' => $this->getId()], ['$pull' => ['properties' => $propertyId]]);
 }
コード例 #6
0
ファイル: Product.php プロジェクト: skukit/mobac
 /**
  * Adds Spec to product.
  *
  * @param Specification $specification
  *
  * @return Result
  */
 public function addSpecification(Specification $specification)
 {
     $result = new Result();
     $validatorResult = $specification->validate();
     if ($validatorResult->isOk() == false) {
         return $result->setError(Result::ERROR_VALIDATION_FAILED, 'Specification invalid');
     }
     $this->getCollection()->update(['_id' => $this->getId()], ['$pull' => ['specifications' => ['property_id' => $specification->getPropertyId()]]]);
     // TODO: Perform next action only in previous succeeded
     return $this->getCollection()->update(['_id' => $this->getId()], ['$push' => ['specifications' => $specification->toArray() + ['_id' => $specification->getId()]]]);
 }
コード例 #7
0
ファイル: Property.php プロジェクト: skukit/mobac
 /**
  * Binds DefaultValue to property.
  *
  * @param DefaultValue $defaultValue
  *
  * @return Result
  */
 public function addDefaultValue(DefaultValue $defaultValue)
 {
     $result = new Result();
     $validatorResult = $defaultValue->validate();
     if ($validatorResult->isValid() == false) {
         return $result->setError(Result::ERROR_VALIDATION_FAILED, 'Default value invalid');
     }
     return $this->getCollection()->update(['_id' => $this->getId()], ['$push' => ['default_values' => $defaultValue->toArray() + ['_id' => $defaultValue->getId()]]]);
 }
コード例 #8
0
ファイル: Specification.php プロジェクト: skukit/mobac
 /**
  * @return Result
  */
 public function validate()
 {
     $result = new Result();
     $property = $this->getProperty();
     return $property ? $property->getTypeHandler()->validateSpecification($this) : $result->setError(Result::ERROR_VALIDATION_FAILED, 'Property not found');
 }