コード例 #1
0
 /**
  * overload schemaSave
  *
  * @return mixed
  *
  * @param  integer $userId
  *
  * @throws Exception
  * @throws PropelException
  */
 public function saveSchemaProperty($userId)
 {
     //if the property is modified then
     if ($this->isModified() || $this->isNew()) {
         $fields = Schema::getProfileArray();
         /** @var $field ProfileProperty */
         foreach ($fields as $field) {
             $fieldIds[sfInflector::underscore($field->getName())] = ["id" => $field->getId(), "hasLang" => $field->getHasLanguage()];
         }
         $statusId = $this->getStatusId();
         $con = Propel::getConnection(SchemaPropertyPeer::DATABASE_NAME);
         try {
             //start a transaction
             $con->begin();
             $this->setUpdatedUserId($userId);
             //if the property is new then
             if ($this->isNew()) {
                 //set the created user
                 $this->setCreatedUserId($userId);
             }
             //FIXME if the status is modified we have to update all of the existing statement statuses -- IF THEY MATCH THE OLD STATUS
             $columns = $this->modifiedColumns;
             //save it last
             $affectedRows = $this->save($con);
             $skipArray = ["is_subproperty_of", "is_subclass_of"];
             foreach ($columns as $column) {
                 $fieldName = SchemaPropertyPeer::translateFieldName($column, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME);
                 if (in_array($fieldName, $skipArray)) {
                     $object = $this->getParentUri();
                     if ("class" == $this->getType()) {
                         $fieldName = "is_subclass_of";
                         $objectId = $this->getIsSubclassOf();
                     } else {
                         $fieldName = "is_subproperty_of";
                         $objectId = $this->getIsSubpropertyOf();
                     }
                 } else {
                     $object = $this->getByName($column, BasePeer::TYPE_COLNAME);
                     $objectId = null;
                 }
                 SchemaPropertyPeer::updateRelatedElements($this, $fieldName, $object, $objectId, $userId, $fieldIds, $statusId, $con);
             }
             //commit the transaction
             $con->commit();
             return $affectedRows;
         } catch (PropelException $e) {
             $con->rollback();
             throw $e;
         }
     }
 }