ActivityModel::getWhere PHP Метод

getWhere() публичный Метод

Events: AfterGet.
public getWhere ( array $Where = [], string $orderFields = '', string $orderDirection = '', integer | boolean $Limit = false, integer | boolean $Offset = false ) : Gdn_DataSet
$Where array A filter suitable for passing to Gdn_SQLDriver::Where().
$orderFields string A comma delimited string to order the data.
$orderDirection string One of **asc** or **desc**.
$Limit integer | boolean The database limit.
$Offset integer | boolean The database offset.
Результат Gdn_DataSet SQL results.
    public function getWhere($Where = [], $orderFields = '', $orderDirection = '', $Limit = false, $Offset = false)
    {
        if (is_string($Where)) {
            deprecated('ActivityModel->getWhere($key, $value)', 'ActivityModel->getWhere([$key => $value])');
            $Where = [$Where => $orderFields];
            $orderFields = '';
        }
        if (is_numeric($orderFields)) {
            deprecated('ActivityModel->getWhere($where, $limit)');
            $Limit = $orderFields;
            $orderFields = '';
        }
        if (is_numeric($orderDirection)) {
            deprecated('ActivityModel->getWhere($where, $limit, $offset)');
            $Offset = $orderDirection;
            $orderDirection = '';
        }
        $Limit = $Limit ?: 30;
        $Offset = $Offset ?: 0;
        $orderFields = $orderFields ?: 'a.DateUpdated';
        $orderDirection = $orderDirection ?: 'desc';
        // Add the basic activity query.
        $this->SQL->select('a2.*')->select('t.FullHeadline, t.ProfileHeadline, t.AllowComments, t.ShowIcon, t.RouteCode')->select('t.Name', '', 'ActivityType')->from('Activity a')->join('Activity a2', 'a.ActivityID = a2.ActivityID')->join('ActivityType t', 'a2.ActivityTypeID = t.ActivityTypeID');
        // Add prefixes to the where.
        foreach ($Where as $Key => $Value) {
            if (strpos($Key, '.') === false) {
                $Where['a.' . $Key] = $Value;
                unset($Where[$Key]);
            }
        }
        $Result = $this->SQL->where($Where)->orderBy($orderFields, $orderDirection)->limit($Limit, $Offset)->get();
        self::getUsers($Result->resultArray());
        Gdn::userModel()->joinUsers($Result->resultArray(), ['ActivityUserID', 'RegardingUserID'], ['Join' => ['Name', 'Email', 'Gender', 'Photo']]);
        $this->calculateData($Result->resultArray());
        $this->EventArguments['Data'] =& $Result;
        $this->fireEvent('AfterGet');
        return $Result;
    }

Usage Example

 /**
  * Grabs all new notifications and adds them to the sender's inform queue.
  *
  * This method gets called by dashboard's hooks file to display new
  * notifications on every pageload.
  *
  * @since 2.0.18
  * @access public
  *
  * @param Gdn_Controller $Sender The object calling this method.
  */
 public static function informNotifications($Sender)
 {
     $Session = Gdn::session();
     if (!$Session->isValid()) {
         return;
     }
     $ActivityModel = new ActivityModel();
     // Get five pending notifications.
     $Where = array('NotifyUserID' => Gdn::session()->UserID, 'Notified' => ActivityModel::SENT_PENDING);
     // If we're in the middle of a visit only get very recent notifications.
     $Where['DateUpdated >'] = Gdn_Format::toDateTime(strtotime('-5 minutes'));
     $Activities = $ActivityModel->getWhere($Where, 0, 5)->resultArray();
     $ActivityIDs = array_column($Activities, 'ActivityID');
     $ActivityModel->setNotified($ActivityIDs);
     $Sender->EventArguments['Activities'] =& $Activities;
     $Sender->fireEvent('InformNotifications');
     foreach ($Activities as $Activity) {
         if ($Activity['Photo']) {
             $UserPhoto = anchor(img($Activity['Photo'], array('class' => 'ProfilePhotoMedium')), $Activity['Url'], 'Icon');
         } else {
             $UserPhoto = '';
         }
         $Excerpt = Gdn_Format::plainText($Activity['Story']);
         $ActivityClass = ' Activity-' . $Activity['ActivityType'];
         $Sender->informMessage($UserPhoto . Wrap($Activity['Headline'], 'div', array('class' => 'Title')) . Wrap($Excerpt, 'div', array('class' => 'Excerpt')), 'Dismissable AutoDismiss' . $ActivityClass . ($UserPhoto == '' ? '' : ' HasIcon'));
     }
 }
All Usage Examples Of ActivityModel::getWhere