function loadFields() { $detail = new Profile_detail(); $detail->profile_id = $this->profile->id; $detail->find(); while ($detail->get()) { $fields[$detail->field][] = clone $detail; } return $fields; }
/** * Load extended profile fields * * @return array $fields the list of fields */ function loadFields() { $detail = new Profile_detail(); $detail->profile_id = $this->profile->getID(); $detail->find(); $fields = array(); while ($detail->fetch()) { $fields[$detail->field_name][] = clone $detail; } return $fields; }
/** * Save an extended profile field as a Profile_detail * * @param User $user the current user * @param string $name field name * @param string $value field value * @param string $rel field rel (type) * @param int $index index (fields can have multiple values) * @param date $date related date */ function saveField($user, $name, $value, $rel = null, $index = null, $date = null) { $profile = $user->getProfile(); $detail = new Profile_detail(); $detail->profile_id = $profile->id; $detail->field_name = $name; $detail->value_index = $index; $result = $detail->find(true); if (empty($result)) { $detial->value_index = $index; $detail->rel = $rel; $detail->field_value = $value; $detail->date = $date; $detail->created = common_sql_now(); $result = $detail->insert(); if (empty($result)) { common_log_db_error($detail, 'INSERT', __FILE__); // TRANS: Server error displayed when a field could not be saved in the database. $this->serverError(_m('Could not save profile details.')); } } else { $orig = clone $detail; $detail->field_value = $value; $detail->rel = $rel; $detail->date = $date; $result = $detail->update($orig); if (empty($result)) { common_log_db_error($detail, 'UPDATE', __FILE__); // TRANS: Server error displayed when a field could not be saved in the database. $this->serverError(_m('Could not save profile details.')); } } $detail->free(); }
/** * Save an extended profile field as a Profile_detail * * @param string $name field name * @param string $value field value * @param string $rel field rel (type) * @param int $index index (fields can have multiple values) * @param date $date related date */ function saveField($name, $value, $rel = null, $index = null, $date = null) { $detail = new Profile_detail(); $detail->profile_id = $this->scoped->getID(); $detail->field_name = $name; $detail->value_index = $index; $result = $detail->find(true); if (!$result instanceof Profile_detail) { $detail->value_index = $index; $detail->rel = $rel; $detail->field_value = $value; $detail->date = $date; $detail->created = common_sql_now(); $result = $detail->insert(); if ($result === false) { common_log_db_error($detail, 'INSERT', __FILE__); // TRANS: Server error displayed when a field could not be saved in the database. throw new ServerException(_m('Could not save profile details.')); } } else { $orig = clone $detail; $detail->field_value = $value; $detail->rel = $rel; $detail->date = $date; $result = $detail->update($orig); if ($result === false) { common_log_db_error($detail, 'UPDATE', __FILE__); // TRANS: Server error displayed when a field could not be saved in the database. throw new ServerException(_m('Could not save profile details.')); } } $detail->free(); }