public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect(' neoblocks.fieldId, neoblocks.ownerId, neoblocks.ownerLocale, neoblocks.typeId, neoblocks.collapsed ')->join('neoblocks neoblocks', 'neoblocks.id = elements.id')->leftJoin('neoblockstructures neoblockstructures', ['and', 'neoblockstructures.ownerId = neoblocks.ownerId', 'neoblockstructures.fieldId = neoblocks.fieldId', ['or', 'neoblockstructures.ownerLocale = neoblocks.ownerLocale', ['and', 'neoblockstructures.ownerLocale is null', 'neoblocks.ownerLocale is null']]])->leftJoin('structureelements structureelements', ['and', 'structureelements.structureId = neoblockstructures.structureId', 'structureelements.elementId = neoblocks.id']); if ($criteria->fieldId) { $query->andWhere(DbHelper::parseParam('neoblocks.fieldId', $criteria->fieldId, $query->params)); } if ($criteria->ownerId) { $query->andWhere(DbHelper::parseParam('neoblocks.ownerId', $criteria->ownerId, $query->params)); } if ($criteria->ownerLocale) { $query->andWhere(DbHelper::parseParam('neoblocks.ownerLocale', $criteria->ownerLocale, $query->params)); } if ($criteria->typeId) { $query->andWhere(DbHelper::parseParam('neoblocks.typeId', $criteria->typeId, $query->params)); } else { if ($criteria->type) { $query->join('neoblocktypes neoblocktypes', 'neoblocktypes.id = neoblocks.typeId'); $query->andWhere(DbHelper::parseParam('neoblocktypes.handle', $criteria->type, $query->params)); } } }
/** * Modifies an element query targeting elements of this type. * * @param DbCommand $query * @param ElementCriteriaModel $criteria * @return mixed */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('venti.startDate, venti.endDate, venti.allDay, venti.isrepeat, venti.eid, venti.eventid, venti.repeat, venti.rRule, venti.summary, venti.locale, entries.postDate, entries.expiryDate')->leftJoin('venti_events venti', 'venti.eventid = elements.id')->leftJoin('entries entries', 'entries.id = eventid')->group('venti.startDate'); if ($criteria->locale) { $query->andWhere(DbHelper::parseParam('venti.locale', $criteria->locale, $query->params)); } if ($criteria->startDate) { $query->andWhere(DbHelper::parseDateParam('venti.startDate', $criteria->startDate, $query->params)); } if ($criteria->id) { $query->andWhere(DbHelper::parseParam('venti.eventid', $criteria->eventid, $query->params)); } if ($criteria->eventid) { $query->andWhere(DbHelper::parseParam('venti.eventid', $criteria->eventid, $query->params)); } if ($criteria->endDate) { $query->andWhere(DbHelper::parseDateParam('venti.endDate', $criteria->endDate, $query->params)); } if ($criteria->summary) { $query->andWhere(DbHelper::parseParam('venti.summary', $criteria->summary, $query->params)); } if ($criteria->isrepeat) { $query->andWhere(DbHelper::parseParam('venti.isrepeat', $criteria->isrepeat, $query->params)); } if ($criteria->rRule) { $query->andWhere(DbHelper::parseParam('venti.rRule', $criteria->rRule, $query->params)); } if ($criteria->eid) { $query->andWhere(DbHelper::parseParam('venti.eid', $criteria->eid, $query->params)); } if ($criteria->repeat) { $query->andWhere(DbHelper::parseParam('venti.repeat', $criteria->repeat, $query->params)); } if ($criteria->allDay) { $query->andWhere(DbHelper::parseDateParam('venti.allDay', $criteria->allDay, $query->params)); } if ($criteria->between) { $dates = array(); $interval = array(); if (!is_array($criteria->between)) { $criteria->between = ArrayHelper::stringToArray($criteria->between); } if (count($criteria->between) == 2) { foreach ($criteria->between as $ref) { if (!$ref instanceof \DateTime) { $dates[] = DateTime::createFromString($ref, craft()->getTimeZone()); } else { $dates[] = $ref; } } if ($dates[0] > $dates[1]) { $interval[0] = $dates[1]; $interval[1] = $dates[0]; } else { $interval = $dates; } $query->andWhere('(venti.startDate BETWEEN :betweenStartDate AND :betweenEndDate) OR (:betweenStartDate BETWEEN venti.startDate AND venti.endDate)', array(':betweenStartDate' => DateTimeHelper::formatTimeForDb($interval[0]->getTimestamp()), ':betweenEndDate' => DateTimeHelper::formatTimeForDb($interval[1]->getTimestamp()))); } } }
public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('submissions.formId')->join('formerly_submissions submissions', 'submissions.id = elements.id'); if ($criteria->formId) { $query->andWhere(DbHelper::parseParam('submissions.formId', $criteria->formId, $query->params)); } if ($criteria->form) { $query->join('formerly_forms forms', 'forms.id = submissions.formId'); $query->andWhere(DbHelper::parseParam('formerly_forms.handle', $criteria->form, $query->params)); } }
/** * Modifies an entries query targeting entries of this type. * * @param DbCommand $query * @param ElementCriteriaModel $criteria * @return mixed */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('tags.setId, tags.name')->join('tags tags', 'tags.id = elements.id'); if ($criteria->name) { $query->andWhere(DbHelper::parseParam('tags.name', $criteria->name, $query->params)); } if ($criteria->setId) { $query->andWhere(DbHelper::parseParam('tags.setId', $criteria->setId, $query->params)); } if ($criteria->set) { $query->join('tagsets tagsets', 'tagsets.id = tags.setId'); $query->andWhere(DbHelper::parseParam('tagsets.handle', $criteria->set, $query->params)); } }
public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('formbuilder_entries.formId, formbuilder_entries.title, formbuilder_entries.data')->join('formbuilder_entries formbuilder_entries', 'formbuilder_entries.id = elements.id'); if ($criteria->formId) { $query->andWhere(DbHelper::parseParam('formbuilder_entries.formId', $criteria->formId, $query->params)); } }
/** * @inheritDoc IElementType::modifyElementsQuery() * * @param DbCommand $query * @param ElementCriteriaModel $criteria * * @return mixed */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('globalsets.name, globalsets.handle, globalsets.fieldLayoutId')->join('globalsets globalsets', 'globalsets.id = elements.id'); if ($criteria->handle) { $query->andWhere(DbHelper::parseParam('globalsets.handle', $criteria->handle, $query->params)); } }
public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('supertableblocks.fieldId, supertableblocks.ownerId, supertableblocks.ownerLocale, supertableblocks.typeId, supertableblocks.sortOrder')->join('supertableblocks supertableblocks', 'supertableblocks.id = elements.id'); if ($criteria->fieldId) { $query->andWhere(DbHelper::parseParam('supertableblocks.fieldId', $criteria->fieldId, $query->params)); } if ($criteria->ownerId) { $query->andWhere(DbHelper::parseParam('supertableblocks.ownerId', $criteria->ownerId, $query->params)); } if ($criteria->ownerLocale) { $query->andWhere(DbHelper::parseParam('supertableblocks.ownerLocale', $criteria->ownerLocale, $query->params)); } if ($criteria->type) { $query->join('supertableblocktypes supertableblocktypes', 'supertableblocktypes.id = supertableblocks.typeId'); $query->andWhere(DbHelper::parseParam('supertableblocktypes.handle', $criteria->type, $query->params)); } }
/** * Modifies an element query targeting elements of this type. * * @param DbCommand $query * @param ElementCriteriaModel $criteria * @return mixed */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('shortlist_list.default, shortlist_list.userSlug, shortlist_list.public, shortlist_list.type, shortlist_list.ownerId, shortlist_list.ownerType')->join('shortlist_list shortlist_list', 'shortlist_list.id = elements.id'); if ($criteria->default) { $query->andWhere(DbHelper::parseParam('shortlist_list.default', $criteria->default, $query->params)); } if ($criteria->userSlug) { $query->andWhere(DbHelper::parseParam('shortlist_list.userSlug', $criteria->userSlug, $query->params)); } if ($criteria->public) { $query->andWhere(DbHelper::parseParam('shortlist_list.public', $criteria->public, $query->params)); } if ($criteria->ownerId) { $query->andWhere(DbHelper::parseParam('shortlist_list.ownerId', $criteria->ownerId, $query->params)); } if ($criteria->ownerType) { $query->andWhere(DbHelper::parseParam('shortlist_list.ownerType', $criteria->ownerType, $query->params)); } }
/** * @inheritDoc IElementType::modifyElementsQuery() * * @param DbCommand $query * @param ElementCriteriaModel $criteria * * @return mixed */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('assetfiles.sourceId, assetfiles.folderId, assetfiles.filename, assetfiles.kind, assetfiles.width, assetfiles.height, assetfiles.size, assetfiles.dateModified')->join('assetfiles assetfiles', 'assetfiles.id = elements.id'); if ($criteria->sourceId) { $query->andWhere(DbHelper::parseParam('assetfiles.sourceId', $criteria->sourceId, $query->params)); } if ($criteria->folderId) { $query->andWhere(DbHelper::parseParam('assetfiles.folderId', $criteria->folderId, $query->params)); } if ($criteria->filename) { $query->andWhere(DbHelper::parseParam('assetfiles.filename', $criteria->filename, $query->params)); } if ($criteria->kind) { if (is_array($criteria->kind)) { $query->andWhere(DbHelper::parseParam('assetfiles.kind', array_merge(array('or'), $criteria->kind), $query->params)); } else { $query->andWhere(DbHelper::parseParam('assetfiles.kind', $criteria->kind, $query->params)); } } if ($criteria->width) { $query->andWhere(DbHelper::parseParam('assetfiles.width', $criteria->width, $query->params)); } if ($criteria->height) { $query->andWhere(DbHelper::parseParam('assetfiles.height', $criteria->height, $query->params)); } if ($criteria->size) { $query->andWhere(DbHelper::parseParam('assetfiles.size', $criteria->size, $query->params)); } }
/** * @inheritDoc IElementType::modifyElementsQuery() * * @param DbCommand $query * @param ElementCriteriaModel $criteria * * @return mixed */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('categories.groupId')->join('categories categories', 'categories.id = elements.id')->join('categorygroups categorygroups', 'categorygroups.id = categories.groupId')->leftJoin('structures structures', 'structures.id = categorygroups.structureId')->leftJoin('structureelements structureelements', array('and', 'structureelements.structureId = structures.id', 'structureelements.elementId = categories.id')); if ($criteria->groupId) { $query->andWhere(DbHelper::parseParam('categories.groupId', $criteria->groupId, $query->params)); } if ($criteria->group) { $query->andWhere(DbHelper::parseParam('categorygroups.handle', $criteria->group, $query->params)); } }
/** * Modifies an element query targeting elements of this type. * * @param DbCommand $query * @param ElementCriteriaModel $criteria * @return mixed */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('events.calendarId, events.startDate, events.endDate')->join('events events', 'events.id = elements.id'); if ($criteria->calendarId) { $query->andWhere(DbHelper::parseParam('events.calendarId', $criteria->calendarId, $query->params)); } if ($criteria->calendar) { $query->join('events_calendars events_calendars', 'events_calendars.id = events.calendarId'); $query->andWhere(DbHelper::parseParam('events_calendars.handle', $criteria->calendar, $query->params)); } if ($criteria->startDate) { $query->andWhere(DbHelper::parseDateParam('events.startDate', $criteria->startDate, $query->params)); } if ($criteria->endDate) { $query->andWhere(DbHelper::parseDateParam('events.endDate', $criteria->endDate, $query->params)); } }
/** * @inheritDoc IFieldType::modifyElementsQuery() * * @param DbCommand $query * @param mixed $value * * @return null|false */ public function modifyElementsQuery(DbCommand $query, $value) { if ($value !== null) { if ($this->defineContentAttribute()) { $handle = $this->model->handle; $query->andWhere(DbHelper::parseParam('content.' . craft()->content->fieldColumnPrefix . $handle, $value, $query->params)); } else { return false; } } }
/** * Modifies an element query targeting elements of this type. * * @param DbCommand $query * @param ElementCriteriaModel $criteria * @return mixed */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('forms.id, forms.fieldLayoutId, forms.redirectEntryId, forms.name, forms.handle, forms.titleFormat, forms.submitAction, forms.submitButton, forms.afterSubmit, forms.afterSubmitText, forms.submissionEnabled, forms.displayTabTitles, forms.redirectUrl, forms.sendCopy, forms.sendCopyTo, forms.notificationEnabled, forms.notificationFilesEnabled, forms.notificationRecipients, forms.notificationSubject, forms.confirmationSubject, forms.notificationSenderName, forms.confirmationSenderName, forms.notificationSenderEmail, forms.confirmationSenderEmail, forms.notificationReplyToEmail, forms.formTemplate, forms.tabTemplate, forms.fieldTemplate, forms.notificationTemplate, forms.confirmationTemplate'); $query->join('amforms_forms forms', 'forms.id = elements.id'); if ($criteria->handle) { $query->andWhere(DbHelper::parseParam('forms.handle', $criteria->handle, $query->params)); } }
/** * @inheritDoc IElementType::modifyElementsQuery() * * @param DbCommand $query * @param ElementCriteriaModel $criteria * * @return mixed */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('users.username, users.photo, users.firstName, users.lastName, users.email, users.admin, users.client, users.locked, users.pending, users.suspended, users.archived, users.lastLoginDate, users.lockoutDate, users.preferredLocale')->join('users users', 'users.id = elements.id'); if ($criteria->admin) { $query->andWhere(DbHelper::parseParam('users.admin', $criteria->admin, $query->params)); } if ($criteria->client && craft()->getEdition() == Craft::Client) { $query->andWhere(DbHelper::parseParam('users.client', $criteria->client, $query->params)); } if ($criteria->can && craft()->getEdition() == Craft::Pro) { // Get the actual permission ID if (is_numeric($criteria->can)) { $permissionId = $criteria->can; } else { $permissionId = craft()->db->createCommand()->select('id')->from('userpermissions')->where('name = :name', array(':name' => strtolower($criteria->can)))->queryScalar(); } // Find the users that have that permission, either directly or through a group $permittedUserIds = array(); // If the permission hasn't been assigned to any groups/users before, it won't have an ID. Don't bail // though, since we still want to look for admins. if ($permissionId) { // Get the user groups that have that permission $permittedGroupIds = craft()->db->createCommand()->select('groupId')->from('userpermissions_usergroups')->where('permissionId = :permissionId', array(':permissionId' => $permissionId))->queryColumn(); if ($permittedGroupIds) { $permittedUserIds = $this->_getUserIdsByGroupIds($permittedGroupIds); } // Get the users that have that permission directly $permittedUserIds = array_merge($permittedUserIds, craft()->db->createCommand()->select('userId')->from('userpermissions_users')->where('permissionId = :permissionId', array(':permissionId' => $permissionId))->queryColumn()); } if ($permittedUserIds) { $permissionConditions = array('or', 'users.admin = 1', array('in', 'elements.id', $permittedUserIds)); } else { $permissionConditions = 'users.admin = 1'; } $query->andWhere($permissionConditions); } if ($criteria->groupId) { $userIds = $this->_getUserIdsByGroupIds($criteria->groupId); if (!$userIds) { return false; } $query->andWhere(array('in', 'elements.id', $userIds)); } if ($criteria->group) { // Get the actual group ID(s) $groupIdsQuery = craft()->db->createCommand()->select('id')->from('usergroups'); $groupIdsQuery->where(DbHelper::parseParam('handle', $criteria->group, $groupIdsQuery->params)); $groupIds = $groupIdsQuery->queryColumn(); // In the case where the group doesn't exist. if (!$groupIds) { return false; } $userIds = $this->_getUserIdsByGroupIds($groupIds); // In case there are no users in the groups. if (!$userIds) { return false; } $query->andWhere(array('in', 'elements.id', $userIds)); } if ($criteria->username) { $query->andWhere(DbHelper::parseParam('users.username', $criteria->username, $query->params)); } if ($criteria->firstName) { $query->andWhere(DbHelper::parseParam('users.firstName', $criteria->firstName, $query->params)); } if ($criteria->lastName) { $query->andWhere(DbHelper::parseParam('users.lastName', $criteria->lastName, $query->params)); } if ($criteria->email) { $query->andWhere(DbHelper::parseParam('users.email', $criteria->email, $query->params)); } if ($criteria->preferredLocale) { $query->andWhere(DbHelper::parseParam('users.preferredLocale', $criteria->preferredLocale, $query->params)); } if ($criteria->lastLoginDate) { $query->andWhere(DbHelper::parseDateParam('users.lastLoginDate', $criteria->lastLoginDate, $query->params)); } }
/** * @param DbCommand $query * @param ElementCriteriaModel $criteria * * @return void */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('orders.id, orders.number, orders.couponCode, orders.itemTotal, orders.baseDiscount, orders.baseShippingCost, orders.totalPrice, orders.totalPaid, orders.orderStatusId, orders.dateOrdered, orders.email, orders.dateOrdered, orders.datePaid, orders.currency, orders.lastIp, orders.message, orders.returnUrl, orders.cancelUrl, orders.orderStatusId, orders.billingAddressId, orders.billingAddressData, orders.shippingAddressId, orders.shippingAddressData, orders.shippingMethodId, orders.paymentMethodId, orders.customerId, orders.dateUpdated')->join('market_orders orders', 'orders.id = elements.id'); if ($criteria->completed) { if ($criteria->completed == true) { $query->andWhere('orders.dateOrdered is not null'); $criteria->completed = null; } } if ($criteria->dateOrdered) { $query->andWhere(DbHelper::parseParam('orders.dateOrdered', $criteria->dateOrdered, $query->params)); } if ($criteria->number) { $query->andWhere(DbHelper::parseParam('orders.number', $criteria->number, $query->params)); } if ($criteria->orderStatus) { if ($criteria->orderStatus instanceof Market_OrderStatusModel) { $criteria->orderStatusId = $criteria->orderStatus->id; $criteria->orderStatus = NULL; } else { $query->andWhere(DbHelper::parseParam('orders.orderStatusId', $criteria->orderStatus, $query->params)); } } if ($criteria->orderStatusId) { $query->andWhere(DbHelper::parseParam('orders.orderStatusId', $criteria->orderStatusId, $query->params)); } if ($criteria->customer) { if ($criteria->customer instanceof Market_CustomerModel) { if ($criteria->customer->id) { $criteria->customerId = $criteria->customer->id; $criteria->customer = null; } else { $query->andWhere(DbHelper::parseParam('orders.customerId', 'IS NULL', $query->params)); } } } if ($criteria->customerId) { $query->andWhere(DbHelper::parseParam('orders.customerId', $criteria->customerId, $query->params)); } if ($criteria->updatedOn) { $query->andWhere(DbHelper::parseDateParam('orders.dateUpdated', $criteria->updatedOn, $query->params)); } else { if ($criteria->updatedAfter) { $query->andWhere(DbHelper::parseDateParam('orders.dateUpdated', '>=' . $criteria->updatedAfter, $query->params)); } if ($criteria->updatedBefore) { $query->andWhere(DbHelper::parseDateParam('orders.dateUpdated', '<' . $criteria->updatedBefore, $query->params)); } } }
/** * Modifies an element query targeting elements of this type. * * @param DbCommand $query * @param ElementCriteriaModel $criteria * @return mixed */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { // you must add the columns here when adding a new field $query->addSelect('applications.formId, applications.firstName, applications.lastName, applications.email, applications.status, applications.phone, applications.dateCreated,')->join('applications applications', 'applications.id = elements.id'); if ($criteria->formId) { $query->andWhere(DbHelper::parseParam('applications.formId', $criteria->formId, $query->params)); } if ($criteria->form) { $query->join('applications_forms applications_forms', 'applications_forms.id = applications.formId'); $query->andWhere(DbHelper::parseParam('applications_forms.handle', $criteria->form, $query->params)); } if ($criteria->dateCreated) { $query->andWhere(DbHelper::parseDateParam('entries.dateCreated', $criteria->dateCreated, $query->params)); } }
/** * @inheritDoc IElementType::modifyElementsQuery() * * @param DbCommand $query * @param ElementCriteriaModel $criteria * * @return mixed */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('assetfiles.sourceId, assetfiles.folderId, assetfiles.filename, assetfiles.kind, assetfiles.width, assetfiles.height, assetfiles.size, assetfiles.dateModified')->join('assetfiles assetfiles', 'assetfiles.id = elements.id'); if (!empty($criteria->source)) { $query->join('assetsources assetsources', 'assetfiles.sourceId = assetsources.id'); } if ($criteria->sourceId) { $query->andWhere(DbHelper::parseParam('assetfiles.sourceId', $criteria->sourceId, $query->params)); } if ($criteria->source) { $query->andWhere(DbHelper::parseParam('assetsources.handle', $criteria->source, $query->params)); } if ($criteria->folderId) { if ($criteria->includeSubfolders) { $folders = craft()->assets->getAllDescendantFolders(craft()->assets->getFolderById($criteria->folderId)); $query->andWhere(DbHelper::parseParam('assetfiles.folderId', array_keys($folders), $query->params)); } else { $query->andWhere(DbHelper::parseParam('assetfiles.folderId', $criteria->folderId, $query->params)); } } if ($criteria->filename) { $query->andWhere(DbHelper::parseParam('assetfiles.filename', $criteria->filename, $query->params)); } if ($criteria->kind) { if (is_array($criteria->kind)) { $query->andWhere(DbHelper::parseParam('assetfiles.kind', array_merge(array('or'), $criteria->kind), $query->params)); } else { $query->andWhere(DbHelper::parseParam('assetfiles.kind', $criteria->kind, $query->params)); } } if ($criteria->width) { $query->andWhere(DbHelper::parseParam('assetfiles.width', $criteria->width, $query->params)); } if ($criteria->height) { $query->andWhere(DbHelper::parseParam('assetfiles.height', $criteria->height, $query->params)); } if ($criteria->size) { $query->andWhere(DbHelper::parseParam('assetfiles.size', $criteria->size, $query->params)); } }
/** * Modifies an element query targeting elements of this type. * * @param DbCommand $query * @param ElementCriteriaModel $criteria * @return mixed */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('forms.id, forms.fieldLayoutId, forms.groupId, forms.name, forms.handle, forms.titleFormat, forms.displaySectionTitles, forms.redirectUri, forms.submitAction, forms.submitButtonText, forms.notificationEnabled, forms.notificationRecipients, forms.notificationSubject, forms.notificationSenderName, forms.notificationSenderEmail, forms.notificationReplyToEmail ')->join('sproutforms_forms forms', 'forms.id = elements.id'); if ($criteria->totalEntries) { $query->addSelect('COUNT(entries.id) totalEntries'); $query->leftJoin('sproutforms_entries entries', 'entries.formId = forms.id'); } if ($criteria->numberOfFields) { $query->addSelect('COUNT(fields.id) numberOfFields'); $query->leftJoin('fieldlayoutfields fields', 'fields.layoutId = forms.fieldLayoutId'); } if ($criteria->handle) { $query->andWhere(DbHelper::parseParam('forms.handle', $criteria->handle, $query->params)); } if ($criteria->groupId) { $query->join('sproutforms_formgroups formgroups', 'formgroups.id = forms.groupId'); $query->andWhere(DbHelper::parseParam('forms.groupId', $criteria->groupId, $query->params)); } }
/** * @inheritDoc IFieldType::modifyElementsQuery() * * @param DbCommand $query * @param mixed $value * * @return null|false */ public function modifyElementsQuery(DbCommand $query, $value) { if ($value !== null) { $handle = $this->model->handle; $query->andWhere(DbHelper::parseDateParam('content.' . craft()->content->fieldColumnPrefix . $handle, $value, $query->params)); } }
/** * Modifies an entries query targeting entries of this type. * * @param DbCommand $query * @param ElementCriteriaModel $criteria * @return mixed */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('entries.sectionId, entries.authorId, entries.postDate, entries.expiryDate, entries_i18n.slug')->join('entries entries', 'entries.id = elements.id')->join('entries_i18n entries_i18n', 'entries_i18n.entryId = elements.id')->andWhere('entries_i18n.locale = elements_i18n.locale'); if ($criteria->slug) { $query->andWhere(DbHelper::parseParam('entries_i18n.slug', $criteria->slug, $query->params)); } if ($criteria->postDate) { $query->andWhere(DbHelper::parseDateParam('entries.postDate', '=', $criteria->postDate, $query->params)); } else { if ($criteria->after) { $query->andWhere(DbHelper::parseDateParam('entries.postDate', '>=', $criteria->after, $query->params)); } if ($criteria->before) { $query->andWhere(DbHelper::parseDateParam('entries.postDate', '<', $criteria->before, $query->params)); } } if ($criteria->editable) { $user = craft()->userSession->getUser(); if (!$user) { return false; } $editableSectionIds = craft()->sections->getEditableSectionIds(); $query->andWhere(array('in', 'entries.sectionId', $editableSectionIds)); $noPeerConditions = array(); foreach ($editableSectionIds as $sectionId) { if (!$user->can('editPeerEntries:' . $sectionId)) { $noPeerConditions[] = array('or', 'entries.sectionId != ' . $sectionId, 'entries.authorId = ' . $user->id); } } if ($noPeerConditions) { array_unshift($noPeerConditions, 'and'); $query->andWhere($noPeerConditions); } } if (Craft::hasPackage(CraftPackage::PublishPro)) { if ($criteria->sectionId) { $query->andWhere(DbHelper::parseParam('entries.sectionId', $criteria->sectionId, $query->params)); } if ($criteria->section) { $query->join('sections sections', 'entries.sectionId = sections.id'); $query->andWhere(DbHelper::parseParam('sections.handle', $criteria->section, $query->params)); } } if (Craft::hasPackage(CraftPackage::Users)) { if ($criteria->authorId) { $query->andWhere(DbHelper::parseParam('entries.authorId', $criteria->authorId, $query->params)); } if ($criteria->authorGroupId || $criteria->authorGroup) { $query->join('usergroups_users usergroups_users', 'usergroups_users.userId = entries.authorId'); if ($criteria->authorGroupId) { $query->andWhere(DbHelper::parseParam('usergroups_users.groupId', $criteria->authorGroupId, $query->params)); } if ($criteria->authorGroup) { $query->join('usergroups usergroups', 'usergroups.id = usergroups_users.groupId'); $query->andWhere(DbHelper::parseParam('usergroups.handle', $criteria->authorGroup, $query->params)); } } } }
public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect(' workflow_submissions.ownerId, workflow_submissions.draftId, workflow_submissions.editorId, workflow_submissions.publisherId, workflow_submissions.status, workflow_submissions.notes, workflow_submissions.dateApproved, workflow_submissions.dateRejected, workflow_submissions.dateRevoked ')->join('workflow_submissions workflow_submissions', 'workflow_submissions.id = elements.id'); if ($criteria->ownerId) { $query->andWhere(DbHelper::parseParam('workflow_submissions.ownerId', $criteria->ownerId, $query->params)); } if ($criteria->draftId) { $query->andWhere(DbHelper::parseParam('workflow_submissions.draftId', $criteria->draftId, $query->params)); } if ($criteria->editorId) { $query->andWhere(DbHelper::parseParam('workflow_submissions.editorId', $criteria->editorId, $query->params)); } if ($criteria->publisherId) { $query->andWhere(DbHelper::parseParam('workflow_submissions.publisherId', $criteria->publisherId, $query->params)); } if ($criteria->status) { $query->andWhere(DbHelper::parseParam('workflow_submissions.status', $criteria->status, $query->params)); } if ($criteria->notes) { $query->andWhere(DbHelper::parseParam('workflow_submissions.notes', $criteria->notes, $query->params)); } if ($criteria->dateApproved) { $query->andWhere(DbHelper::parseDateParam('workflow_submissions.dateApproved', $criteria->dateApproved, $query->params)); } if ($criteria->dateRejected) { $query->andWhere(DbHelper::parseDateParam('workflow_submissions.dateRejected', $criteria->dateRejected, $query->params)); } if ($criteria->dateRevoked) { $query->andWhere(DbHelper::parseDateParam('workflow_submissions.dateRevoked', $criteria->dateRevoked, $query->params)); } if ($criteria->dateCreated) { $query->andWhere(DbHelper::parseDateParam('workflow_submissions.dateCreated', $criteria->dateCreated, $query->params)); } }
/** * Modifies an element query targeting elements of this type. * * @param DbCommand $query * @param ElementCriteriaModel $criteria * * @return mixed */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('entries.id , entries.subjectLine as subjectLine , entries.campaignId as campaignId , entries.recipients as recipients , entries.fromName as fromName , entries.fromEmail as fromEmail , entries.replyTo as replyTo , entries.sent as sent , campaigns.type as type')->join('sproutemail_campaigns_entries entries', 'entries.id = elements.id')->join('sproutemail_campaigns campaigns', 'campaigns.id = entries.campaignId'); if ($criteria->campaignId) { $query->andWhere(DbHelper::parseParam('entries.campaignId', $criteria->campaignId, $query->params)); } if ($criteria->campaignHandle) { $query->andWhere(DbHelper::parseParam('campaigns.handle', $criteria->campaignHandle, $query->params)); } }
/** * Modifies an element query targeting elements of this type. * * @param DbCommand $query * @param ElementCriteriaModel $criteria * @return mixed */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('nodes.menuId, nodes.linkedEntryId, nodes.customUrl, i18n.uri linkedEntryUrl')->join('menus_nodes nodes', 'nodes.id = elements.id')->join('menus menus', 'menus.id = nodes.menuId')->leftJoin('elements_i18n i18n', 'i18n.elementId = nodes.linkedEntryId')->leftJoin('structures structures', 'structures.id = menus.structureId')->leftJoin('structureelements structureelements', array('and', 'structureelements.structureId = structures.id', 'structureelements.elementId = nodes.id')); if ($criteria->menuId) { $query->andWhere(DbHelper::parseParam('nodes.menuId', $criteria->menuId, $query->params)); } if ($criteria->menu) { $query->andWhere(DbHelper::parseParam('menus.handle', $criteria->menu, $query->params)); } // if ($criteria->startDate) // { // $query->andWhere(DbHelper::parseDateParam('entries.startDate', $criteria->startDate, $query->params)); // } // // if ($criteria->endDate) // { // $query->andWhere(DbHelper::parseDateParam('entries.endDate', $criteria->endDate, $query->params)); // } }
/** * Modifies an entries query targeting entries of this type. * * @param DbCommand $query * @param ElementCriteriaModel $criteria * @return mixed */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('users.username, users.photo, users.firstName, users.lastName, users.email, users.admin, users.status, users.lastLoginDate, users.lockoutDate, users.preferredLocale')->join('users users', 'users.id = elements.id'); if ($criteria->groupId) { $query->join('usergroups_users usergroups_users', 'users.id = usergroups_users.userId'); $query->andWhere(DbHelper::parseParam('usergroups_users.groupId', $criteria->groupId, $query->params)); } if ($criteria->group) { $query->join('usergroups_users usergroups_users', 'users.id = usergroups_users.userId'); $query->join('usergroups usergroups', 'usergroups_users.groupId = usergroups.id'); $query->andWhere(DbHelper::parseParam('usergroups.handle', $criteria->group, $query->params)); } if ($criteria->username) { $query->andWhere(DbHelper::parseParam('users.username', $criteria->username, $query->params)); } if ($criteria->firstName) { $query->andWhere(DbHelper::parseParam('users.firstName', $criteria->firstName, $query->params)); } if ($criteria->lastName) { $query->andWhere(DbHelper::parseParam('users.lastName', $criteria->lastName, $query->params)); } if ($criteria->email) { $query->andWhere(DbHelper::parseParam('users.email', $criteria->email, $query->params)); } if ($criteria->preferredLocale) { $query->andWhere(DbHelper::parseParam('users.preferredLocale', $criteria->preferredLocale, $query->params)); } if ($criteria->status) { $query->andWhere(DbHelper::parseParam('users.status', $criteria->status, $query->params)); } }
/** * @inheritDoc IFieldType::modifyElementsQuery() * * @param DbCommand $query * @param mixed $value * * @return null|false */ public function modifyElementsQuery(DbCommand $query, $value) { if ($value == 'not :empty:') { $value = ':notempty:'; } if ($value == ':notempty:' || $value == ':empty:') { $alias = 'relations_' . $this->model->handle; $operator = $value == ':notempty:' ? '!=' : '='; $query->andWhere("(select count({$alias}.id) from {{relations}} {$alias} where {$alias}.sourceId = elements.id and {$alias}.fieldId = :fieldId) {$operator} 0", array(':fieldId' => $this->model->id)); } else { if ($value !== null) { return false; } } }
/** * @inheritDoc IElementType::modifyElementsQuery() * * @param DbCommand $query * @param ElementCriteriaModel $criteria * * @return mixed */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('assetfiles.sourceId, assetfiles.folderId, assetfiles.filename, assetfiles.kind, assetfiles.width, assetfiles.height, assetfiles.size, assetfiles.dateModified, assetfolders.path as folderPath')->join('assetfiles assetfiles', 'assetfiles.id = elements.id')->join('assetfolders assetfolders', 'assetfolders.id = assetfiles.folderId'); if (!empty($criteria->source)) { $query->join('assetsources assetsources', 'assetfiles.sourceId = assetsources.id'); } if ($criteria->sourceId) { $query->andWhere(DbHelper::parseParam('assetfiles.sourceId', $criteria->sourceId, $query->params)); } if ($criteria->source) { $query->andWhere(DbHelper::parseParam('assetsources.handle', $criteria->source, $query->params)); } if ($criteria->folderId) { if ($criteria->includeSubfolders) { $folders = craft()->assets->getAllDescendantFolders(craft()->assets->getFolderById($criteria->folderId)); $query->andWhere(DbHelper::parseParam('assetfiles.folderId', array_keys($folders), $query->params)); } else { $query->andWhere(DbHelper::parseParam('assetfiles.folderId', $criteria->folderId, $query->params)); } } if ($criteria->filename) { $query->andWhere(DbHelper::parseParam('assetfiles.filename', $criteria->filename, $query->params)); } if ($criteria->kind) { if (is_array($criteria->kind)) { $query->andWhere(DbHelper::parseParam('assetfiles.kind', array_merge(array('or'), $criteria->kind), $query->params)); } else { $query->andWhere(DbHelper::parseParam('assetfiles.kind', $criteria->kind, $query->params)); } } if ($criteria->width) { $query->andWhere(DbHelper::parseParam('assetfiles.width', $criteria->width, $query->params)); } if ($criteria->height) { $query->andWhere(DbHelper::parseParam('assetfiles.height', $criteria->height, $query->params)); } if ($criteria->size) { $query->andWhere(DbHelper::parseParam('assetfiles.size', $criteria->size, $query->params)); } // Clear out existing onPopulateElements handlers $criteria->detachEventHandler('onPopulateElements', array($this, 'eagerLoadTransforms')); // Are we eager-loading any transforms? if ($criteria->withTransforms) { $criteria->attachEventHandler('onPopulateElements', array($this, 'eagerLoadTransforms')); } }
/** * @inheritDoc IElementType::modifyElementsQuery() * * @param DbCommand $query * @param ElementCriteriaModel $criteria * * @return bool|false|null|void */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('entries.sectionId, entries.typeId, entries.authorId, entries.postDate, entries.expiryDate')->join('entries entries', 'entries.id = elements.id')->join('sections sections', 'sections.id = entries.sectionId')->leftJoin('structures structures', 'structures.id = sections.structureId')->leftJoin('structureelements structureelements', array('and', 'structureelements.structureId = structures.id', 'structureelements.elementId = entries.id')); if ($criteria->ref) { $refs = ArrayHelper::stringToArray($criteria->ref); $conditionals = array(); foreach ($refs as $ref) { $parts = array_filter(explode('/', $ref)); if ($parts) { if (count($parts) == 1) { $conditionals[] = DbHelper::parseParam('elements_i18n.slug', $parts[0], $query->params); } else { $conditionals[] = array('and', DbHelper::parseParam('sections.handle', $parts[0], $query->params), DbHelper::parseParam('elements_i18n.slug', $parts[1], $query->params)); } } } if ($conditionals) { if (count($conditionals) == 1) { $query->andWhere($conditionals[0]); } else { array_unshift($conditionals, 'or'); $query->andWhere($conditionals); } } } if ($criteria->type) { $typeIds = array(); if (!is_array($criteria->type)) { $criteria->type = array($criteria->type); } foreach ($criteria->type as $type) { if (is_numeric($type)) { $typeIds[] = $type; } else { if (is_string($type)) { $types = craft()->sections->getEntryTypesByHandle($type); if ($types) { foreach ($types as $type) { $typeIds[] = $type->id; } } else { return false; } } else { if ($type instanceof EntryTypeModel) { $typeIds[] = $type->id; } else { return false; } } } } $query->andWhere(DbHelper::parseParam('entries.typeId', $typeIds, $query->params)); } if ($criteria->postDate) { $query->andWhere(DbHelper::parseDateParam('entries.postDate', $criteria->postDate, $query->params)); } else { if ($criteria->after) { $query->andWhere(DbHelper::parseDateParam('entries.postDate', '>=' . $criteria->after, $query->params)); } if ($criteria->before) { $query->andWhere(DbHelper::parseDateParam('entries.postDate', '<' . $criteria->before, $query->params)); } } if ($criteria->expiryDate) { $query->andWhere(DbHelper::parseDateParam('entries.expiryDate', $criteria->expiryDate, $query->params)); } if ($criteria->editable) { $user = craft()->userSession->getUser(); if (!$user) { return false; } // Limit the query to only the sections the user has permission to edit $editableSectionIds = craft()->sections->getEditableSectionIds(); $query->andWhere(array('in', 'entries.sectionId', $editableSectionIds)); // Enforce the editPeerEntries permissions for non-Single sections $noPeerConditions = array(); foreach (craft()->sections->getEditableSections() as $section) { if ($section->type != SectionType::Single && !$user->can('editPeerEntries:' . $section->id)) { $noPeerConditions[] = array('or', 'entries.sectionId != ' . $section->id, 'entries.authorId = ' . $user->id); } } if ($noPeerConditions) { array_unshift($noPeerConditions, 'and'); $query->andWhere($noPeerConditions); } } if ($criteria->section) { if ($criteria->section instanceof SectionModel) { $criteria->sectionId = $criteria->section->id; $criteria->section = null; } else { $query->andWhere(DbHelper::parseParam('sections.handle', $criteria->section, $query->params)); } } if ($criteria->sectionId) { $query->andWhere(DbHelper::parseParam('entries.sectionId', $criteria->sectionId, $query->params)); } if (craft()->getEdition() >= Craft::Client) { if ($criteria->authorId) { $query->andWhere(DbHelper::parseParam('entries.authorId', $criteria->authorId, $query->params)); } if ($criteria->authorGroupId || $criteria->authorGroup) { $query->join('usergroups_users usergroups_users', 'usergroups_users.userId = entries.authorId'); if ($criteria->authorGroupId) { $query->andWhere(DbHelper::parseParam('usergroups_users.groupId', $criteria->authorGroupId, $query->params)); } if ($criteria->authorGroup) { $query->join('usergroups usergroups', 'usergroups.id = usergroups_users.groupId'); $query->andWhere(DbHelper::parseParam('usergroups.handle', $criteria->authorGroup, $query->params)); } } } }
/** * Adds conditions to related elements query. * * @access private * @param DbCommand $query * @param string $source * @param string $target * @param int $sourceId * @param int|null $fieldId * @param bool $ordered */ private function _addConditionsToRelationsQuery(DbCommand $query, $source, $target, $sourceId, $fieldId) { $query->join('relations relations', "relations.{$target}Id = elements.id")->andWhere(array("relations.{$source}Id" => $sourceId)); if ($fieldId) { $query->andWhere(array('relations.fieldId' => $fieldId)); } }
public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect("variants.id,variants.productId,variants.isImplicit,variants.sku,variants.price,variants.width,variants.height,variants.length,variants.weight,variants.stock,variants.unlimitedStock,variants.minQty,variants.maxQty")->join('market_variants variants', 'variants.id = elements.id'); if ($criteria->sku) { $query->andWhere(DbHelper::parseParam('variants.sku', $criteria->sku, $query->params)); } if ($criteria->product) { if ($criteria->product instanceof Market_ProductModel) { $criteria->productId = $criteria->product->id; $criteria->product = NULL; } else { $query->andWhere(DbHelper::parseParam('variants.productId', $criteria->product, $query->params)); } } if ($criteria->productId) { $query->andWhere(DbHelper::parseParam('variants.productId', $criteria->productId, $query->params)); } if ($criteria->isImplicit) { $query->andWhere(DbHelper::parseParam('variants.isImplicit', $criteria->isImplicit, $query->params)); } }
/** * Modifies an element query targeting elements of this type. * * @param DbCommand $query * @param ElementCriteriaModel $criteria * * @return mixed */ public function modifyElementsQuery(DbCommand $query, ElementCriteriaModel $criteria) { $query->addSelect('pushnotifications_devices.appId, pushnotifications_devices.platform, pushnotifications_devices.token')->join('pushnotifications_devices pushnotifications_devices', 'pushnotifications_devices.id = elements.id'); if ($criteria->appId) { $query->andWhere(DbHelper::parseParam('pushnotifications_devices.appId', $criteria->appId, $query->params)); } if ($criteria->app) { $query->join('pushnotifications_apps pushnotifications_apps', 'pushnotifications_apps.id = pushnotifications_devices.appId'); $query->andWhere(DbHelper::parseParam('pushnotifications_apps.handle', $criteria->app, $query->params)); } if ($criteria->platform) { $query->andWhere(DbHelper::parseParam('pushnotifications_devices.platform', $criteria->platform, $query->params)); } if ($criteria->token) { $query->andWhere(DbHelper::parseParam('pushnotifications_devices.token', $criteria->token, $query->params)); } }