@param  string $foreign_id
@param  string $time
@param  array $new_targets
@param  array $added_targets
@param  array $removed_targets
@return mixed

@throws StreamFeedException
13678
public function updateActivityToTargets($foreign_id, $time, $new_targets = [], $added_targets = [], $removed_targets = [])
    {
        $data = [
            'foreign_id' => $foreign_id,
            'time'       => $time,
        ];

        if ($new_targets) {
            $data['new_targets'] = $new_targets;
        }

        if ($added_targets) {
            $data['added_targets'] = $added_targets;
        }

        if ($removed_targets) {
            $data['removed_targets'] = $removed_targets;
        }
        return $this->makeHttpRequest("feed_targets/{$this->slug}/{$this->user_id}/activity_to_targets/", 'POST', $data, null, 'feed_targets', 'write');
    }
1253870
public function removeActivity($activity_id, $foreign_id = false)
    {
        $query_params = [];

        if ($foreign_id === true) {
            $query_params['foreign_id'] = 1;
        }

        return $this->makeHttpRequest("{$this->base_feed_url}/{$activity_id}/", 'DELETE', null, $query_params, 'feed', 'delete');
    }
828226
public function actionMessages($queue_name, $subscriber_id = null)
    {
        if (($subscriber_id = trim($subscriber_id)) === '') {
            $subscriber_id = null;
        }
        /** @var QueueInterface $queue */
        list($queue, $authItems) = $this->loadQueue($queue_name, ['nfy.message.read', 'nfy.message.create']);
        $this->verifySubscriber($queue, $subscriber_id);

        $formModel = new models\MessageForm();
        if ($authItems['nfy.message.create'] && isset($_POST['MessageForm'])) {
            $formModel->attributes = $_POST['MessageForm'];
            if ($formModel->validate()) {
                $queue->send($formModel->content, $formModel->category);

                return $this->redirect([
                    'messages',
                    'queue_name' => $queue_name,
                    'subscriber_id' => $subscriber_id,
                ]);
            }
        }

        $dataProvider = null;
        if ($authItems['nfy.message.read']) {
            $dataProvider = new \yii\data\ArrayDataProvider([
                'allModels' => $queue->peek($subscriber_id, 200, [
                    components\Message::AVAILABLE,
                    components\Message::RESERVED,
                    components\Message::DELETED,
                ]),
                'sort' => [
                    'attributes' => ['id'],
                    'defaultOrder' => ['id' => SORT_DESC],
                ],
            ]);
            // reverse display order to simulate a chat window, where latest message is right above the message form
            $dataProvider->setModels(array_reverse($dataProvider->getModels()));
        }

        return $this->render('messages', [
            'queue' => $queue,
            'queue_name' => $queue_name,
            'dataProvider' => $dataProvider,
            'model' => $formModel,
            'authItems' => $authItems,
        ]);
    }
147514
public function getTableMigration($output, $new, $old)
    {
        if (!empty($this->options['foreign_keys'])) {
            $output[] = $this->getSetUniqueChecks(0);
            $output[] = $this->getSetForeignKeyCheck(0);
        }

        $output = $this->getTableMigrationNewDatabase($output, $new, $old);
        $output = $this->getTableMigrationNewTables($output, $new, $old);

        if (!empty($this->options['foreign_keys'])) {
            $lines = $this->getForeignKeysMigrations($new, $old);
            $output = $this->appendLines($output, $lines);
        }

        $output = $this->getTableMigrationOldTables($output, $new, $old);

        if (!empty($this->options['foreign_keys'])) {
            $output[] = $this->getSetForeignKeyCheck(1);
            $output[] = $this->getSetUniqueChecks(1);
        }

        return $output;
    }
333244
public function listTimecardEvents($timecard_id)
    {
        list($response, $statusCode, $httpHeader) = $this->listTimecardEventsWithHttpInfo ($timecard_id);
        return $response; 
    }
915764
public function insertChild ($relationIdentifier, $id, $row, $foreignKey = null)
		{
			$relation = $this->getRelation($relationIdentifier);

			if (! $relation) {
				throw new RelationException('Invalid relation `' . $relationIdentifier);
			}

			if ($relation instanceof OneToMany || $relation instanceof OneToOne) {
				if (is_null($foreignKey)) {
					$foreignKey = $this->getPrimaryKey();
				}

				$row[$foreignKey] = $id;

				$this->database->createQuery()
					->insert()
					->into($relation->getRelatedTable())
					->set($row)
					->execute();

				return $this->database->insertId();

			} else if ($relation instanceof ManyToMany) {
				if (is_null($foreignKey)) {
					$foreignKey = $this->getPrimaryKey();
				}

				$childId = $this->database->createQuery()
					->insert()
					->into($relation->getRelatedTable())
					->set($row)
					->execute();

				$data = array(
					$foreignKey => $id,
					$this->database->primaryKey($relation->getRelatedTable()) => $childId,
				);

				$this->database->createQuery()
					->insert()
					->into($relation->getRelationalTable())
					->set($data)
					->execute();

				return $childId;

			} else {
				throw new RelationException('Invalid relation type `' . gettype($relation) . '`');
			}
		}
1106915
function(target, time, noChange) {
            var inst = this._getInst(target);
            if (inst) {
                this._setTime(inst, time, noChange);
                this._updateTimepicker(inst);
                this._updateAlternate(inst, time);
            }
        }
975356
public static function process_foreign_keys($foreign_keys, $db = null)
	{
		if ( ! is_array($foreign_keys))
		{
			throw new \Database_Exception('Foreign keys on create_table() must be specified as an array');
		}

		$fk_list = array();

		foreach($foreign_keys as $definition)
		{
			// some sanity checks
			if (empty($definition['key']))
			{
				throw new \Database_Exception('Foreign keys on create_table() must specify a foreign key name');
			}
			if ( empty($definition['reference']))
			{
				throw new \Database_Exception('Foreign keys on create_table() must specify a foreign key reference');
			}
			if (empty($definition['reference']['table']) or empty($definition['reference']['column']))
			{
				throw new \Database_Exception('Foreign keys on create_table() must specify a reference table and column name');
			}

			$sql = '';
			! empty($definition['constraint']) and $sql .= " CONSTRAINT ".\DB::quote_identifier($definition['constraint']);
			$sql .= " FOREIGN KEY (".\DB::quote_identifier($definition['key']).')';
			$sql .= " REFERENCES ".\DB::quote_identifier(\DB::table_prefix($definition['reference']['table'], static::$connection)).' (';
			if (is_array($definition['reference']['column']))
			{
				$sql .= implode(', ', \DB::quote_identifier($definition['reference']['column']));
			}
			else
			{
				$sql .= \DB::quote_identifier($definition['reference']['column']);
			}
			$sql .= ')';
			! empty($definition['on_update']) and $sql .= " ON UPDATE ".$definition['on_update'];
			! empty($definition['on_delete']) and $sql .= " ON DELETE ".$definition['on_delete'];

			$fk_list[] = "\n\t".ltrim($sql);
		}

		return ', '.implode(',', $fk_list);
	}
264185
public function addResearch($id, $time)
    {
        $this->researchesById[$id] = new Research($this->rec, $id, $time);
    }
1246014
public function addForeignKey($fkdata)
    {
        if ($fkdata instanceof ForeignKey) {
            $fk = $fkdata;
            $fk->setTable($this);
            $this->foreignKeys[] = $fk;

            if ($this->foreignTableNames === null) {
                $this->foreignTableNames = array();
            }
            if (!in_array($fk->getForeignTableName(), $this->foreignTableNames)) {
                $this->foreignTableNames[] = $fk->getForeignTableName();
            }

            return $fk;
        } else {
            $fk = new ForeignKey();
            $fk->setTable($this);
            $fk->loadFromXML($fkdata);

            return $this->addForeignKey($fk);
        }
    }
84896
public function add($kind, $activityId, $userId, array $data=null, array $targetFeeds=null)
    {
        $payload = [
            'kind' => $kind,
            'activity_id' => $activityId,
            'user_id' => $userId,
        ];
        if( $data !== null ){
            $payload['data'] = $data;
        }
        if( $targetFeeds !== null ){
            $payload['target_feeds'] = $targetFeeds;
        }
        $response = $this->doRequest('POST', 'reaction/', $payload);
        $body = $response->getBody()->getContents();
        return json_decode($body, true);
    }
614976
public function addChildObject($alias, $parent_id, $model, $foreignKey) {
        $query = array(
            'alias' => $alias,
            'parent_id' => $parent_id,
            'model' => $model,
            'foreign_key' => $foreignKey
        );

        $result = $this->find('first', array(
            'conditions' => $query
        ));

        if ($result) {
            return $result;
        }

        $this->create();

        if ($this->save($query)) {
            $this->deleteCache(array('RequestObject::hasAlias', $alias));

            return $this->getByAlias($alias);
        }

        return null;
    }
545077
public function purge(DateTime $newest = null)
    {

        $deleteIds = [];

        /**
         * @var int $taskId
         * @var Task $task
         */
        foreach ($this->tasks as $taskId=>$task) {
            if ($task->getState() == Queue::FINISHED) {
                $deleteIds[] = $taskId;
            }
        }

        foreach ($deleteIds as $taskId) {
            unset($this->tasks[$taskId]);
        }

        return count($deleteIds);
    }
96292
public function postEventTrigger($event, $time, $time_unit, $zephyr) {
        $data = [ ];
        $data['time'] = $time;
        $data['time_unit'] = $time_unit;
        $data['event'] = $event;
        $data['zephyr'] = $zephyr;

        $result = $this->apiPost('trigger', $data);
        return $result;
    }
518547
static function ClassHasMany($parentclass, $foreignRef, $foreignKey = false, $foreignClass = 'ADODB_Active_Record')
	{
		$ar = new $parentclass();
		$ar->hasMany($foreignRef, $foreignKey, $foreignClass);
	}
1301234
public function assignChildren ($relationIdentifier, $id, $childIds, $subtractive = true)
		{
			$relation = $this->getRelation($relationIdentifier);
			$childIds = (array)$childIds;

			if (! $relation) {
				throw new RelationException('Invalid relation `' . $relationIdentifier);
			}

			if ($relation instanceof OneToMany) {
				$this->database->createQuery()
					->update()
					->table($relation->getRelatedTable())
					->set(
						array(
							$relation->getRelatedKey() => $id,
						)
					)
					->whereIn($this->database->primaryKey($relation->getRelatedTable()), $childIds)
					->execute();

				if ($subtractive) {
					$this->database->createQuery()
						->update()
						->table($relation->getRelatedTable())
						->set(
							array(
								$relation->getRelatedKey() => null,
							)
						)
						->whereEqual($relation->getRelatedKey(), $id)
						->whereNotIn($this->database->primaryKey($relation->getRelatedTable()), $childIds)
						->execute();
				}
			} else if ($relation instanceof ManyToMany) {
				if ($subtractive) {
					$this->database->createQuery()
						->delete()
						->from($relation->getRelationalTable())
						->whereEqual($relation->getKey(), $id)
						->whereNotIn($relation->getRelatedKey(), $childIds)
						->execute();
				}

				$query = $this->database->createQuery();

				$assignedIds =
					$query->select($relation->getRelatedKey())
						->from($relation->getRelationalTable())
						->whereEqual($relation->getKey(), $id)
						->execute()
						->fetchColumn();

				$newIds = array_diff($childIds, $assignedIds);

				foreach ($newIds as $newId) {
					$this->database->createQuery()
						->insert()
						->into($relation->getRelationalTable())
						->set(
							array(
								$relation->getKey()        => $id,
								$relation->getRelatedKey() => $newId,
							)
						)
						->execute();
				}
			} else {
				throw new RelationException('Invalid relation type `' . gettype($relation) . '`');
			}
		}
1270910
public function join(
        $foreignTable,
        $leftField = null,
        $joinKind = null,
        $joinAlias = null,
        $relation = null,
        $behaviour = 'cascade'
    ) {
        list($rightTable, $rightField) = explode('.', $foreignTable, 2);
        if (is_null($rightField)) {
            $rightField = 'id';
        }
        $referenceType = ($rightField === 'id') ? 'hasOne' : 'hasMany';
        if ($referenceType === 'hasMany') {
            throw $this->exception('has many join isn\'t supported');
        }
        $leftTable = $this->table;

        $joinAlias = $this->_unique($this->relations, $joinAlias);
        /** @type Field_SQL_Relation $field */
        $field = $this->add($this->defaultSQLRelationFieldClass);
        $field->setLeftTable($relation ?: $leftTable)
            ->setLeftField($leftField)
            ->setRightTable($rightTable)
            ->setRightField($rightField)
            ->setJoinKind($joinKind)
            ->setJoinAlias($joinAlias)
            ->setModel($this);

        $field->referenceType = $referenceType;
        $field->setBehaviour($behaviour);

        $this->relations[$joinAlias] = $field;

        return $field;
    }