protected static function resolveRelatedItemIdsByModelAndUser(Item $model, &$relatedItemIds, User $user)
 {
     assert('is_array($relatedItemIds)');
     if (RightsUtil::canUserAccessModule($model::getModuleClassName(), $user)) {
         $itemId = $model->getClassId('Item');
         if (!in_array($itemId, $relatedItemIds)) {
             $relatedItemIds[] = $itemId;
         }
     }
 }
Example #2
0
 /**
  * Given a Item (Either User or Person),  Try to find an existing models and index the returning array by
  * badge type.
  * @param Item $person
  */
 public static function getAllByPersonIndexedByType(Item $person)
 {
     assert('$person->id > 0');
     assert('$person instanceof Contact || $person instanceof User');
     $searchAttributeData = array();
     $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'person', 'relatedAttributeName' => 'id', 'operatorType' => 'equals', 'value' => $person->getClassId('Item')));
     $searchAttributeData['structure'] = '1';
     $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('GameBadge');
     $where = RedBeanModelDataProvider::makeWhere('GameBadge', $searchAttributeData, $joinTablesAdapter);
     $models = self::getSubset($joinTablesAdapter, null, null, $where, null);
     $indexedModels = array();
     foreach ($models as $gameBadge) {
         $indexedModels[$gameBadge->type] = $gameBadge;
     }
     return $indexedModels;
 }
Example #3
0
 /**
  * Given an Item (Either User or Person),  try to find an existing model. If the model does
  * not exist, create it and populate the Item.
  * @param Item $person
  * @return The found or created model.
  * @throws NotSupportedException
  */
 public static function resolveByPerson(Item $person)
 {
     assert('$person->id > 0');
     assert('$person instanceof Contact || $person instanceof User');
     $searchAttributeData = array();
     $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'person', 'relatedAttributeName' => 'id', 'operatorType' => 'equals', 'value' => $person->getClassId('Item')));
     $searchAttributeData['structure'] = '1';
     $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('GameCoin');
     $where = RedBeanModelDataProvider::makeWhere('GameCoin', $searchAttributeData, $joinTablesAdapter);
     $models = self::getSubset($joinTablesAdapter, null, 2, $where, null);
     if (count($models) > 1) {
         $logContent = 'Duplicate Game Coin for Person: ' . $person->id;
         GamificationUtil::logAndNotifyOnDuplicateGameModel($logContent);
         return $models[0];
     }
     if (count($models) == 0) {
         $gameCoin = new GameCoin();
         $gameCoin->person = $person;
         $gameCoin->value = 0;
         return $gameCoin;
     }
     return $models[0];
 }
Example #4
0
 public function doNotificationSubscribersContainPerson(Item $item)
 {
     foreach ($this->notificationSubscribers as $notificationSubscriber) {
         if ($notificationSubscriber->person->getClassId('Item') == $item->getClassId('Item')) {
             return true;
         }
     }
     return false;
 }
Example #5
0
 /**
  * Given an  Item (Either User or Person),  try to find an existing model for each type. If the model does
  * not exist, create it and populate the Item and type. @return models found or created indexed by type.
  * @param Item $person
  * @param array $levelTypes - Level types
  */
 public static function resolvePersonAndAvailableTypes(Item $person, $levelTypes)
 {
     assert('$person->id > 0');
     assert('$person instanceof Contact || $person instanceof User');
     assert('is_array($levelTypes)');
     $searchAttributeData = array();
     $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'person', 'relatedAttributeName' => 'id', 'operatorType' => 'equals', 'value' => $person->getClassId('Item')));
     $searchAttributeData['structure'] = '1';
     $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('GameLevel');
     $where = RedBeanModelDataProvider::makeWhere('GameLevel', $searchAttributeData, $joinTablesAdapter);
     $models = self::getSubset($joinTablesAdapter, null, null, $where, null);
     $modelsByType = array();
     foreach ($levelTypes as $type) {
         $modelFound = false;
         foreach ($models as $model) {
             if ($model->type == $type) {
                 $modelsByType[$type] = $model;
                 $modelFound = true;
                 break;
             }
         }
         if (!$modelFound) {
             $gameLevel = new GameLevel();
             $gameLevel->type = $type;
             $gameLevel->person = $person;
             $gameLevel->value = 1;
             $modelsByType[$type] = $gameLevel;
         }
     }
     return $modelsByType;
 }
Example #6
0
 /**
  * Get all tasks by kanban type
  * @param int $taskType
  * @param Item $childObjectOfItem
  * @return array of objects
  */
 public static function getAllTasksByType($taskType, Item $childObjectOfItem)
 {
     assert('is_int($taskType)');
     $searchAttributeData = array();
     $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'type', 'operatorType' => 'equals', 'value' => intval($taskType)), 2 => array('attributeName' => 'kanbanRelatedItem', 'operatorType' => 'equals', 'value' => $childObjectOfItem->getClassId('Item')));
     $searchAttributeData['structure'] = '(1 and 2)';
     $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter(get_called_class());
     $where = RedBeanModelDataProvider::makeWhere(get_called_class(), $searchAttributeData, $joinTablesAdapter);
     $models = self::getSubset($joinTablesAdapter, null, null, $where, 'sortOrder ASC');
     return $models;
 }
 /**
  * Given an  Item (Either User or Person),  try to find an existing model for each type. If the model does
  * not exist, create it and populate the Item and type. @return models found or created indexed by type.
  * @param Item $person
  * @param $collectionTypes
  * @return array
  * @throws FailedToSaveModelException
  */
 public static function resolvePersonAndAvailableTypes(Item $person, $collectionTypes)
 {
     assert('$person->id > 0');
     assert('$person instanceof Contact || $person instanceof User');
     assert('is_array($collectionTypes)');
     $searchAttributeData = array();
     $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'person', 'relatedAttributeName' => 'id', 'operatorType' => 'equals', 'value' => $person->getClassId('Item')));
     $searchAttributeData['structure'] = '1';
     $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('GameCollection');
     $where = RedBeanModelDataProvider::makeWhere('GameCollection', $searchAttributeData, $joinTablesAdapter);
     $models = self::getSubset($joinTablesAdapter, null, null, $where, null);
     $modelsByType = array();
     foreach ($collectionTypes as $type) {
         $modelFound = false;
         foreach ($models as $model) {
             if ($model->type == $type) {
                 $modelsByType[$type] = $model;
                 $modelFound = true;
                 break;
             }
         }
         if (!$modelFound) {
             $gameCollectionRules = GameCollectionRulesFactory::createByType($type);
             $gameCollection = new GameCollection();
             $gameCollection->type = $type;
             $gameCollection->person = $person;
             $gameCollection->serializedData = serialize($gameCollectionRules::makeDefaultData());
             $saved = $gameCollection->save();
             if (!$saved) {
                 throw new FailedToSaveModelException();
             }
             $modelsByType[$type] = $gameCollection;
         }
     }
     return $modelsByType;
 }