コード例 #1
0
 /**
  * Dump the results of our query in array form,
  * before the results get populated into EntryModels.
  */
 public function showResults()
 {
     if (!$this->dbCommand) {
         Craft::dd($this->criteria->find());
     }
     Craft::dd($this->dbCommand->queryAll());
 }
コード例 #2
0
 /**
  * @inheritDoc IElementAction::performAction()
  *
  * @param ElementCriteriaModel $criteria
  *
  * @return bool
  */
 public function performAction(ElementCriteriaModel $criteria)
 {
     // Get all submission
     $submissions = $criteria->find();
     // Gather submissions based on form
     $formSubmissions = array();
     foreach ($submissions as $submission) {
         if (!isset($formSubmissions[$submission->formId])) {
             $formSubmissions[$submission->formId] = array();
         }
         $formSubmissions[$submission->formId][] = $submission->id;
     }
     // Export submission(s)
     foreach ($formSubmissions as $formId => $submissionIds) {
         $total = count($submissionIds);
         $export = new AmForms_ExportModel();
         $export->name = Craft::t('{total} submission(s)', array('total' => $total));
         $export->formId = $formId;
         $export->total = $total;
         $export->totalCriteria = $total;
         $export->submissions = $submissionIds;
         craft()->amForms_exports->saveExport($export);
     }
     // Success!
     $this->setMessage(Craft::t('Submissions exported.'));
     return true;
 }
コード例 #3
0
 /**
  * Paginates an ElementCriteriaModel instance.
  *
  * @param ElementCriteriaModel $criteria
  *
  * @return array
  */
 public static function paginateCriteria(ElementCriteriaModel $criteria)
 {
     $currentPage = craft()->request->getPageNum();
     $limit = $criteria->limit;
     $total = $criteria->total() - $criteria->offset;
     $totalPages = ceil($total / $limit);
     if ($currentPage > $totalPages) {
         $currentPage = $totalPages;
     }
     $offset = $limit * ($currentPage - 1);
     // Is there already an offset set?
     if ($criteria->offset) {
         $offset += $criteria->offset;
     }
     $last = $offset + $limit;
     if ($last > $total) {
         $last = $total;
     }
     $paginateVariable = new PaginateVariable();
     $paginateVariable->first = $offset + 1;
     $paginateVariable->last = $last;
     $paginateVariable->total = $total;
     $paginateVariable->currentPage = $currentPage;
     $paginateVariable->totalPages = $totalPages;
     // Get the entities
     $criteria->offset = $offset;
     $entities = $criteria->find();
     return array($paginateVariable, $entities);
 }
 public function performAction(ElementCriteriaModel $criteria)
 {
     if (craft()->varnishpurge->getSetting('varnishPurgeEnabled')) {
         $elements = $criteria->find();
         craft()->varnishpurge->purgeElements($elements, false);
         $this->setMessage(Craft::t('Varnish cache was purged.'));
         return true;
     }
 }
コード例 #5
0
 /**
  * Perform action
  *
  * @param ElementCriteriaModel $criteria
  *
  * @return bool
  */
 public function performAction(ElementCriteriaModel $criteria)
 {
     $entries = $criteria->find();
     foreach ($entries as $entry) {
         craft()->entryCount->reset($entry->id);
     }
     $this->setMessage(Craft::t('Entry Count Successfully Reset'));
     return true;
 }
 public function performAction(ElementCriteriaModel $criteria)
 {
     $assets = $criteria->find();
     foreach ($assets as $asset) {
         craft()->imager->removeTransformsForAsset($asset);
     }
     $this->setMessage(Craft::t('Transforms were removed'));
     return true;
 }
コード例 #7
0
 /**
  * @inheritDoc IElementAction::performAction()
  *
  * @param ElementCriteriaModel $criteria
  *
  * @return bool
  */
 public function performAction(ElementCriteriaModel $criteria)
 {
     // Get the users that are suspended
     $criteria->status = UserStatus::Suspended;
     $users = $criteria->find();
     foreach ($users as $user) {
         craft()->users->unsuspendUser($user);
     }
     $this->setMessage(Craft::t('Users unsuspended.'));
     return true;
 }
コード例 #8
0
 /**
  * @inheritDoc IElementAction::performAction()
  *
  * @param ElementCriteriaModel $criteria
  *
  * @return bool
  */
 public function performAction(ElementCriteriaModel $criteria)
 {
     // Get the users that aren't already suspended
     $criteria->status = array(UserStatus::Active, UserStatus::Locked, UserStatus::Pending);
     $users = $criteria->find();
     foreach ($users as $user) {
         if (!$user->isCurrent()) {
             craft()->users->suspendUser($user);
         }
     }
     $this->setMessage(Craft::t('Users suspended.'));
     return true;
 }
コード例 #9
0
 public function performAction(ElementCriteriaModel $criteria)
 {
     // Get the selected category
     $categoryId = $this->getParams()->category;
     $category = craft()->forumCategories->getCategoryById($categoryId);
     // Make sure it's a valid one
     if (!$category) {
         $this->setMessage(Craft::t('The selected category could not be found.'));
         return false;
     }
     // Add the category to the selected elements
     $elements = $criteria->find();
     foreach ($elements as $element) {
         craft()->forumCategories->addCategoryToElement($element, $category);
     }
     // Success!
     $this->setMessage(Craft::t('Category added successfully.'));
     return true;
 }
 /**
  * @inheritDoc IElementAction::performAction()
  *
  * @param ElementCriteriaModel $criteria
  *
  * @return bool
  */
 public function performAction(ElementCriteriaModel $criteria)
 {
     $variants = $criteria->find();
     $attributes = ['price', 'minQty', 'maxQty', 'width', 'height', 'length', 'weight'];
     try {
         foreach ($variants as $variant) {
             foreach ($attributes as $attribute) {
                 $set = $this->getParams()->{'set' . ucfirst($attribute)};
                 if ($set) {
                     $variant->{$attribute} = $this->getParams()->{$attribute};
                 }
             }
             craft()->market_variant->save($variant);
         }
     } catch (Exception $e) {
         $this->setMessage(Craft::t('Error'));
         return false;
     }
     $this->setMessage(Craft::t('Variants updated.'));
     return true;
 }
コード例 #11
0
 /**
  * Paginates an ElementCriteriaModel instance.
  */
 public static function paginateCriteria(ElementCriteriaModel $criteria)
 {
     $currentPage = craft()->request->getPageNum();
     $limit = $criteria->limit;
     $total = $criteria->total();
     $totalPages = ceil($total / $limit);
     if ($currentPage > $totalPages) {
         $currentPage = $totalPages;
     }
     $offset = $limit * ($currentPage - 1);
     $path = craft()->request->getPath();
     $pageUrlPrefix = ($path ? $path . '/' : '') . craft()->config->get('pageTrigger');
     $last = $offset + $limit;
     if ($last > $total) {
         $last = $total;
     }
     $info = array('first' => $offset + 1, 'last' => $last, 'total' => $total, 'currentPage' => $currentPage, 'totalPages' => $totalPages, 'prevUrl' => $currentPage > 1 ? UrlHelper::getUrl($pageUrlPrefix . ($currentPage - 1)) : null, 'nextUrl' => $currentPage < $totalPages ? UrlHelper::getUrl($pageUrlPrefix . ($currentPage + 1)) : null);
     // Get the entities
     $criteria->offset = $offset;
     $entities = $criteria->find();
     return array($info, $entities);
 }
コード例 #12
0
 /**
  * @param ElementCriteriaModel $criteria
  * @param array                $disabledElementIds
  * @param array                $viewState
  * @param null|string          $sourceKey
  * @param null|string          $context
  * @param                      $includeContainer
  * @param                      $showCheckboxes
  *
  * @return string
  */
 public function getIndexHtml($criteria, $disabledElementIds, $viewState, $sourceKey, $context, $includeContainer, $showCheckboxes)
 {
     craft()->templates->includeJsResource('sproutemail/js/sproutmodal.js');
     craft()->templates->includeJs('var sproutModalInstance = new SproutModal(); sproutModalInstance.init();');
     sproutEmail()->mailers->includeMailerModalResources();
     $order = isset($viewState['order']) ? $viewState['order'] : 'dateCreated';
     $sort = isset($viewState['sort']) ? $viewState['sort'] : 'desc';
     $criteria->limit = null;
     $criteria->order = sprintf('%s %s', $order, $sort);
     return craft()->templates->render('sproutemail/entries/_entryindex', array('context' => $context, 'elementType' => new ElementTypeVariable($this), 'disabledElementIds' => $disabledElementIds, 'elements' => $criteria->find()));
 }
コード例 #13
0
 /**
  * Returns an element at a specific offset.
  *
  * @param int $offset The offset.
  *
  * @return BaseElementModel|null The element, if there is one.
  */
 public function nth($offset)
 {
     if (!isset($this->_matchedElementsAtOffsets) || !array_key_exists($offset, $this->_matchedElementsAtOffsets)) {
         $criteria = new ElementCriteriaModel($this->getAttributes(), $this->_elementType);
         $criteria->offset = $offset;
         $criteria->limit = 1;
         $elements = $criteria->find();
         if ($elements) {
             $this->_matchedElementsAtOffsets[$offset] = $elements[0];
         } else {
             $this->_matchedElementsAtOffsets[$offset] = null;
         }
     }
     return $this->_matchedElementsAtOffsets[$offset];
 }
コード例 #14
0
ファイル: CategoryElementType.php プロジェクト: kant312/sop
 /**
  * @inheritDoc IElementType::getIndexHtml()
  *
  * @param ElementCriteriaModel $criteria
  * @param array                $disabledElementIds
  * @param array                $viewState
  * @param string|null          $sourceKey
  * @param string|null          $context
  *
  * @return string
  */
 public function getIndexHtml($criteria, $disabledElementIds, $viewState, $sourceKey, $context)
 {
     if ($context == 'index' && $viewState['mode'] == 'structure') {
         $criteria->offset = 0;
         $criteria->limit = null;
         $source = $this->getSource($sourceKey, $context);
         return craft()->templates->render('_elements/categoryindex', array('viewMode' => $viewState['mode'], 'context' => $context, 'elementType' => new ElementTypeVariable($this), 'disabledElementIds' => $disabledElementIds, 'structure' => craft()->structures->getStructureById($source['structureId']), 'collapsedElementIds' => isset($viewState['collapsedElementIds']) ? $viewState['collapsedElementIds'] : array(), 'elements' => $criteria->find(), 'groupId' => $source['criteria']['groupId']));
     } else {
         return parent::getIndexHtml($criteria, $disabledElementIds, $viewState, $sourceKey, $context);
     }
 }
コード例 #15
0
ファイル: BaseElementType.php プロジェクト: kant312/sop
 /**
  * @inheritDoc IElementType::getIndexHtml()
  *
  * @param ElementCriteriaModel $criteria
  * @param array                $disabledElementIds
  * @param array                $viewState
  * @param null|string          $sourceKey
  * @param null|string          $context
  *
  * @return string
  */
 public function getIndexHtml($criteria, $disabledElementIds, $viewState, $sourceKey, $context)
 {
     $variables = array('viewMode' => $viewState['mode'], 'context' => $context, 'elementType' => new ElementTypeVariable($this), 'disabledElementIds' => $disabledElementIds);
     switch ($viewState['mode']) {
         case 'table':
             // Make sure the attribute is actually allowed
             $variables['attributes'] = $this->defineTableAttributes($sourceKey);
             // Ordering by an attribute?
             if (!empty($viewState['order']) && in_array($viewState['order'], array_keys($variables['attributes']))) {
                 $criteria->order = $viewState['order'] . ' ' . $viewState['sort'];
                 $variables['order'] = $viewState['order'];
                 $variables['sort'] = $viewState['sort'];
             }
             break;
         case 'structure':
             $source = $this->getSource($sourceKey, $context);
             $variables['structure'] = craft()->structures->getStructureById($source['structureId']);
             $variables['collapsedElementIds'] = isset($viewState['collapsedElementIds']) ? $viewState['collapsedElementIds'] : array();
             $variables['newChildUrl'] = isset($source['newChildUrl']) ? $source['newChildUrl'] : null;
             $criteria->offset = 0;
             $criteria->limit = null;
             break;
     }
     $variables['elements'] = $criteria->find();
     $template = '_elements/' . $viewState['mode'] . 'view/' . (!$criteria->offset ? 'container' : 'elements');
     return craft()->templates->render($template, $variables);
 }
コード例 #16
0
 /**
  * @inheritDoc IFieldType::getSearchKeywords()
  *
  * @param ElementCriteriaModel $criteria
  *
  * @return string
  */
 public function getSearchKeywords($criteria)
 {
     $titles = array();
     foreach ($criteria->find() as $element) {
         $titles[] = (string) $element;
     }
     return parent::getSearchKeywords($titles);
 }
コード例 #17
0
 /**
  * @inheritDoc IElementAction::performAction()
  *
  * @param ElementCriteriaModel $criteria
  *
  * @return bool
  */
 public function performAction(ElementCriteriaModel $criteria)
 {
     $users = $criteria->find();
     $undeletableIds = $this->_getUndeletableUserIds();
     // Are we transfering the user's content to a different user?
     $transferContentToId = $this->getParams()->transferContentTo;
     if (is_array($transferContentToId) && isset($transferContentToId[0])) {
         $transferContentToId = $transferContentToId[0];
     }
     if ($transferContentToId) {
         $transferContentTo = craft()->users->getUserById($transferContentToId);
         if (!$transferContentTo) {
             throw new Exception(Craft::t('No user exists with the ID “{id}”.', array('id' => $transferContentTo)));
         }
     } else {
         $transferContentTo = null;
     }
     // Delete the users
     foreach ($users as $user) {
         if (!in_array($user->id, $undeletableIds)) {
             craft()->users->deleteUser($user, $transferContentTo);
         }
     }
     $this->setMessage(Craft::t('Users deleted.'));
     return true;
 }
コード例 #18
0
 /**
  * @inheritDoc IElementType::getIndexHtml()
  *
  * @param ElementCriteriaModel $criteria
  * @param array                $disabledElementIds
  * @param array                $viewState
  * @param null|string          $sourceKey
  * @param null|string          $context
  * @param bool                 $includeContainer
  * @param bool                 $showCheckboxes
  *
  * @return string
  */
 public function getIndexHtml($criteria, $disabledElementIds, $viewState, $sourceKey, $context, $includeContainer, $showCheckboxes)
 {
     $variables = array('viewMode' => $viewState['mode'], 'context' => $context, 'elementType' => new ElementTypeVariable($this), 'disabledElementIds' => $disabledElementIds, 'collapsedElementIds' => craft()->request->getParam('collapsedElementIds'), 'showCheckboxes' => $showCheckboxes);
     // Special case for sorting by structure
     if (isset($viewState['order']) && $viewState['order'] == 'structure') {
         $source = $this->getSource($sourceKey, $context);
         if (isset($source['structureId'])) {
             $criteria->order = 'lft asc';
             $variables['structure'] = craft()->structures->getStructureById($source['structureId']);
             // Are they allowed to make changes to this structure?
             if ($context == 'index' && $variables['structure'] && !empty($source['structureEditable'])) {
                 $variables['structureEditable'] = true;
                 // Let StructuresController know that this user can make changes to the structure
                 craft()->userSession->authorize('editStructure:' . $variables['structure']->id);
             }
         } else {
             unset($viewState['order']);
         }
     } else {
         if (!empty($viewState['order']) && $viewState['order'] == 'score') {
             $criteria->order = 'score';
         } else {
             $sortableAttributes = $this->defineSortableAttributes();
             if ($sortableAttributes) {
                 $order = !empty($viewState['order']) && isset($sortableAttributes[$viewState['order']]) ? $viewState['order'] : ArrayHelper::getFirstKey($sortableAttributes);
                 $sort = !empty($viewState['sort']) && in_array($viewState['sort'], array('asc', 'desc')) ? $viewState['sort'] : 'asc';
                 // Combine them, accounting for the possibility that $order could contain multiple values,
                 // and be defensive about the possibility that the first value actually has "asc" or "desc"
                 // typeId             => typeId [sort]
                 // typeId, title      => typeId [sort], title
                 // typeId, title desc => typeId [sort], title desc
                 // typeId desc        => typeId [sort]
                 $criteria->order = preg_replace('/^(.*?)(?:\\s+(?:asc|desc))?(,.*)?$/i', "\$1 {$sort}\$2", $order);
             }
         }
     }
     switch ($viewState['mode']) {
         case 'table':
             // Get the table columns
             $variables['attributes'] = $this->getTableAttributesForSource($sourceKey);
             break;
     }
     $variables['elements'] = $criteria->find();
     $template = '_elements/' . $viewState['mode'] . 'view/' . ($includeContainer ? 'container' : 'elements');
     return craft()->templates->render($template, $variables);
 }