/** * @param $partialName * @param $pageSize * @param null|string $moduleClassName * @param null|string $type * @return Array of SavedReport models */ public static function getReportsByPartialName($partialName, $pageSize, $moduleClassName = null, $type = null) { assert('is_string($partialName)'); assert('is_int($pageSize)'); assert('is_string($moduleClassName) || $moduleClassName == null'); assert('is_string($type) || $type == null'); $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'name', 'operatorType' => 'contains', 'value' => $partialName)); $clauseCount = 2; if ($moduleClassName != null) { $searchAttributeData['clauses'][$clauseCount] = array('attributeName' => 'moduleClassName', 'operatorType' => 'equals', 'value' => $moduleClassName); $clauseCount++; } if ($type != null) { $searchAttributeData['clauses'][$clauseCount] = array('attributeName' => 'type', 'operatorType' => 'equals', 'value' => $type); } if ($clauseCount == 1) { $searchAttributeData['structure'] = '(1)'; } elseif ($clauseCount == 2) { $searchAttributeData['structure'] = '(1 and 2)'; } else { $searchAttributeData['structure'] = '(1 and 2 and 3)'; } $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('SavedReport'); $where = RedBeanModelDataProvider::makeWhere('SavedReport', $searchAttributeData, $joinTablesAdapter); return SavedReport::getSubset($joinTablesAdapter, null, $pageSize, $where, 'name'); }
protected function preFilter($filterChain) { if (isset($_POST['ajax'])) { return true; } $modelClassName = $this->modelClassName; if ($modelClassName == null) { $modelClassName = $this->controller->getModule()->getPrimaryModelName(); } if ($this->stateMetadataAdapterClassName != null) { $stateClassName = $this->stateMetadataAdapterClassName; $metadata = array('clauses' => array(), 'structure' => ''); $stateMetadataAdapter = new $stateClassName($metadata); $metadata = $stateMetadataAdapter->getAdaptedDataProviderMetadata(); $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter($modelClassName); $where = RedBeanModelDataProvider::makeWhere($modelClassName, $metadata, $joinTablesAdapter); } else { $joinTablesAdapter = null; $where = null; } if ($modelClassName::getCount($joinTablesAdapter, $where) != 0) { return true; } $messageViewClassName = $this->getMessageViewClassName(); if ($messageViewClassName == null) { $messageViewClassName = $this->controller->getModule()->getPluralCamelCasedName() . 'ZeroModelsYetView'; } $messageView = new $messageViewClassName($this->resolveMessageControllerId(), $this->resolveMessageModuleId(), $modelClassName); $this->resolveAndRenderView($messageView); return false; }
public function getUnreadCountForCurrentUser() { $searchAttributeData = $this->getMetadataForUnreadForCurrentUser(); $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Mission'); $where = RedBeanModelDataProvider::makeWhere('Mission', $searchAttributeData, $joinTablesAdapter); return Mission::getCount($joinTablesAdapter, $where, 'Mission', true); }
/** * @param $partialName * @param $pageSize * @param null|string $moduleClassName * @param null|string $type * @return Array of SavedReport models */ public static function getEmailTemplatesByPartialName($partialName, $pageSize, $modelClassName = null, $type = null) { $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'type', 'operatorType' => 'equals', 'value' => intval($type)), 2 => array('attributeName' => 'modelClassName', 'operatorType' => 'equals', 'value' => $modelClassName), 3 => array('attributeName' => 'isDraft', 'operatorType' => 'equals', 'value' => intval(false)), 4 => array('attributeName' => 'name', 'operatorType' => 'contains', 'value' => $partialName)); $searchAttributeData['structure'] = '1 and 2 and 3 and 4'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('EmailTemplate'); $where = RedBeanModelDataProvider::makeWhere('EmailTemplate', $searchAttributeData, $joinTablesAdapter); return EmailTemplate::getSubset($joinTablesAdapter, null, $pageSize, $where, 'name'); }
public static function getIdsByUsersMemberOfGroup($groupId) { $groupId = intval($groupId); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'users', 'relatedModelData' => array('attributeName' => 'groups', 'relatedAttributeName' => 'id', 'operatorType' => 'equals', 'value' => $groupId))); $searchAttributeData['structure'] = '1'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter(get_called_class()); $where = RedBeanModelDataProvider::makeWhere(get_called_class(), $searchAttributeData, $joinTablesAdapter); return static::getSubsetIds($joinTablesAdapter, null, null, $where); }
/** * Given a related model id return a list of check items models. * @param integer $taskId */ public static function getByTask($taskId) { assert('is_int($taskId)'); $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('TaskCheckListItem'); $orderBySortColumnName = RedBeanModelDataProvider::resolveSortAttributeColumnName('TaskCheckListItem', $joinTablesAdapter, 'sortOrder'); $orderByColumnNameFallback = RedBeanModelDataProvider::resolveSortAttributeColumnName('TaskCheckListItem', $joinTablesAdapter, 'id'); $where = "task_id = '" . $taskId . "'"; $orderBy = $orderBySortColumnName . 'asc, ' . $orderByColumnNameFallback . ' desc'; return self::getSubset($joinTablesAdapter, null, null, $where, $orderBy); }
/** * For a given partialName, run search by partial name and retrieve account models. * @param string $partialName * @param null|int $pageSize */ public static function getAccountsByPartialName($partialName, $pageSize = null) { assert('is_string($partialName)'); $metadata = array(); $metadata['clauses'] = array(1 => array('attributeName' => 'name', 'operatorType' => 'contains', 'value' => $partialName)); $metadata['structure'] = '1'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Account'); $where = RedBeanModelDataProvider::makeWhere('Account', $metadata, $joinTablesAdapter); return Account::getSubset($joinTablesAdapter, null, $pageSize, $where); }
/** * For a given email address, run search by email address and retrieve account models. */ public static function getAccountsByAnyEmailAddress($emailAddress, $pageSize = null) { assert('is_string($emailAddress)'); $metadata = array(); $metadata['clauses'] = array(1 => array('attributeName' => 'primaryEmail', 'relatedAttributeName' => 'emailAddress', 'operatorType' => 'equals', 'value' => $emailAddress), 2 => array('attributeName' => 'secondaryEmail', 'relatedAttributeName' => 'emailAddress', 'operatorType' => 'equals', 'value' => $emailAddress)); $metadata['structure'] = '(1 or 2)'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Account'); $where = RedBeanModelDataProvider::makeWhere('Account', $metadata, $joinTablesAdapter); return Account::getSubset($joinTablesAdapter, null, $pageSize, $where); }
/** * @param string $type * @param null|int $pageSize */ public static function getByType($type, $pageSize = null) { assert('is_string($type)'); $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'type', 'operatorType' => 'equals', 'value' => $type)); $searchAttributeData['structure'] = '1'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter(get_called_class()); $where = RedBeanModelDataProvider::makeWhere(get_called_class(), $searchAttributeData, $joinTablesAdapter); return self::getSubset($joinTablesAdapter, null, $pageSize, $where, null); }
public static function getAllByFolderType($type) { assert('is_string($type)'); $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'folder', 'relatedAttributeName' => 'type', 'operatorType' => 'equals', 'value' => $type)); $searchAttributeData['structure'] = '1'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('EmailMessage'); $where = RedBeanModelDataProvider::makeWhere('EmailMessage', $searchAttributeData, $joinTablesAdapter); return self::getSubset($joinTablesAdapter, null, null, $where, null); }
public static function getCountByUser(User $user) { assert('$user->id > 0'); $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'owner', 'relatedAttributeName' => 'id', 'operatorType' => 'equals', 'value' => $user->id)); $searchAttributeData['structure'] = '1'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Notification'); $where = RedBeanModelDataProvider::makeWhere('Notification', $searchAttributeData, $joinTablesAdapter); return self::getCount($joinTablesAdapter, $where, null, true); }
/** * Given a user, retrieval all notifications for that user, sorted desc by Id * @param User $user */ public static function getAllByUser(User $user) { assert('$user->id > 0'); $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'user', 'relatedAttributeName' => 'id', 'operatorType' => 'equals', 'value' => $user->id)); $searchAttributeData['structure'] = '1'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('GameNotification'); $where = RedBeanModelDataProvider::makeWhere('GameNotification', $searchAttributeData, $joinTablesAdapter); $models = self::getSubset($joinTablesAdapter, null, null, $where, 'gamenotification.id asc'); return $models; }
/** * @param User $user * @param string $viewClassName */ public static function getByOwnerAndViewClassName(User $user, $viewClassName) { assert('$user->id > 0'); assert('is_string($viewClassName)'); $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'owner', 'operatorType' => 'equals', 'value' => $user->id), 2 => array('attributeName' => 'viewClassName', 'operatorType' => 'equals', 'value' => $viewClassName)); $searchAttributeData['structure'] = '1 and 2'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('SavedSearch'); $where = RedBeanModelDataProvider::makeWhere('SavedSearch', $searchAttributeData, $joinTablesAdapter); return self::getSubset($joinTablesAdapter, null, null, $where, null); }
/** * Given a related model type, a related model id, and a page size, return a list of comment models. * @param string $type * @param integer $relatedId * @param integer $pageSize */ public static function getCommentsByRelatedModelTypeIdAndPageSize($type, $relatedId, $pageSize) { assert('is_string($type)'); assert('is_int($relatedId)'); assert('is_int($pageSize) || $pageSize = null'); $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Comment'); $orderByColumnName = RedBeanModelDataProvider::resolveSortAttributeColumnName('Comment', $joinTablesAdapter, 'createdDateTime'); $where = "relatedmodel_type = '" . strtolower($type) . "' AND relatedmodel_id = '" . $relatedId . "'"; $orderBy = $orderByColumnName . ' desc'; return self::getSubset($joinTablesAdapter, null, $pageSize, $where, $orderBy); }
/** * @param $pageSize * @return array of WorkflowMessageInQueue models */ public static function getModelsToProcess($pageSize) { assert('is_int($pageSize)'); $timeStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time()); $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'processDateTime', 'operatorType' => 'lessThan', 'value' => $timeStamp)); $searchAttributeData['structure'] = '1'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('WorkflowMessageInQueue'); $where = RedBeanModelDataProvider::makeWhere('WorkflowMessageInQueue', $searchAttributeData, $joinTablesAdapter); return self::getSubset($joinTablesAdapter, null, $pageSize, $where, null); }
public static function getModelsTResolveToJobQueue($pageSize, $offset, $modelClassName, $timeStamp) { assert('is_int($pageSize) || $pageSize == null'); assert('is_int($offset)'); assert('is_string($modelClassName)'); assert('is_int($timeStamp)'); $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'processDateTime', 'operatorType' => 'greaterThan', 'value' => DateTimeUtil::convertTimestampToDbFormatDateTime($timeStamp))); $searchAttributeData['structure'] = '1'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter($modelClassName); $where = RedBeanModelDataProvider::makeWhere($modelClassName, $searchAttributeData, $joinTablesAdapter); return $modelClassName::getSubset($joinTablesAdapter, $offset, $pageSize, $where, null); }
protected function deleteRelatedFileContentIfNotRelatedToAnyOtherFileModel() { $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'fileContent', 'relatedModelData' => array('attributeName' => 'id', 'operatorType' => 'equals', 'value' => $this->fileContent->id))); $searchAttributeData['structure'] = '1'; $class = get_class($this); $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter($class); $where = RedBeanModelDataProvider::makeWhere($class, $searchAttributeData, $joinTablesAdapter); if (static::getCount($joinTablesAdapter, $where, $class) == 1) { return $this->fileContent->delete(); } return true; }
/** * Get all imports where the modifiedDateTime was more than 1 week ago. Then * delete the imports. * (non-PHPdoc) * @see BaseJob::run() */ public function run() { $oneWeekAgoTimeStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 60 * 60 * 24 * 7); $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'modifiedDateTime', 'operatorType' => 'lessThan', 'value' => $oneWeekAgoTimeStamp)); $searchAttributeData['structure'] = '1'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Import'); $where = RedBeanModelDataProvider::makeWhere('Import', $searchAttributeData, $joinTablesAdapter); $importModels = Import::getSubset($joinTablesAdapter, null, self::$pageSize, $where, null); foreach ($importModels as $import) { $import->delete(); } return true; }
/** * Get by activity items casted down * @param int $relationItemId * @return integer */ public static function getByActivityItemsCastedDown($relationItemId) { $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'activityItems', 'relatedAttributeName' => 'id', 'operatorType' => 'equals', 'value' => intval($relationItemId))); $searchAttributeData['structure'] = '1'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter(get_called_class()); $where = RedBeanModelDataProvider::makeWhere(get_called_class(), $searchAttributeData, $joinTablesAdapter); $models = self::getSubset($joinTablesAdapter, null, null, $where, null); if (count($models) == 0) { return null; } else { return $models; } }
public static function getUsersByEmailAddress($emailAddress, $operatorType = null) { assert('is_string($emailAddress)'); assert('$operatorType == null || is_string($operatorType)'); if ($operatorType == null) { $operatorType = 'equals'; } $metadata = array(); $metadata['clauses'] = array(1 => array('attributeName' => 'primaryEmail', 'relatedAttributeName' => 'emailAddress', 'operatorType' => $operatorType, 'value' => $emailAddress)); $metadata['structure'] = '(1)'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('User'); $where = RedBeanModelDataProvider::makeWhere('User', $metadata, $joinTablesAdapter); $users = User::getSubset($joinTablesAdapter, null, null, $where); return $users; }
public function run() { $timestamp = time() - static::DRAFT_LIFE_TIME_IN_DAYS * 24 * 60 * 60; $dateTime = DateTimeUtil::convertTimestampToDbFormatDateTime($timestamp); $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'createdDateTime', 'operatorType' => 'lessThan', 'value' => $dateTime), 2 => array('attributeName' => 'isDraft', 'operatorType' => 'equals', 'value' => 1)); $searchAttributeData['structure'] = '1 and 2'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('EmailTemplate'); $where = RedBeanModelDataProvider::makeWhere('EmailTemplate', $searchAttributeData, $joinTablesAdapter); $models = EmailTemplate::getSubset($joinTablesAdapter, null, null, $where, null); foreach ($models as $model) { $model->delete(); } return true; }
/** * * (non-PHPdoc) * @see BaseJob::run() */ public function run() { $box = EmailBox::resolveAndGetByName(EmailBox::NOTIFICATIONS_NAME); $oneWeekAgoTimeStamp = DateTimeUtil::convertTimestampToDbFormatDateTime(time() - 60 * 60 * 24 * 7); $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'modifiedDateTime', 'operatorType' => 'lessThan', 'value' => $oneWeekAgoTimeStamp), 2 => array('attributeName' => 'folder', 'relatedAttributeName' => 'type', 'operatorType' => 'equals', 'value' => EmailFolder::TYPE_SENT), 3 => array('attributeName' => 'folder', 'relatedAttributeName' => 'emailBox', 'operatorType' => 'equals', 'value' => $box->id)); $searchAttributeData['structure'] = '1 and 2 and 3'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('EmailMessage'); $where = RedBeanModelDataProvider::makeWhere('EmailMessage', $searchAttributeData, $joinTablesAdapter); $emailMessageModels = EmailMessage::getSubset($joinTablesAdapter, null, self::$pageSize, $where, null); foreach ($emailMessageModels as $emailMessage) { $emailMessage->delete(); } return true; }
/** * For a given email find user. * Function consider that user sent email to dropbox (To, CC or BCC), * or forwarded email to dropbox, via his email client. * @param ImapMessage $emailMessage * @return User $user */ public static function resolveOwnerOfEmailMessage(ImapMessage $emailMessage) { if (isset($emailMessage->fromEmail) && $emailMessage->fromEmail != '') { $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'primaryEmail', 'relatedAttributeName' => 'emailAddress', 'operatorType' => 'equals', 'value' => $emailMessage->fromEmail)); $searchAttributeData['structure'] = '1'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('User'); $where = RedBeanModelDataProvider::makeWhere('User', $searchAttributeData, $joinTablesAdapter); $models = User::getSubset($joinTablesAdapter, null, null, $where, null); } if (count($models) == 1) { return $models[0]; } else { throw new NotFoundException(); } }
/** * Given a Item (Either User or Person), Try to find an existing models and index the returning array by * badge type. * @param Item $person */ public static function getAllByPersonIndexedByType(Item $person) { assert('$person->id > 0'); assert('$person instanceof Contact || $person instanceof User'); $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'person', 'relatedAttributeName' => 'id', 'operatorType' => 'equals', 'value' => $person->getClassId('Item'))); $searchAttributeData['structure'] = '1'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('GameBadge'); $where = RedBeanModelDataProvider::makeWhere('GameBadge', $searchAttributeData, $joinTablesAdapter); $models = self::getSubset($joinTablesAdapter, null, null, $where, null); $indexedModels = array(); foreach ($models as $gameBadge) { $indexedModels[$gameBadge->type] = $gameBadge; } return $indexedModels; }
/** * if count is greater than 1, return first, since then eventually this will clean out the jobs in process over time. * @param string $type * @return mixed * @throws NotFoundException */ public static function getByType($type) { assert('is_string($type) && $type != ""'); $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'type', 'operatorType' => 'equals', 'value' => $type)); $searchAttributeData['structure'] = '1'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('JobInProcess'); $where = RedBeanModelDataProvider::makeWhere('JobInProcess', $searchAttributeData, $joinTablesAdapter); $models = self::getSubset($joinTablesAdapter, null, null, $where, null); if (count($models) > 1) { return $models[0]; } if (count($models) == 0) { throw new NotFoundException(); } return $models[0]; }
/** * @param User $userToSendTo * @param MessageLogger $messageLogger */ public function run(User $userToSendTo, $messageLogger) { MonitorJob::makeJobStuckNotification(array('Process Outbound Email Job', 'Process Inbound Email Job')); $messageLogger->addInfoMessage('Sending a job is stuck message'); JobsManagerUtil::makeMonitorStuckJobNotification(); $messageLogger->addInfoMessage('Sending monitor job stuck message'); //Clear out notifications for super user $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'owner', 'relatedAttributeName' => 'id', 'operatorType' => 'equals', 'value' => Yii::app()->user->userModel->id)); $searchAttributeData['structure'] = '1'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Notification'); $where = RedBeanModelDataProvider::makeWhere('Notification', $searchAttributeData, $joinTablesAdapter); $models = Notification::getSubset($joinTablesAdapter, null, null, $where, null); foreach ($models as $model) { $model->delete(); } }
/** * This test specifically looks at when searching a note's owner. Because note extends mashableactivity which * does not have a bean, the query is constructed slightly different than if mashableactivity had a bean. */ public function testQueryIsProperlyGeneratedForNoteWithRelatedOwnerSearch() { Yii::app()->user->userModel = User::getByUsername('super'); $_FAKEPOST = array('Note' => array('owner' => array('id' => Yii::app()->user->userModel->id))); $metadataAdapter = new SearchDataProviderMetadataAdapter(new Note(false), 1, $_FAKEPOST['Note']); $_GET['Note_sort'] = 'description.desc'; $searchAttributeData = $metadataAdapter->getAdaptedMetadata(); $quote = DatabaseCompatibilityUtil::getQuote(); $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Note'); $where = RedBeanModelDataProvider::makeWhere('Note', $searchAttributeData, $joinTablesAdapter); $orderByColumnName = RedBeanModelDataProvider::resolveSortAttributeColumnName('Note', $joinTablesAdapter, 'description'); $subsetSql = Note::makeSubsetOrCountSqlQuery('note', $joinTablesAdapter, 1, 5, $where, $orderByColumnName); $compareSubsetSql = "select {$quote}note{$quote}.{$quote}id{$quote} id "; $compareSubsetSql .= "from ({$quote}note{$quote}, {$quote}activity{$quote}, {$quote}ownedsecurableitem{$quote})"; $compareSubsetSql .= " where ({$quote}ownedsecurableitem{$quote}.{$quote}owner__user_id{$quote} = " . Yii::app()->user->userModel->id . ")"; $compareSubsetSql .= " and {$quote}activity{$quote}.{$quote}id{$quote} ="; $compareSubsetSql .= " {$quote}note{$quote}.{$quote}activity_id{$quote}"; $compareSubsetSql .= " and {$quote}ownedsecurableitem{$quote}.{$quote}id{$quote} = {$quote}activity{$quote}.{$quote}ownedsecurableitem_id{$quote}"; $compareSubsetSql .= " order by {$quote}note{$quote}.{$quote}description{$quote} limit 5 offset 1"; $this->assertEquals($compareSubsetSql, $subsetSql); }
/** * @param string $beginDateTime * @param array $searchAttributeData * @return string */ protected static function makeColumnSqlQuery($beginDateTime, $searchAttributeData) { assert('is_string($beginDateTime)'); $quote = DatabaseCompatibilityUtil::getQuote(); $where = null; $selectDistinct = false; $marketingListTableName = MarketingList::getTableName(); $marketingListMemberTableName = MarketingListMember::getTableName(); $createdDateTimeColumnName = MarketingListMember::getColumnNameByAttribute('createdDateTime'); $unsubscribedColumnName = MarketingListMember::getColumnNameByAttribute('unsubscribed'); $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('MarketingList'); $where = RedBeanModelDataProvider::makeWhere('MarketingList', $searchAttributeData, $joinTablesAdapter); MarketingList::resolveReadPermissionsOptimizationToSqlQuery(Yii::app()->user->userModel, $joinTablesAdapter, $where, $selectDistinct); $selectQueryAdapter = new RedBeanModelSelectQueryAdapter($selectDistinct); $newSubscriberSelectPart = "sum(CASE WHEN {$quote}{$marketingListMemberTableName}{$quote}.{$quote}{$createdDateTimeColumnName}" . $quote . " >= '{$beginDateTime}' THEN 1 ELSE 0 END)"; $existingSubscriberSelectPart = "sum(CASE WHEN {$quote}{$marketingListMemberTableName}{$quote}.{$quote}{$createdDateTimeColumnName}" . $quote . " < '{$beginDateTime}' AND " . "{$quote}{$marketingListMemberTableName}{$quote}.{$quote}" . "{$unsubscribedColumnName}{$quote}=0 THEN 1 ELSE 0 END)"; // Not Coding Standard $selectQueryAdapter->addClauseByQueryString($newSubscriberSelectPart, static::NEW_SUBSCRIBERS_COUNT); $selectQueryAdapter->addClauseByQueryString($existingSubscriberSelectPart, static::EXISTING_SUBSCRIBERS_COUNT); $joinTablesAdapter->addLeftTableAndGetAliasName($marketingListMemberTableName, 'id', $marketingListTableName, 'marketinglist_id'); $sql = SQLQueryUtil::makeQuery($marketingListTableName, $selectQueryAdapter, $joinTablesAdapter, null, null, $where); return $sql; }
/** * Given an Item (Either User or Person), try to find an existing model. If the model does * not exist, create it and populate the Item. * @param Item $person * @return The found or created model. * @throws NotSupportedException */ public static function resolveByPerson(Item $person) { assert('$person->id > 0'); assert('$person instanceof Contact || $person instanceof User'); $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'person', 'relatedAttributeName' => 'id', 'operatorType' => 'equals', 'value' => $person->getClassId('Item'))); $searchAttributeData['structure'] = '1'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('GameCoin'); $where = RedBeanModelDataProvider::makeWhere('GameCoin', $searchAttributeData, $joinTablesAdapter); $models = self::getSubset($joinTablesAdapter, null, 2, $where, null); if (count($models) > 1) { $logContent = 'Duplicate Game Coin for Person: ' . $person->id; GamificationUtil::logAndNotifyOnDuplicateGameModel($logContent); return $models[0]; } if (count($models) == 0) { $gameCoin = new GameCoin(); $gameCoin->person = $person; $gameCoin->value = 0; return $gameCoin; } return $models[0]; }
/** * Given a user get the count of conversations that have unread comments. * @param object $user User */ public static function getUnreadCountByUser(User $user) { $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'ownerHasReadLatest', 'operatorType' => 'doesNotEqual', 'value' => (bool) 1), 2 => array('attributeName' => 'owner', 'operatorType' => 'equals', 'value' => $user->id), 3 => array('attributeName' => 'conversationParticipants', 'relatedAttributeName' => 'person', 'operatorType' => 'equals', 'value' => $user->getClassId('Item')), 4 => array('attributeName' => 'conversationParticipants', 'relatedAttributeName' => 'hasReadLatest', 'operatorType' => 'doesNotEqual', 'value' => (bool) 1)); $searchAttributeData['structure'] = '((1 and 2) or (3 and 4))'; $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('Conversation'); $where = RedBeanModelDataProvider::makeWhere('Conversation', $searchAttributeData, $joinTablesAdapter); return self::getCount($joinTablesAdapter, $where, null, true); }