public function safeUp() { $this->addColumn('{{%object_cbs}}', 'id', Schema::TYPE_PK); $this->addColumn('{{%object_cbs}}', 'created_at', Schema::TYPE_INTEGER . ' NOT NULL'); $this->addColumn('{{%object_cbs}}', 'updated_at', Schema::TYPE_INTEGER . ' NOT NULL'); $query = \app\models\Objects::find(); $query->where(['not', ['cbs' => null]]); $dataProvider = new \yii\data\ActiveDataProvider(['query' => $query]); $objectsArray = $dataProvider->getModels(); foreach ($objectsArray as $objects) { $cbsNames = explode(',', $objects->cbs); foreach ($cbsNames as $cbsName) { // Find the CBS from APIs that matches the name that was saved as a text before $cbs = \app\models\Apis::findOne(['name' => $cbsName]); if ($cbs) { $objectsCBS = new \app\models\ObjectCBS(); $objectsCBS->object = $objects->id; $objectsCBS->cbs = $cbs->id; $objectsCBS->save(); } } } // Drop column cbs from Objects Table that is not needed anymore $this->dropColumn('{{%objects}}', 'cbs'); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Objects::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Objects::find(); $query->joinWith(['createdBy']); $query->where(['or', ['privacy' => 'public'], ['privacy' => 'protected'], ['privacy' => 'private', 'created_by' => Yii::$app->getUser()->id]]); $query->where(['not in', 'name', ['Addressmodel', 'Timemodel', 'Durationmodel', 'Frommodel', 'Locationmodel', 'Sizemodel', 'Tagsmodel', 'Applicationmodel', 'Basefilemodel', 'Organizationmodel', 'Personmodel', 'Placemodel', 'Productmodel', 'Servicemodel', 'Cartproductlist', 'Cartservicelist', 'Cart_target_id', 'Orderproductlist', 'Orderservicelist', 'Registeredapplication_user']]); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->sort->attributes['createdBy.username'] = ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC]]; if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'api' => $this->api, 'inherited' => $this->inherited, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'votes_up' => $this->votes_up, 'votes_down' => $this->votes_down, 'proposed' => $this->proposed]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'privacy', $this->privacy])->andFilterWhere(['like', 'methods', $this->methods])->andFilterWhere(['like', 'schema_org', $this->schema_org]); return $dataProvider; }
/** * Updates an existing Devices model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $listparent = Devices::find()->all(); $listobject = Objects::find()->all(); $listbrend = Brends::find()->all(); $listinterface = Interfaces::find()->all(); $liststate = States::find()->all(); $listype = Types::find()->all(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'listparent' => $listparent, 'listobject' => $listobject, 'listbrend' => $listbrend, 'listinterface' => $listinterface, 'liststate' => $liststate, 'listype' => $listype]); } }
function BuildObject($objectName, $objectDescription) { $model = Objects::find()->where(['name' => $objectName])->one(); if ($model === null) { $model = new Objects(); } else { Properties::deleteAll(['object' => $model->id]); } // If APIS_addressmodel keep only addressmodel and make it Addressmodel // If Checkin_openicheckin keep only checkin and make it Checkin $model->name = $objectName; $pos = strpos($model->name, '_'); if ($pos !== false) { $model->name = substr($model->name, $pos + 1); } $model->name = str_replace("openi", "", $model->name); $model->name = ucfirst($model->name); $model->description = $objectDescription; $model->api = $this->_apiID; $model->privacy = 'public'; $model->save(); $this->_objectID = $model->id; }
/** * Displays a User model. * @param integer $id * @param boolean $followed * @return mixed */ public function actionView($id, $followed = null) { // If I'm trying to view myself then redirect to index $myId = \Yii::$app->user->id; if ($myId == $id) { return $this->redirect(['index']); } $model = $this->findModel($id); $votedUpAPIsArray = array_filter(explode(',', $model->votes_up_apis)); $votedUpAPIsArrayInt = array_map('intval', $votedUpAPIsArray); $votedUpAPIsQuery = Apis::find()->where(['id' => $votedUpAPIsArrayInt]); $votedUpAPIsDataProvider = new ActiveDataProvider(['query' => $votedUpAPIsQuery, 'sort' => false, 'pagination' => ['pageSize' => 5]]); $votedDownAPIsArray = array_filter(explode(',', $model->votes_down_apis)); $votedDownAPIsArrayInt = array_map('intval', $votedDownAPIsArray); $votedDownAPIsQuery = Apis::find()->where(['id' => $votedDownAPIsArrayInt]); $votedDownAPIsDataProvider = new ActiveDataProvider(['query' => $votedDownAPIsQuery, 'sort' => false, 'pagination' => ['pageSize' => 5]]); $votedUpObjectsArray = array_filter(explode(',', $model->votes_up_objects)); $votedUpObjectsArrayInt = array_map('intval', $votedUpObjectsArray); $votedUpObjectsQuery = Objects::find()->where(['id' => $votedUpObjectsArrayInt]); $votedUpObjectsDataProvider = new ActiveDataProvider(['query' => $votedUpObjectsQuery, 'sort' => false, 'pagination' => ['pageSize' => 5]]); $votedDownObjectsArray = array_filter(explode(',', $model->votes_down_objects)); $votedDownObjectsArrayInt = array_map('intval', $votedDownObjectsArray); $votedDownObjectsQuery = Objects::find()->where(['id' => $votedDownObjectsArrayInt]); $votedDownObjectsDataProvider = new ActiveDataProvider(['query' => $votedDownObjectsQuery, 'sort' => false, 'pagination' => ['pageSize' => 5]]); $votedUpCommentsArray = array_filter(explode(',', $model->votes_up_comments)); $votedUpCommentsArrayInt = array_map('intval', $votedUpCommentsArray); $votedUpCommentsQuery = Comments::find()->where(['id' => $votedUpCommentsArrayInt]); $votedUpCommentsDataProvider = new ActiveDataProvider(['query' => $votedUpCommentsQuery, 'sort' => false, 'pagination' => ['pageSize' => 5]]); $votedDownCommentsArray = array_filter(explode(',', $model->votes_down_comments)); $votedDownCommentsArrayInt = array_map('intval', $votedDownCommentsArray); $votedDownCommentsQuery = Comments::find()->where(['id' => $votedDownCommentsArrayInt]); $votedDownCommentsDataProvider = new ActiveDataProvider(['query' => $votedDownCommentsQuery, 'sort' => false, 'pagination' => ['pageSize' => 5]]); $followedUsers = $model->getFollowees(); $followedUsersDataProvider = new ActiveDataProvider(['query' => $followedUsers, 'sort' => false, 'pagination' => ['pageSize' => 5]]); $followedApis = $model->getFollowingApis(); $followedApisDataProvider = new ActiveDataProvider(['query' => $followedApis, 'sort' => false, 'pagination' => ['pageSize' => 5]]); $followUserUser = FollowUserUser::findOne(['follower' => $myId, 'followee' => $id]); $doIFollow = false; if ($followUserUser != null) { $doIFollow = true; $followUserUser->last_seen = date("Y-m-d H:i:s"); $followUserUser->changed_photo = false; $followUserUser->changed_linkedin = false; $followUserUser->changed_github = false; $followUserUser->created_api = null; $followUserUser->changed_upvotes_apis = null; $followUserUser->changed_downvotes_apis = null; $followUserUser->save(); } $followers = FollowUserUser::find(['followee' => $id])->count(); $this->view->params['followed'] = $followed; return $this->render('view', ['model' => $model, 'votedUpAPIsDataProvider' => $votedUpAPIsDataProvider, 'votedDownAPIsDataProvider' => $votedDownAPIsDataProvider, 'votedUpObjectsDataProvider' => $votedUpObjectsDataProvider, 'votedDownObjectsDataProvider' => $votedDownObjectsDataProvider, 'votedUpCommentsDataProvider' => $votedUpCommentsDataProvider, 'votedDownCommentsDataProvider' => $votedDownCommentsDataProvider, 'followedUsersDataProvider' => $followedUsersDataProvider, 'followedApisDataProvider' => $followedApisDataProvider, 'doIFollow' => $doIFollow, 'followers' => $followers]); }
use yii\helpers\Html; use yii\bootstrap\ActiveForm; /* @var $this yii\web\View */ /* @var $model app\models\Properties */ /* @var $form yii\widgets\ActiveForm */ /* @var $propertyDropdownList yii\helpers\ArrayHelper Has all the available datatypes (string, integer, etc.) and the public objects but itself to make foreign keys.*/ // Find all the IDs of the Objects that are contained in this API so that we can populate the DropdownList below. $objectsOfAPI = $model->object0->api0->objects; $objectsIDs = []; foreach ($objectsOfAPI as $object) { // Exclude our Object as it can't be FK to itself. if ($object->id != $model->object) { $objectsIDs[] = $object->id; } } $propertyDropdownList = ArrayHelper::map(Objects::find()->where(['and', ['in', 'id', $objectsIDs]])->all(), 'name', 'name'); $propertyDropdownList = ArrayHelper::merge(['integer' => 'integer', 'long' => 'long', 'float' => 'float', 'double' => 'double', 'string' => 'string', 'byte' => 'byte', 'boolean' => 'boolean', 'date' => 'date', 'dateTime' => 'dateTime', '--------' => '--------'], $propertyDropdownList); ?> <div class="properties-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => 255, 'placeholder' => 'Property Name']); ?> <?php echo $form->field($model, 'description')->textInput(['maxlength' => 255, 'placeholder' => 'Property Description']);
/** * @inheritdoc */ public static function getList() { return Objects::find()->All(); }
/** * Lists all Objects models. * @return mixed */ public function actionIndex() { $dataProvider = new ActiveDataProvider(['query' => Objects::find()]); return $this->render('index', ['dataProvider' => $dataProvider]); }
use app\models\States; use app\models\Types; use yii\helpers\ArrayHelper; /* @var $this yii\web\View */ /* @var $searchModel app\models\DevicesSearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = 'Devices'; $this->params['breadcrumbs'][] = $this->title; ?> <div class="devices-index"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php // echo $this->render('_search', ['model' => $searchModel]); ?> <p> <?php echo Html::a('Create Devices', ['create'], ['class' => 'btn btn-success']); ?> </p> <?php echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'name', 'description:ntext', ['attribute' => 'type', 'label' => 'Тип', 'value' => 'types.name', 'filter' => ArrayHelper::map(Types::find()->all(), 'id', 'name')], ['attribute' => 'state', 'label' => 'state', 'value' => 'states.name', 'filter' => ArrayHelper::map(States::find()->all(), 'id', 'name')], ['attribute' => 'idobject', 'label' => 'Обьект', 'value' => 'objects.name', 'filter' => ArrayHelper::map(Objects::find()->all(), 'id', 'name')], ['class' => 'yii\\grid\\ActionColumn']]]); ?> </div>
<?php use app\models\Objects; use yii\helpers\ArrayHelper; use yii\helpers\Html; use yii\bootstrap\ActiveForm; /* @var $this yii\web\View */ /* @var $model app\models\Objects */ /* @var $form yii\widgets\ActiveForm */ /* @var $objectDropdownList yii\helpers\ArrayHelper */ $query = Objects::find(); $query->where(['privacy' => 'public']); $query->where(['not in', 'name', ['Addressmodel', 'Timemodel', 'Durationmodel', 'Frommodel', 'Locationmodel', 'Sizemodel', 'Tagsmodel', 'Applicationmodel', 'Basefilemodel', 'Organizationmodel', 'Personmodel', 'Placemodel', 'Productmodel', 'Servicemodel', 'Cartproductlist', 'Cartservicelist', 'Cart_target_id', 'Orderproductlist', 'Orderservicelist', 'Registeredapplication_user']]); $objectDropdownList = ArrayHelper::map($query->all(), 'id', 'name'); ?> <div class="objects-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'name')->textInput(['maxlength' => 255, 'placeholder' => 'Must be a unique name']); ?> <?php echo $form->field($model, 'inherited')->dropDownList($objectDropdownList, ['prompt' => '']); ?> <div class="form-group">