/** * Get top contributors. * * @param [[@doctodo param_type:parentObject]] $parentObject [[@doctodo param_description:parentObject]] * @param array $options [[@doctodo param_description:options]] [optional] * * @return [[@doctodo return_type:getTopContributors]] [[@doctodo return_description:getTopContributors]] */ public function getTopContributors($parentObject, $options = []) { $individualType = Yii::$app->collectors['types']->getOne('Individual')->object; $individualModelClass = $individualType->primaryModel; $individualModelAlias = $individualModelClass::modelAlias(); $taxonomyType = Yii::$app->collectors['taxonomies']->getOne('ic_time_individual_role'); $taxonomy = $taxonomyType->getTaxonomy('contributor'); $limit = isset($options['limit_contributors']) ? $options['limit_contributors'] : 5; $query = $this->getBaseStatsQuery($parentObject); $query->join('LEFT JOIN', Relation::tableName() . ' r2', 'r2.child_object_id=innerQuery.id'); $query->join('LEFT JOIN', Registry::tableName() . ' reg', 'r2.parent_object_id=reg.id'); $query->join('LEFT JOIN', RelationTaxonomy::tableName() . ' tax', 'r2.id=tax.relation_id'); $query->select(['r2.parent_object_id', 'SUM(`hours`) as sum']); $query->groupBy(['r2.parent_object_id']); $query->andWhere(['reg.object_model' => $individualModelAlias]); $query->andWhere(['tax.taxonomy_id' => $taxonomy->primaryKey]); $query->addOrderBy(['SUM(`hours`)' => SORT_DESC]); $query->limit($limit); $c = []; foreach ($query->each() as $row) { $individual = Registry::getObject($row['parent_object_id']); if (!$individual) { continue; } $c[$row['parent_object_id']] = ['label' => $individual->descriptor, 'sum' => $row['sum']]; } return $c; }
/** * @inheritdoc */ public function getModel() { if (is_null($this->_model)) { $relationTabularId = RelationModel::generateTabularId($this->field); $attributes = empty($this->attributes) ? [] : $this->attributes; $taxonomy = false; if (isset($attributes['taxonomy_id'])) { $taxonomy = $attributes['taxonomy_id']; unset($attributes['taxonomy_id']); } $relationOptions = ['where' => $attributes, 'taxonomy' => $taxonomy]; $this->model = $this->relationship->getPrimaryRelation($this->baseModel, $this->modelRole, $relationOptions); if (empty($this->_model)) { $this->model = $this->baseModel->getObjectRelationModel($this->field); } $this->_model->_moduleHandler = $this->field; if (empty($this->_model)) { \d("what"); exit; } } return $this->_model; }
/** * */ public function groupWalker(&$item, $key, $mparent = null) { if (is_array($item)) { $parent = Group::find()->disableAccessCheck()->where(['name' => $key])->one(); if (empty($parent)) { $parent = new Group(); //$parent->disableAcl(); $parent->name = $key; $parent->system = preg_replace('/ /', '_', strtolower($parent->name)); $parent->level = $this->getGroupLevel($key); if (!$parent->save()) { $this->errors[] = "Failed to create group {$key}!"; return false; } if (!empty($mparent)) { $r = new Relation(); $r->parent_object_id = $mparent; $r->child_object_id = $parent->id; $r->active = 1; if (!$r->save()) { $this->errors[] = "Failed to create group relationship {$key}!"; return false; } } } $item = array_walk($item, [$this, 'groupWalker'], $parent->id); } else { $sitem = Group::find()->disableAccessCheck()->where(['name' => $item])->one(); if (empty($sitem)) { $sitem = new Group(); //$sitem->disableAcl(); $sitem->name = $item; $sitem->system = preg_replace('/ /', '_', strtolower($sitem->name)); $sitem->level = $this->getGroupLevel($item); if (!$sitem->save()) { $this->errors[] = "Failed to create group {$item}!"; return false; } if (!empty($mparent)) { $r = new Relation(); $r->parent_object_id = $mparent; $r->child_object_id = $sitem->id; $r->active = 1; if (!$r->save()) { $this->errors[] = "Failed to create group relationship {$key}!"; return false; } } } $setup->registry['Group'][$item] = $sitem->id; } }
public static function getRelationClass() { return Relation::className(); }
/** * @inheritdoc */ public function taxonomies() { return [['name' => 'Role', 'models' => [\cascade\models\Relation::className()], 'modules' => [self::className()], 'systemId' => 'ic_agreement_account_role', 'systemVersion' => 1.1, 'multiple' => false, 'parentUnique' => false, 'required' => true, 'initialTaxonomies' => ['contractor' => 'Contractor', 'contractee' => 'Contractee', 'subcontractor' => 'Subcontractor']], ['name' => 'Role', 'models' => [\cascade\models\Relation::className()], 'modules' => [self::className()], 'systemId' => 'ic_agreement_individual_role', 'systemVersion' => 1.0, 'multiple' => true, 'parentUnique' => false, 'required' => true, 'initialTaxonomies' => ['primary_staff' => 'Primary Staff Member', 'primary_client_contact' => 'Primary Client Contact', 'billing_contact' => 'Billing Contact', 'technical_contact' => 'Technical Contact', 'other_contact' => 'Other Contact']]]; }
/** * @inheritdoc */ public function taxonomies() { return [['name' => 'Address Type', 'models' => [\cascade\models\Relation::className()], 'modules' => [self::className()], 'systemId' => 'ic_address_type', 'systemVersion' => 1.0, 'multiple' => true, 'parentUnique' => true, 'required' => true, 'initialTaxonomies' => ['billing' => 'Billing Address', 'shipping' => 'Shipping Address']]]; }
/** * @inheritdoc */ public function taxonomies() { return [['name' => 'Role', 'models' => [\cascade\models\Relation::className()], 'modules' => [self::className()], 'systemId' => 'ic_task_individual_role', 'systemVersion' => 1.0, 'multiple' => false, 'parentUnique' => true, 'required' => true, 'initialTaxonomies' => ['assignee' => 'Assigned To', 'requestor' => 'Requestor']]]; }