コード例 #1
0
ファイル: EntityField.php プロジェクト: HansonHuang/Pyramid
 public static function writeTable($table, $item, $primary_keys = array())
 {
     $schema = EntityConfigurator::getSchema($table);
     $fields = array();
     if (is_string($primary_keys)) {
         $primary_keys = array($primary_keys);
     }
     foreach ($schema as $field => $spec) {
         if (!empty($spec['increment'])) {
             $serial = $field;
         }
         if (in_array($field, $primary_keys)) {
             continue;
         }
         if (!property_exists($item, $field)) {
             continue;
         }
         $fields[$field] = $item->{$field};
     }
     if (empty($fields)) {
         return;
     }
     //没有指定keys,则新增
     if (empty($primary_keys)) {
         $query_return = db_insert($table)->fields($fields)->execute();
         if (isset($serial)) {
             $item->{$serial} = $query_return;
         }
         //赋其它字段默认值
         foreach ($schema as $field => $spec) {
             if (isset($spec['default']) && !property_exists($item, $field)) {
                 $item->{$field} = $spec['default'];
             }
         }
     } else {
         $query = db_update($table)->fields($fields);
         foreach ($primary_keys as $key) {
             $query->condition($key, $item->{$key});
         }
         $query_return = $query->execute();
     }
 }
コード例 #2
0
ファイル: EntityField.php プロジェクト: royalwang/Pyramid
 public static function fieldDelete($entityType, $entityId)
 {
     $info = EntityConfigurator::getEntityInfo($entityType);
     foreach ($info['cck'] as $field_name => $data) {
         $table = self::getFieldTableName($field_name);
         db_delete($table)->condition('entity_type', $entityType)->condition('entity_id', $entityId)->execute();
     }
 }