Exemplo n.º 1
0
  /** After the Eloquent has run on the attributes and returned an eloquent collection,
   * this method takes the collection and $querySets as above, 
   * [$key=>['val'=>$val,'crit'=>$crit,'parm0'=>$parm0.....
   * @param Eloquent Collection $collection
   * @param array $querySets or null to take from local object
   */
  public function filterOnMethods(Collection $collection, $matchObjs=null) {
    //pkdebug("Yes, trying to filter.");
    if (!$matchObjs || !is_arrayish($matchObjs)) $matchObjs = $this->getMatchObjs();
    if (!$matchObjs || !is_arrayish($matchObjs)) return $collection;
    $numpre = count($matchObjs);
    $modelName = $collection-> getQueueableClass();
    //pkdebug("The num of match objs before: The QC is: [ $modelName ], the num $numpre -- is mine here?");
    //foreach ($matchObjs as $ma) { if ($ma->compfield == 'assetdebtratio') pkdebug("After buildQS, The MA is: ", $ma); }



    $trimmedMatches = PkMatch::filterMatchArr($matchObjs,
        ['modelName'=>$modelName,'modelMethods'=>true,'emptyCrit'=>true]);
    //pkdebug("The Trimmed Match Collection:", $trimmedMatches);
    if (!count($trimmedMatches)) return $collection;
    $trimmedCollection = $collection->reject(function ($item) use ($trimmedMatches) {
      foreach($trimmedMatches as $match) {
        $methodName = $match->method;
        $methodResult = $item->$methodName();
        $passed = $match->satisfy($methodResult);
        $reject = !$passed;
        if ($reject) return $reject;
      } ## Passed all the criteria; don't reject
      return false;
    });
    return $trimmedCollection;
  }
 /**
  * Retrieve only those conferences which should be tweeted.
  *
  * @param \Illuminate\Database\Eloquent\Collection $conferences
  *
  * @return \Illuminate\Database\Eloquent\Collection
  */
 private function tweetable($conferences)
 {
     return $conferences->reject(function ($conference) {
         $starts = $conference->cfp_starts_at;
         $ends = $conference->cfp_ends_at;
         return $starts->isSameDay($ends);
     });
 }