Approve an incoming connection request.  AKA "approve request"

@param $model
@return bool
493613
public function approve($model)
    {
        $approvedAtLeastOne = false;

        if ($model->friends->count()) {
            foreach ($model->friends as $friend) {
                if ((int) $friend->getKey() === (int) $this->getKey()) {
                    $friend->pivot->approved_at = new \Carbon\Carbon;
                    $friend->pivot->save();
                    $this->resetFriends();

                    $approvedAtLeastOne = true;
                }
            }
        }

        return $approvedAtLeastOne;
    }
537365
public function ApproveLink($member = null)
    {
        if ($this->canEdit($member) && !$this->Moderated) {
            return $this->actionLink('approve', $member);
        }
    }
392111
public function upload($model, $request)
    {
        $files = $this->getFile($request);

        if (array_search(null,$files) === false) {
            foreach($files as $key => $file) {
                $this->setFileName($file);
                $this->setFileSize($file);
                $this->files[] = $this->moveImage($file, $key, $model, $request);
            }
            return count($this->files) === 1 ? $this->files[0] : $this->files;
        }
        return false;
    }
386289
public function authorized(User $user, Model $model = null)
    {
        return $this->filter(function ($action) use ($user, $model) {
            // authorize action only if action allows it.
            if (method_exists($action, 'authorize')) {
                return $action->authorize($user, $model);
            }

            return true;
        });
    }
558319
public function afterValidate(Model $model) {
		if (!empty($model->validationErrors)){
			$model->data[$model->alias] = $this->runtime[$model->alias]['data'];
		}
		
		return true;
	}
431938
public function drop($model, $confirm)
    {
        // exit if no correct confirmation string
        if ($confirm != 'confirm') {
            return;
        }

        //
        $models = $model == '*'
                ? $this->getModels()
                : [$model];

        //
        if (!count($models)) {
            return;
        }

        //
        foreach ($models as $model) {
            $table = $this->getTable($model);

            //
            if (!$table) {
                continue;
            }

            //
            $sql = "DROP TABLE `{$table}`";

            //
            $this->execute($sql);
        }
    }
495044
public function delete( $model, $config = [] ) {

		$hard	= $config[ 'hard' ] ?? true;
		$notify = $config[ 'notify' ] ?? true;

		if( isset( $model ) ) {

			// Permanent Delete
			if( $hard ) {

				return $model->delete();
			}
			// Soft Delete - Useful for models using status to mark model as deleted, but keep for historic purpose.
			else {

				$interfaces = class_implements( static::class );

				if( isset( $interfaces[ 'cmsgears\core\common\services\interfaces\base\IApproval' ] ) ) {

					// Approval Trait
					return $this->softDeleteNotify( $model, $notify, $config );
				}
				else {

					return $this->softDelete( $model );
				}
			}
		}

		return false;
	}
119946
public function count($model)
    {
        $method = 'search_count';

        $condition = $this->condition ?: [[]];

        $result = $this->call($model, $method, $condition);

        //Reset params for future queries.
        $this->resetParams('condition');

        return $this->makeResponse($result, 0);

    }
209202
public function authorize($action, $model = null)
    {
        // for most cases it is enough to set
        // permissions in Resource object.
        if (method_exists($this->module, 'authorize')) {
            return $this->module->authorize($action, $model);
        }

        // Ask Actions Service for action permissions.
        return $this->service->authorize($action, $model, $this->module);
    }
769591
public function liked(Model $model): bool
    {
        return (bool) $this->likes()
                           ->where('liked_by_id', $model->id)
                           ->where('liked_by_type', get_class($model))
                           ->count();
    }
1290029
public function connect($database, $model)
    {
        $this->database = $database;
        $this->tableName = $model;
        $this->_connection = $this->getConnection($database);

        return $this;
    }
188783
public function save(Model $model)
    {
        $this->setForeignAttributesForCreate($model);

        return $model->save() ? $model : false;
    }
354189
public function confirm(HTTPRequest $request)
    {
        if ($this->EmailType !== 'Confirmation' &&
            $this->EmailType !== 'Validation') {
            return $this->httpError(400, 'No confirmation required.');
        }

        $currentMember = Member::currentUser();
        $id = (int)$request->param('ID');
        $key = $request->getVar('key');

        if ($currentMember) {
            if ($currentMember->ID == $id) {
                return Security::permissionFailure($this, _t(
                    'MemberProfiles.ALREADYCONFIRMED',
                    'Your account is already confirmed.'
                ));
            }
            return Security::permissionFailure($this, _t(
                'MemberProfiles.CANNOTCONFIRMLOGGEDIN',
                'You cannot confirm account while you are logged in.'
            ));
        }

        if (!$id ||
            !$key) {
            return $this->httpError(404);
        }

        $confirmationTitle = $this->data()->dbObject('ConfirmationTitle');

        /**
         * @var Member|null $member
         */
        $member = DataObject::get_by_id(Member::class, $id);
        if (!$member) {
            return $this->invalidRequest('Member #'.$id.' does not exist.');
        }
        if (!$member->NeedsValidation) {
            // NOTE(Jake): 2018-05-03
            //
            // You might be hitting this if you set your MemberProfilePage to use
            // Email Setting 'Confirmation' rather than 'Validation' and you didn't
            // edit the original Email template to not include the copy about confirmation.
            //
            return $this->invalidRequest('Member #'.$id.' does not need validation.');
        }
        if (!$member->ValidationKey) {
            return $this->invalidRequest('Member #'.$id.' does not have a validation key.');
        }
        if ($member->ValidationKey !== $key) {
            return $this->invalidRequest('Validation key does not match.');
        }

        // Allow member to login
        $member->NeedsValidation = false;
        $member->ValidationKey = null;

        $validationResult = $member->validateCanLogin();
        if (!$validationResult->isValid()) {
            $this->getResponse()->setStatusCode(500);
            $validationMessages = $validationResult->getMessages();
            return [
                'Title'   => $confirmationTitle,
                'Content' => $validationMessages ? $validationMessages[0]['message'] : _t('MemberProfiles.ERRORCONFIRMATION', 'An unexpected error occurred.'),
            ];
        }
        $member->write();

        $this->extend('onConfirm', $member);

        if ($member->canLogin()) {
            Injector::inst()->get(IdentityStore::class)->logIn($member);
        } else {
            throw new Exception('Permission issue occurred. Was the "$member->validateCanLogin" check above this code block removed?');
        }

        return [
            'Title'   => $this->data()->dbObject('ConfirmationTitle'),
            'Content' => $this->data()->dbObject('ConfirmationContent')
        ];
    }
535650
public function save(Model $model)
    {
        $model->setAttribute($this->getPlainForeignKey(), $this->getParentKey());

        return $model->save() ? $model : false;
    }
1232149
protected function checkModelType($model)
    {
        if (is_string($model)) {
            return $this->getTable($model);
        } elseif (is_object($model)) {
            return $this->getTable(get_class($model));
        }
    }
131333
public function update(Record $model)
    {
        $query = $this->updateQuery($model);

        if ($query) {
            return $query->execute();
        }

        return false;
    }
1193396
protected function validateAjax($model)
    {
        if (!Yii::$app->request->isAjax || Yii::$app->request->isPjax) {
            return false;
        }
        $response = clone Yii::$app->response;
        $response->format = Response::FORMAT_JSON;
        if (!is_array($model)) {
            $model = [$model];
        }
        $response->content = json_encode(call_user_func_array('\yii\widgets\ActiveForm::validate', $model));
        return $response;
    }