Ejemplo n.º 1
0
 /**
  * Get module.
  *
  * @return [[@doctodo return_type:getModule]] [[@doctodo return_description:getModule]]
  */
 public function getModule()
 {
     $method = ArrayHelper::getValue($this->parentWidget->settings, 'queryRole', 'all');
     $relationship = ArrayHelper::getValue($this->parentWidget->settings, 'relationship', false);
     if ($method === 'children') {
         return $relationship->child;
     } elseif ($method === 'parents') {
         return $relationship->parent;
     }
     return false;
 }
Ejemplo n.º 2
0
 /**
  * [[@doctodo method_description:handleInstructions]].
  *
  * @param [[@doctodo param_type:params]] $params [[@doctodo param_description:params]]
  */
 public function handleInstructions($params)
 {
     $this->clearParams($params);
     //\d($params);
     $this->scope = ArrayHelper::getValue($params, 'scope', 'watching');
     $direction = $this->direction = ArrayHelper::getValue($params, 'direction', '_older');
     $limit = ArrayHelper::getValue($params, 'limit', 25);
     $object = $this->context = ArrayHelper::getValue($params, 'object', false);
     if ($direction === '_newer') {
         $mostRecentItem = ArrayHelper::getValue($params, 'mostRecentItem', false);
         $this->query->andWhere($this->query->primaryAlias . '.[[created]] > FROM_UNIXTIME(' . (double) $mostRecentItem . ')');
         $this->query->orderBy([$this->query->primaryAlias . '.[[created]]' => SORT_DESC]);
         $this->pagination->pageSize = false;
         //\d(["newer", $this->query->createCommand()->rawSql]);exit;
     } else {
         // _older
         $this->pagination->pageSize = $limit;
         $lastTime = ArrayHelper::getValue($params, 'lastItemTimestamp', false);
         $lastItem = ArrayHelper::getValue($params, 'lastItem', false);
         if ($lastItem) {
             $this->query->andWhere($this->query->primaryAlias . '.[[created]] < FROM_UNIXTIME(' . (double) $lastItem . ')');
         }
         $this->query->orderBy([$this->query->primaryAlias . '.[[created]]' => SORT_DESC]);
         //SORT_ASC
         //\d($lastTime);
         //echo $this->query->createCommand()->rawSql;exit;
     }
     if ($this->scope === 'object' && $object) {
         $this->query->andWhere(['or', [$this->query->primaryAlias . '.direct_object_id' => $object], [$this->query->primaryAlias . '.indirect_object_id' => $object]]);
     } elseif ($this->scope !== 'all' && !empty(Yii::$app->user->id)) {
         $subquery = ObjectFamiliarity::find();
         $subquery->andWhere([$subquery->primaryAlias . '.user_id' => Yii::$app->user->id]);
         if ($this->scope === 'watching') {
             $subquery->andWhere([$subquery->primaryAlias . '.watching' => 1]);
         }
         $subquery->select(['object_id']);
         $this->query->join('INNER JOIN', ['sof' => $subquery], ['or', '{{sof}}.[[object_id]] = {{' . $this->query->primaryAlias . '}}.[[direct_object_id]]', '{{sof}}.[[object_id]] = {{' . $this->query->primaryAlias . '}}.[[indirect_object_id]]']);
         $this->query->distinct = true;
     } else {
         $this->scope = 'all';
     }
 }
Ejemplo n.º 3
0
 public function getMenuItems($model, $key, $index)
 {
     $objectType = $model->objectType;
     $menu = [];
     $baseUrl = ['id' => $model->primaryKey];
     $queryRole = ArrayHelper::getValue($this->settings, 'queryRole', false);
     $relationship = ArrayHelper::getValue($this->settings, 'relationship', false);
     // $relationModel = $this->getObjectRelationModel($model);
     $baseUrl['related_object_id'] = Yii::$app->request->object->primaryKey;
     // $baseUrl['relationship_id'] = $relationship->systemId;
     if ($queryRole === 'children') {
         $primaryRelation = $relationship->getPrimaryObject(Yii::$app->request->object, $model, 'child');
         $baseUrl['object_relation'] = 'child:' . $model->objectType->systemId;
         $checkField = 'child_object_id';
     } else {
         $primaryRelation = $relationship->getPrimaryObject(Yii::$app->request->object, $model, 'parent');
         $baseUrl['object_relation'] = 'parent:' . $model->objectType->systemId;
         $checkField = 'parent_object_id';
     }
     if ($primaryRelation !== false && (empty($primaryRelation) || $primaryRelation && $primaryRelation->{$checkField} !== $model->primaryKey)) {
         $menu['primary'] = ['icon' => 'fa fa-star', 'label' => 'Set as primary', 'url' => ['/object/set-primary'] + $baseUrl, 'linkOptions' => ['data-handler' => 'background']];
     }
     // update button
     $updateLabel = false;
     if (!$objectType->hasDashboard && $model->can('update')) {
         $updateLabel = 'Update';
         $updateUrl = ['/object/update'] + $baseUrl;
     } elseif ($model->canUpdateAssociation(Yii::$app->request->object) && $relationship->hasFields) {
         $updateLabel = 'Update Relationship';
         $updateUrl = ['/object/link'] + $baseUrl;
     }
     if ($updateLabel) {
         $menu['update'] = ['icon' => 'fa fa-wrench', 'label' => $updateLabel, 'url' => $updateUrl, 'linkOptions' => ['data-handler' => 'background']];
     }
     if (!$objectType->hasDashboard && $model->can('manageAccess')) {
         $menu['access'] = ['icon' => 'fa fa-key', 'label' => 'Manage Access', 'url' => ['/object/access'] + $baseUrl, 'linkOptions' => ['data-handler' => 'background']];
     }
     // delete button
     if ($model->can('delete') || $model->canDeleteAssociation(Yii::$app->request->object)) {
         $menu['delete'] = ['icon' => 'fa fa-trash-o', 'label' => 'Delete', 'url' => ['/object/delete'] + $baseUrl, 'linkOptions' => ['data-handler' => 'background']];
     }
     return $menu;
 }
Ejemplo n.º 4
0
 /**
  * [[@doctodo method_description:_parseParams]].
  *
  * @throws HttpException [[@doctodo exception_description:HttpException]]
  * @return [[@doctodo return_type:_parseParams]] [[@doctodo return_description:_parseParams]]
  *
  */
 public function _parseParams()
 {
     $paramSource = $_GET;
     $p = [];
     // primary object
     $p['objectId'] = ArrayHelper::getValue($paramSource, 'id', false);
     if ($p['objectId']) {
         $p['object'] = Registry::getObject($p['objectId'], false);
         if (empty($p['object'])) {
             throw new HttpException(404, "Unknown object '{$p['objectId']}.");
         }
     }
     // object type
     $p['typeName'] = ArrayHelper::getValue($paramSource, 'type', false);
     if ($p['typeName']) {
         $p['typeItem'] = Yii::$app->collectors['types']->getOne($p['typeName']);
         if (isset($p['typeItem']->object)) {
             $p['type'] = $p['typeItem']->object;
         }
     } elseif (isset($p['object'])) {
         $p['typeItem'] = $p['object']->objectTypeItem;
         $p['type'] = $p['object']->objectType;
     }
     if (empty($p['type'])) {
         throw new HttpException(404, "Unknown object type.");
     }
     // related object
     $p['relatedObjectId'] = ArrayHelper::getValue($paramSource, 'related_object_id', false);
     if ($p['relatedObjectId']) {
         $p['relatedObject'] = Registry::getObject($p['relatedObjectId'], false);
         if (empty($p['relatedObject'])) {
             throw new HttpException(404, "Unknown related object.");
         }
         $p['relatedType'] = $p['relatedObject']->objectType;
     }
     // relation
     $p['objectRelationName'] = ArrayHelper::getValue($paramSource, 'object_relation', false);
     if ($p['objectRelationName'] && isset($p['relatedType'])) {
         list($p['relationship'], $p['relationshipRole']) = $p['relatedType']->getRelationship($p['objectRelationName']);
         if (!empty($p['relationship']) && !empty($p['relatedObject']) && !empty($p['object'])) {
             if ($p['relationshipRole'] === 'child') {
                 $p['parentObject'] = $p['relatedObject'];
                 $p['childObject'] = $p['object'];
             } else {
                 $p['parentObject'] = $p['object'];
                 $p['childObject'] = $p['relatedObject'];
             }
             $p['relation'] = $p['relationship']->getModel($p['parentObject'], $p['childObject']);
         }
         if (empty($p['relationship'])) {
             throw new HttpException(404, "Unknown type relationship {$p['objectRelationName']}");
         }
     }
     return $p;
 }