public function update(RecordInterface $record) { if ($record->hasFields('id')) { $con = new Condition(array('id', '=', $record->id)); $this->table->update($record->getData(), $con); // update rights if available $rights = isset($record->rights) ? $record->rights : null; $handler = $this->hm->getHandler('AmunService\\User\\Group\\Right', $this->user); $con = new Condition(array('groupId', '=', $record->id)); $oldRights = $this->hm->getTable('AmunService\\User\\Group\\Right')->getCol('id', $con); // delete old rights foreach ($oldRights as $id) { $rightRecord = $handler->getRecord(); $rightRecord->id = $id; $handler->delete($rightRecord); } if (!empty($rights)) { // create new rights foreach ($rights as $rightId) { $rightRecord = $handler->getRecord(); $rightRecord->groupId = $record->id; $rightRecord->rightId = $rightId; $handler->create($rightRecord); } } $this->notify(RecordAbstract::UPDATE, $record); return $record; } else { throw new Exception('Missing field in record'); } }
public function notify($type, TableInterface $table, RecordInterface $record) { $message = Json::encode($record->getData()); $headers = array('amun-table' => $table->getName(), 'amun-type' => $type, 'amun-user-id' => $this->user->id); $stomp = new Stomp($this->registry['stomp.broker'], $this->registry['stomp.user'], $this->registry['stomp.pw']); $stomp->send($this->registry['stomp.destination'], $message, $headers); unset($stomp); }
public function update(RecordInterface $record) { if ($record->hasFields('id')) { $con = new Condition(array('id', '=', $record->id)); $this->table->update($record->getData(), $con); $this->notify(RecordAbstract::UPDATE, $record); return $record; } else { throw new Exception('Missing field in record'); } }
public function create(RecordInterface $record) { if ($record->hasFields('accessId', 'rightId')) { $this->table->insert($record->getData()); $record->id = $this->sql->getLastInsertId(); $this->notify(RecordAbstract::INSERT, $record); return $record; } else { throw new Exception('Missing field in record'); } }
public function update(RecordInterface $record) { if ($record->hasFields('id')) { if (isset($record->url)) { // request host meta $template = $this->getLrddTemplate($record->getUrl()); $record->template = (string) $template; } $con = new Condition(array('id', '=', $record->id)); $this->table->update($record->getData(), $con); $this->notify(RecordAbstract::UPDATE, $record); return $record; } else { throw new Exception('Missing field in record'); } }
public function update(RecordInterface $record) { if ($record->hasFields('id')) { // check whether project exists if (isset($record->url)) { $type = TypeAbstract::getType($record->type); if (!$type->hasProject($record->url)) { throw new Exception('Project doesnt exist'); } } $con = new Condition(array('id', '=', $record->id)); $this->table->update($record->getData(), $con); $this->notify(RecordAbstract::UPDATE, $record); return $record; } else { throw new Exception('Missing field in record'); } }
private function substituteVars(RecordInterface $record, $content, $url = null) { // object fields if ($url !== null && strpos($content, '{object.url') !== false) { $content = str_replace('{object.url}', $url, $content); } // user fields if (strpos($content, '{user.') !== false) { $fields = array('id', 'name', 'profileUrl', 'lastSeen', 'date'); foreach ($fields as $v) { $key = '{user.' . $v . '}'; if (strpos($content, $key) !== false) { $value = call_user_func(array($this->user, 'get' . ucfirst($v))); $content = str_replace($key, $value, $content); } } } // record fields if (strpos($content, '{record.') !== false) { $fields = $record->getData(); foreach ($fields as $k => $v) { $key = '{record.' . $k . '}'; if (strpos($content, $key) !== false) { $content = str_replace($key, $v, $content); } } } return $content; }
public function update(RecordInterface $record) { if ($record->hasFields('id')) { $date = new DateTime('NOW', $this->registry['core.default_timezone']); $record->ip = $_SERVER['REMOTE_ADDR']; $record->updated = $date->format(DateTime::SQL); // set host id if we have an remote host discover the profile url if (isset($record->hostId)) { if (!isset($record->name)) { $con = new Condition(array('id', '=', $record->id)); $name = $this->sql->select($this->table->getName(), array('name'), $con, Sql::SELECT_FIELD); } else { $name = $record->name; } if (empty($record->hostId)) { $record->hostId = 0; $record->profileUrl = $this->config['psx_url'] . '/' . $this->config['psx_dispatch'] . 'profile.htm/' . $name; } else { $record->status = Record::REMOTE; $record->profileUrl = $this->discoverProfileUrl($record->hostId, $name); } } // set thumbnail if email available and thumbnail not set if (!empty($record->email) && !isset($record->thumbnailUrl)) { $default = $this->config['psx_url'] . '/img/avatar/no_image.png'; $record->thumbnailUrl = 'http://www.gravatar.com/avatar/' . md5($record->email) . '.jpg?d=' . urlencode($default) . '&s=48'; } $con = new Condition(array('id', '=', $record->id)); $this->table->update($record->getData(), $con); $this->notify(RecordAbstract::UPDATE, $record); return $record; } else { throw new Exception('Missing field in record'); } }