LogModel::getWhere PHP Method

getWhere() public method

Get log rows by a query.
public getWhere ( array | false $Where = false, string $OrderFields = '', string $OrderDirection = 'asc', boolean $Offset = false, boolean $Limit = false ) : array
$Where array | false The where filter.
$OrderFields string The fields to order by.
$OrderDirection string The order direction.
$Offset boolean The database offset.
$Limit boolean The database limit.
return array Returns a data set.
    public function getWhere($Where = false, $OrderFields = '', $OrderDirection = 'asc', $Offset = false, $Limit = false)
    {
        if ($Offset < 0) {
            $Offset = 0;
        }
        if (isset($Where['Operation'])) {
            Gdn::sql()->whereIn('Operation', (array) $Where['Operation']);
            unset($Where['Operation']);
        }
        $Result = Gdn::sql()->select('l.*')->select('ru.Name as RecordName, iu.Name as InsertName')->from('Log l')->join('User ru', 'l.RecordUserID = ru.UserID', 'left')->join('User iu', 'l.InsertUserID = iu.UserID', 'left')->where($Where)->limit($Limit, $Offset)->orderBy($OrderFields, $OrderDirection)->get()->resultArray();
        // Deserialize the data.
        foreach ($Result as &$Row) {
            $Row['Data'] = dbdecode($Row['Data']);
            if (!$Row['Data']) {
                $Row['Data'] = [];
            }
        }
        return $Result;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * View spam logs.
  *
  * @since 2.0.?
  * @access public
  *
  * @param int $Page Page number.
  */
 public function spam($Page = '')
 {
     $this->permission(array('Garden.Moderation.Manage', 'Moderation.Spam.Manage'), false);
     list($Offset, $Limit) = offsetLimit($Page, 10);
     $this->setData('Title', t('Spam Queue'));
     $Where = array('Operation' => array('Spam'));
     $RecordCount = $this->LogModel->getCountWhere($Where);
     $this->setData('RecordCount', $RecordCount);
     if ($Offset >= $RecordCount) {
         $Offset = $RecordCount - $Limit;
     }
     $Log = $this->LogModel->getWhere($Where, 'LogID', 'Desc', $Offset, $Limit);
     $this->setData('Log', $Log);
     if ($this->deliveryType() == DELIVERY_TYPE_VIEW) {
         $this->View = 'Table';
     }
     $this->addSideMenu('dashboard/log/spam');
     $this->render();
 }