Пример #1
0
 public function rewind()
 {
     $this->groups = Ginq::from($this->it)->toLookup($this->groupingKeySelector, $this->elementSelector, $this->eqComparer)->getIterator();
     $this->groups->rewind();
     if ($this->valid()) {
         $this->fetch();
     }
 }
 public function getUserByPk($id)
 {
     return Ginq::from($this->getAll())->where(function ($user) use($id) {
         return $user['id'] == $id;
     })->select(function ($user) {
         return $user;
     })->firstOrElse(null);
 }
Пример #3
0
 /**
  * @return \Iterator
  */
 public function getIterator()
 {
     $dict = $this->dict;
     $it = Ginq::from($dict->keys())->select(function ($key) use(&$dict) {
         return new GroupingGinq(IteratorUtil::iterator($dict->get($key)), $key);
     }, ValueSelector::getInstance())->getIterator();
     return $it;
 }
 public static function getOutsourcingByProjectKey($projectKey)
 {
     return Ginq::from(self::getAllData())->where(function ($row) use($projectKey) {
         return $row->project_key === $projectKey;
     })->select(function ($row) {
         return $row->outsourcing_cost;
     })->firstOrElse(0);
 }
Пример #5
0
 public function testGetProjectIds()
 {
     try {
         $projects = $this->backlog->projects->get(['archived' => false, 'all' => true]);
         $projecttIds = Ginq::from($projects)->select(function ($project) {
             return $project['id'];
         })->toArray();
     } catch (BacklogException $e) {
         echo $e->getMessage();
     } finally {
         $this->assertNotNull($projects);
     }
 }
 public function getProjectsSumData()
 {
     $cache = Cache::getAdapter();
     $result = $cache->getItem(self::CACHE_KEY_SUM, $success);
     if ($success) {
         return unserialize($result);
     } else {
         $projectRows = Factory::getInstance()->getProjectRepository()->getAll();
         $projects = Ginq::from($projectRows)->orderBy(function ($projectRow) {
             return $projectRow['archived'] == true ? 1 : 0;
         })->thenBy(function ($projectRow) {
             return $projectRow['id'];
         })->renum()->toArray();
         $result = Ginq::from($projects)->select(function ($project) {
             $issues = Factory::getInstance()->getIssueRepository()->getIssueByProjectId($project['id']);
             $estimatedHours = Ginq::from($issues)->sum(function ($issue) {
                 return $issue['estimatedHours'];
             });
             $actualHours = Ginq::from($issues)->sum(function ($issue) {
                 return $issue['actualHours'];
             });
             $backlogUrl = 'https://' . AbstractRepository::$spaceName . '.backlog.jp/gantt/' . $project['projectKey'];
             $projectSumInfo = new ProjectSumInfo();
             $projectSumInfo->setProjectName($project['name']);
             $archived = $project['archived'] === true ? '◯' : '';
             $projectSumInfo->setArchived($archived);
             $orderAmount = OrderAmount::getOrderAmountByProjectKey($project['projectKey']);
             $totalManHour = OrderAmount::getTotalManHourByProjectKey($project['projectKey']);
             $projectSumInfo->setTotalManHour($totalManHour);
             $outsourcingCost = OrderAmount::getOutsourcingByProjectKey($project['projectKey']);
             $projectSumInfo->setOutsourcingCost($outsourcingCost);
             $projectSumInfo->setOrderAmount($orderAmount);
             $projectSumInfo->setSumEstimatedHours($estimatedHours);
             $projectSumInfo->setSumActualHours($actualHours);
             $estimatedCost = (int) $estimatedHours * Cost::getCostPerHourPerPerson();
             $projectSumInfo->setSumEstimatedCost($estimatedCost);
             $actualCost = $actualHours * Cost::getCostPerHourPerPerson();
             $projectSumInfo->setSumActualCost($actualCost);
             $projectSumInfo->setBackLogUrl($backlogUrl);
             $projectSumInfo->setCostCompare($orderAmount - $actualCost - $outsourcingCost);
             return $projectSumInfo;
         })->toArray();
         $cache->setItem(self::CACHE_KEY_SUM, serialize($result));
     }
     return $result;
 }
Пример #7
0
 /**
  * generate
  *
  */
 public static function generate($data, $fields, $options = array())
 {
     $options = array_merge(self::$options, $options);
     if ($fields !== array_values($fields)) {
         $header = array_keys($fields);
         array_unshift($data, $header);
     }
     Ginq::register('Ginq\\GinqCsv');
     return Ginq::from($data)->select(function ($v, $k) use($fields) {
         if ($k === 0 && $fields !== array_values($fields)) {
             return $v;
         }
         $line = array();
         foreach ($fields as $pointer) {
             $line[] = Hash::get($v, $pointer);
         }
         return $line;
     })->toCsv($options);
 }
Пример #8
0
 /**
  * @JMS\VirtualProperty
  * @JMS\SerializedName("capacity")
  *
  * @return integer
  */
 public function computeCapacity()
 {
     return Ginq::from($this->roleConfigs)->map(function (RoleConfig $roleConfig) {
         return $roleConfig->getCount();
     })->sum();
 }
Пример #9
0
 /**
  * @param \Iterator $it
  * @param \Ginq\Core\Comparer $comparer
  */
 public function __construct($it, $comparer)
 {
     $this->comparer = $comparer;
     parent::__construct($it);
 }
 public function getMemberMonthDetailData($userId)
 {
     $cache = Cache::getAdapter();
     $result = $cache->getItem(self::CACHE_KEY_MONTH_USER . '-' . $userId, $success);
     if ($success) {
         return unserialize($result);
     } else {
         $issues = Factory::getInstance()->getIssueRepository()->getIssueByProjectIdAndStartMonthDate($userId);
         $result = Ginq::from($issues)->select(function ($issue) {
             $project = Factory::getInstance()->getProjectRepository()->getProjectByPk($issue['projectId']);
             $userDetail = new UserDetail();
             $userDetail->setProjectName($project['name']);
             $userDetail->setThisWeekEstimatedHours($issue['estimatedHours']);
             $userDetail->setThisWeekActualHours($issue['actualHours']);
             $userDetail->setSummary($issue['summary']);
             $userDetail->setPriority($issue['priority']['name']);
             $userDetail->setStatus($issue['status']['name']);
             return $userDetail;
         })->toArray();
         $cache->setItem(self::CACHE_KEY_MONTH_USER . '-' . $userId, serialize($result));
     }
     return $result;
 }
Пример #11
0
 public static function getConfigData($key)
 {
     return Ginq::from(self::getAllData())->select(function ($row) use($key) {
         return $row->{$key};
     })->firstOrElse('');
 }
Пример #12
0
 public function rewind()
 {
     $this->outer->rewind();
     $this->lookup = Ginq::from($this->inner)->toLookup($this->innerCompareKeySelector, ValueSelector::getInstance());
     $this->fetchIfValid();
 }
Пример #13
0
 /**
  * @JMS\VirtualProperty
  * @JMS\SerializedName("alive")
  * @JMS\Groups({"finished"})
  *
  * @return bool | null
  */
 public function isAlive()
 {
     if (!$this->game->hasFinished()) {
         return true;
     }
     $myVotedCount = $this->voteSources->count();
     $players = $this->game->getGamePlayers();
     $maxVotedCount = Ginq::from($players)->map(function (GamePlayer $player) {
         return $player->getVoteSources()->count();
     })->max();
     return $myVotedCount < $maxVotedCount;
 }
Пример #14
0
 /**
  * @JMS\VirtualProperty
  * @JMS\SerializedName("score")
  * @JMS\Groups({"Default", "getRoom"})
  *
  * @return int
  */
 public function computeScore()
 {
     return Ginq::from($this->getGamePlayers())->sum(function (GamePlayer $gamePlayer) {
         return $gamePlayer->computeReward();
     });
 }
Пример #15
0
 public static function register($className)
 {
     $ref = new \ReflectionClass($className);
     //echo "$className";
     $funcNames = Ginq::from($ref->getMethods(\ReflectionMethod::IS_STATIC))->where(function ($m) {
         /** @var $m \ReflectionMethod  */
         return $m->isPublic();
     })->where(function ($m) {
         /** @var $m \ReflectionMethod  */
         /** @var $p \ReflectionParameter */
         $p = Ginq::from($m->getParameters())->firstOrElse(false);
         if ($p === false) {
             return false;
         }
         $c = $p->getClass();
         return $c->getName() === 'Ginq\\Ginq' or $c->isSubclassOf('Ginq\\Ginq');
     })->select(function ($m) {
         /** @var $m \ReflectionMethod  */
         return $m->getName();
     });
     foreach ($funcNames as $func) {
         self::$registeredFunctions[$func] = array($className, $func);
     }
 }
Пример #16
0
 public function rewind()
 {
     $outerKeySelector = $this->outerKeySelector;
     $lookup = Ginq::from($this->inner)->toLookup($this->innerKeySelector, ValueSelector::getInstance(), $this->eqComparer);
     $this->it = new SelectManyWithJoinIterator($this->outer, new DelegateSelector(function ($v, $k) use($lookup, $outerKeySelector) {
         return $lookup->get($outerKeySelector->select($v, $k));
     }), $this->valueJoinSelector, $this->keyJoinSelector);
     $this->it->rewind();
 }
Пример #17
0
 private function shuffleRoles()
 {
     $roles = Ginq::from($this->room->getRoleConfigs())->flatMap(function (RoleConfig $roleConfig) {
         return Ginq::repeat($roleConfig->getRole(), $roleConfig->getCount());
     })->toList();
     shuffle($roles);
     return $roles;
 }
 public function getProjectByPk($id)
 {
     return Ginq::from($this->getAll())->where(function ($row) use($id) {
         return $row['id'] == $id;
     })->firstOrElse(null);
 }
Пример #19
0
 public static function register()
 {
     Ginq::register(get_called_class());
 }