Gc\Property\Value\Model::save PHP Method

save() public method

Save property value
public save ( ) : integer
return integer
    public function save()
    {
        $this->events()->trigger(__CLASS__, 'before.save', $this);
        $arraySave = array('document_id' => $this->getDocumentId(), 'property_id' => $this->getPropertyId());
        if ($this->getDriverName() == 'pdo_pgsql') {
            $arraySave['value'] = pg_escape_bytea($this->getValue());
        } else {
            $arraySave['value'] = $this->getValue();
        }
        try {
            $id = $this->getId();
            if (empty($id)) {
                $this->insert($arraySave);
                $this->setId($this->getLastInsertId());
            } else {
                $this->update($arraySave, array('id' => $this->getId()));
            }
            $this->events()->trigger(__CLASS__, 'after.save', $this);
            return $this->getId();
        } catch (\Exception $e) {
            $this->events()->trigger(__CLASS__, 'after.save.failed', $this);
            throw new \Gc\Exception($e->getMessage(), $e->getCode(), $e);
        }
    }

Usage Example

Esempio n. 1
0
 /**
  * Save property value
  *
  * @return boolean
  */
 public function saveValue()
 {
     $value = $this->getValue();
     $this->value->save();
     if ((is_null($value) or $value === '') and $this->isRequired()) {
         return false;
     } else {
         return true;
     }
 }
All Usage Examples Of Gc\Property\Value\Model::save