Filter by the latest created

@param      int $nbDays Maximum age of in days

@return     $this|ChildRecordQuery The current query, for fluid interface
195823
public function recentlyCreated($nbDays = 7)
    {
        return $this->addUsingAlias(RecordTableMap::COL_CREATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL);
    }
977954
public function newQuery()
    {
        $this->orderBys = [];
        $this->limit = null;
        $this->offset = null;

        return $this->freshQueryBuilder();
    }
792844
public function recentlyUpdated($nbDays = 7)
    {
        return $this->addUsingAlias(PersonFunctionTableMap::UPDATED_AT, time() - $nbDays * 24 * 60 * 60, Criteria::GREATER_EQUAL);
    }
490000
public function cleanOldEntryLogs($days = null)
	{
	    if(!isset($days))
	    {
	       $days = $this->_configRead('days_to_keep_logs');
	    }

	    if(!empty($days) && $days > 0)
	    {
	        $log_levels_to_keep     = $this->_configRead('log_levels_to_keep');
	        $log_categories_to_keep = $this->_configRead('log_categories_to_keep');

	        /*
	         * Find all EntryLogs that are:
	         * - older than $days_to_keep_logs days
	         * - whose log level is not in $log_levels_to_keep
	         * - whose log category is not in $log_categories_to_keep
	         *
	         * then delete them
	         */

	        $query = TableRegistry::get('Alaxos.LogEntries')->query();
	        $query->delete();

	        $query->where(function($exp) use ($days){
	            return $exp->lte('created', (new Time('-' . $days . ' days'))->toDateTimeString());
	        });

	        if(!empty($log_levels_to_keep))
	        {
	            $query->where(function($exp) use ($log_levels_to_keep){
	                return $exp->not(['log_level_id' => $log_levels_to_keep], ['log_level_id' => 'integer[]']);
	            });
	        }

	        if(!empty($log_categories_to_keep))
	        {
	            $query->where(function($exp) use ($log_categories_to_keep){
	                return $exp->not(['log_category_id IN' => $log_categories_to_keep]);
	            });
	        }

	        //$query->connection()->logQueries(true);
	        //debug($query->__debugInfo()['sql']);

	        $statement = $query->execute();
	        $deleted_total = $statement->rowCount();

	        //$query->connection()->logQueries(false);
	    }
	}
125443
public function setParent(FilterBuilderWithChildren $parent)
    {
        if ($this->parent && $this->parent !== $parent) {
            $this->parent->remove($this);
        }

        $this->parent = $parent;
        $this->parent->add($this);

        return $this;
    }
588787
function getChildren() {
        return $this->guild->channels->filter(function ($channel) {
            return ($channel->parentID === $this->id);
        });
    }
366956
public function getNumberProspectsPerDay($maxDays = 30)
    {
    	$select = $this->tableGateway->getSql()->select();

    	$select->columns(array(new \Zend\Db\Sql\Expression('COUNT("pros_id") AS nb'), "pros_contact_date"));
    	$select->group("pros_contact_date");
    	$select->limit($maxDays);
    	
    	$resultSet = $this->tableGateway->selectWith($select);
    
    	return $resultSet;
    }
1327452
public function findWithBase($baseRecords)
	{
		if(!is_array($baseRecords))
			$baseRecords=array($baseRecords);
		if(is_string($this->_table->primaryKey))
		{
			foreach($baseRecords as $baseRecord)
				$this->records[$baseRecord->{$this->_table->primaryKey}]=$baseRecord;
		}
		else
		{
			foreach($baseRecords as $baseRecord)
			{
				$pk=array();
				foreach($this->_table->primaryKey as $name)
					$pk[$name]=$baseRecord->$name;
				$this->records[serialize($pk)]=$baseRecord;
			}
		}

		$query=new CJoinQuery($this);
		$this->buildQuery($query);
		if(count($query->joins)>1)
			$this->runQuery($query);
		foreach($this->children as $child)
			$child->find();

		foreach($this->stats as $stat)
			$stat->query();
	}
163453
protected function removeDeletedFsChildrenFromDb($dbChildren)
    {
        $existingChildren = [];

        // First delete all children that do not exist in fs
        foreach ($dbChildren as $child) {

            if (!$this->filesystem->exists($child->getPath())) {
                $this->nodeRepository->delete($child);
                continue;
            }
            $existingChildren[] = $child;
        }

        return $existingChildren;
    }
400135
public function expiresIn($days = 14)
    {
        $this->expiry = Carbon::now(config('app.timezone'))->addDays($days)->endOfDay();

        return $this;
    }
88625
public function filterByIds($ids)
    {
        $this->getInstance()->andWhere($this->mainAlias.'.id IN (:ids)')->setParameter('ids', $ids);

        return $this;
    }
993576
public function create_children(&$records, &$children, $thisrecordid) {
        //keys where value is $thisrecordid
        $thischildren = array_keys($children, $thisrecordid);
        foreach ($thischildren as $child) {
            $thisclass = get_class($this);
            $newlistitem = new $thisclass($records[$child], $this->children, $this->attributes);
            $this->children->add_item($newlistitem);
            $newlistitem->create_children($records, $children, $records[$child]->id);
        }
    }
1290133
public function each($cb)
    {
        foreach ($this->rows as $index=>$row) {
            $result = $cb($row, $index);
            if (is_array($result)) {
                $this->rows[$index] = $result;
            } else if ($result===false) {
                break;
            }
        }
        return $this;
    }
712252
public function newQuery($excludeDeleted = true)
	{
		$builder = $this->newActiveRecordBuilder($this->newBaseQueryBuilder());

		// Once we have the query builders, we will set the model instances so the
		// builder can easily access any information it may need from the model
		// while it is constructing and executing various queries against it.
		$builder->setModel($this)->with($this->with);

		if ($excludeDeleted && $this->softDelete)
		{
			$builder->whereNull($this->getQualifiedDeletedAtColumn());
		}

		return $builder;
	}
19152
public function setCreationDatetime($creation_datetime) : CNabuDataObject
    {
        if ($creation_datetime === null) {
            throw new ENabuCoreException(
                    ENabuCoreException::ERROR_NULL_VALUE_NOT_ALLOWED_IN,
                    array("\$creation_datetime")
            );
        }
        $this->setValue('nb_user_creation_datetime', $creation_datetime);
        
        return $this;
    }
1052485
public function filter(array $filters)
	{
		foreach ($filters as $filter) {
			if ($filter->isValueSet()) {
				if ($filter->hasConditionCallback()) {
					Callback::invokeArgs(
						$filter->getConditionCallback(),
						[$this->data_source, $filter->getValue()]
					);
				} else {
					if ($filter instanceof Filter\FilterText) {
						$this->applyFilterText($filter);
					} elseif ($filter instanceof Filter\FilterMultiSelect) {
						$this->applyFilterMultiSelect($filter);
					} elseif ($filter instanceof Filter\FilterSelect) {
						$this->applyFilterSelect($filter);
					} elseif ($filter instanceof Filter\FilterDate) {
						$this->applyFilterDate($filter);
					} elseif ($filter instanceof Filter\FilterDateRange) {
						$this->applyFilterDateRange($filter);
					} elseif ($filter instanceof Filter\FilterRange) {
						$this->applyFilterRange($filter);
					}
				}
			}
		}

		return $this;
	}
380047
public function setMaxResults($maxResults)
    {
        $this->limit = $maxResults;
        
        if( $this->query instanceof Query )
        {
            $this->query->setMaxResults($maxResults);
        }

        return $this;
    }