Пример #1
0
 /**
  * Sets (i.e. updates) an entity meta property.
  *
  * @param string $key
  * @param mixed $value
  * @param string $locale
  * @param boolean $track
  * @throws InvalidArgumentException
  */
 public function setMeta($key, $value, $locale = null, $track = true)
 {
     parent::setMeta($key, $value, $track);
     if ($track) {
         if (!array_key_exists($key, $this->metaLocale)) {
             $this->metaLocale[$key] = $locale;
         } else {
             if (is_null($this->metaLocale[$key]) && !is_null($locale)) {
                 $this->metaLocale[$key] = $locale;
                 $index = array_search($key, $this->updatedMetaProperties);
                 unset($this->updatedMetaProperties[$index]);
                 reset($this->updatedMetaProperties);
                 $this->insertedMetaProperties[] = $key;
             }
         }
     } else {
         $this->metaLocale[$key] = $locale;
     }
 }
Пример #2
0
 /**
  * Adds meta data to the actual entity object.
  *
  * @param AbstractEntity $entity
  * @param mixed $resultRecord
  */
 protected static function setEntityMeta(AbstractEntity $entity, $resultRecord)
 {
     $entity->addMeta($resultRecord->key, $resultRecord->value);
 }
Пример #3
0
 protected function getInsertValues(AbstractEntity $entity)
 {
     return array('sid' => $entity->get('sid'), 'status' => $entity->get('status', 'enabled'), 'datetime_start' => $entity->need('datetime_start'), 'datetime_end' => $entity->need('datetime_end'), 'capacity' => $entity->get('capacity'));
 }
Пример #4
0
 /**
  * Deletes an entity meta record.
  *
  * @param string $id
  * @param int $eid
  * @param string $key
  * @param AbstractEntity $entity
  */
 protected function deleteMeta($id, $eid, $key, AbstractEntity $entity)
 {
     $locale = $entity->getMetaLocale($key);
     if ($locale) {
         $where = array($id => $eid, 'key' => $key, 'locale' => $locale);
     } else {
         $where = array($id => $eid, 'key' => $key, new IsNull('locale'));
     }
     $this->entityMetaTable->delete($where);
 }
Пример #5
0
 /**
  * Deletes an entity and all respective meta properties (through database foreign keys).
  *
  * @param AbstractEntity|int $entity
  * @return int
  * @throws InvalidArgumentException
  */
 public function delete($entity)
 {
     if ($entity instanceof AbstractEntity) {
         $eid = $entity->need($entity->getPrimary());
     } else {
         $eid = $entity;
     }
     if (!(is_numeric($eid) && $eid > 0)) {
         throw new InvalidArgumentException('Entity id must be numeric');
     }
     $entity = $this->get($eid);
     $id = $entity->getPrimary();
     $deletion = $this->entityTable->delete(array($id => $eid));
     $this->getEventManager()->trigger('delete', $entity);
     return $deletion;
 }