Returns the number of papers for an exercise.

@param Exercise $exercise

@return int the number of exercise papers
429000
public function countExercisePapers(Exercise $exercise)
    {
        return (int) $this->getEntityManager()
            ->createQuery('
                SELECT COUNT(p)
                FROM UJM\ExoBundle\Entity\Attempt\Paper AS p
                WHERE p.exercise = :exercise
            ')
            ->setParameters([
                'exercise' => $exercise,
            ])
            ->getSingleScalarResult();
    }
1277575
public function getPageCount()
    {
        //build URI
        $strURI = Product::$baseProductUri . '/pdf/' . $this->getFileName() . '/pages';

        //sign URI
        $signedURI = Utils::sign($strURI);

        //get response stream
        $responseStream = Utils::ProcessCommand($signedURI, 'GET', '');

        $json = json_decode($responseStream);

        return count($json->Pages->List);
    }
147913
@Override
    public int numSheets()
    {
        int ret = -1;
        if(workbook != null)
            ret = workbook.getNumberOfSheets();
        else if(writableWorkbook != null)
            ret = writableWorkbook.getNumberOfSheets();
        return ret;
    }
45567
public function getConsumedWriteUnits($table = null)
    {
        if (is_null($table)) {
            return array_sum($this->writeUnit);
        } else {
            return (isset($this->writeUnit[$table])?$this->writeUnit[$table]:0);
        }
    }
941983
public function getPage(): int {
        if ($this->getLimit() === 0) {
            return 1;
        }
        $result = floor($this->getOffset() / (int)$this->getLimit()) + 1;
//        $result = intdiv($this->getOffset(), (int)$this->getLimit()) + 1;
        return (int)$result;
    }
656129
public function getObjectsCount() : int
    {
        return $this->nb_language_list->getSize() +
               $this->nb_role_list->getSize() +
               $this->nb_site_list->getSize()
        ;
    }
1257432
private function pickStepsByTags(Exercise $exercise, array $previousExercise = null)
    {
        $pickConfig = $exercise->getPick();

        // Retrieve the list of items to use
        $items = [];

        if (!empty($previousExercise) && Recurrence::ALWAYS !== $exercise->getRandomPick()) {
            // Just get the list of items from the previous paper
            foreach ($previousExercise['steps'] as $pickedStep) {
                foreach ($pickedStep['items'] as $pickedItem) {
                    $items[] = $exercise->getQuestion($pickedItem['id']);
                }
            }
        } else {
            // Get the list of items from exercise
            foreach ($exercise->getSteps() as $step) {
                $items = array_merge($items, $step->getQuestions());
            }
        }

        // Serialize items (we will automatically get items tags for filtering)
        $serializedItems = array_map(function (Item $pickedItem) {
            return $this->itemSerializer->serialize($pickedItem, [
                Transfer::SHUFFLE_ANSWERS,
                Transfer::INCLUDE_SOLUTIONS,
            ]);
        }, $items);

        $pickedItems = [];

        if (!empty($previousExercise) && Recurrence::ALWAYS !== $exercise->getRandomPick()) {
            // items are already filtered
            $pickedItems = $serializedItems;
        } else {
            // Only pick wanted tags (format : ['tagName', itemCount])
            foreach ($pickConfig['tags'] as $pickedTag) {
                $taggedItems = array_filter($serializedItems, function ($serializedItem) use ($pickedTag) {
                    return !empty($serializedItem['tags']) && in_array($pickedTag[0], $serializedItem['tags']);
                });

                // Get the correct number of items with the current tag
                // There is no error if we want more items than there are in the quiz,
                // we just stop to pick when there are no more available items
                $pickedItems = array_merge($pickedItems, static::pick($taggedItems, $pickedTag[1], true));
            }
        }

        // Shuffle items according to config
        if ((empty($previousExercise) && Recurrence::ONCE === $exercise->getRandomOrder())
            || Recurrence::ALWAYS === $exercise->getRandomOrder()) {
            shuffle($pickedItems);
        }

        // Create steps and fill it with the correct number of questions
        $pickedSteps = [];
        while (!empty($pickedItems)) {
            $pickedStep = $this->stepSerializer->serialize(new Step());
            $pickedStep['items'] = array_splice($pickedItems, 0, $pickConfig['pageSize']);
            $pickedSteps[] = $pickedStep;
        }

        return $pickedSteps;
    }
340593
public function exportAction(Exercise $exercise)
    {
        $this->assertHasPermission('ADMINISTRATE', $exercise);

        $file = $this->exerciseManager->export($exercise);

        $response = new StreamedResponse();
        $response->setCallBack(
            function () use ($file) {
                readfile($file);
            }
        );

        $name = $exercise->getResourceNode()->getName().'.json';
        $response->headers->set('Content-Transfer-Encoding', 'octet-stream');
        $response->headers->set('Content-Type', 'application/force-download');
        $response->headers->set('Content-Disposition', 'attachment; filename='.urlencode($name));
        $response->headers->set('Content-Type', 'application/json');
        $response->headers->set('Connection', 'close');
        $response->send();

        return new Response();
    }
597987
public function getStatistics(Item $question, Exercise $exercise = null, $finishedPapersOnly = false)
    {
        $questionStats = [];

        // We load all the answers for the question (we need to get the entities as the response in DB are not processable as is)
        $answers = $this->answerRepository->findByQuestion($question, $exercise, $finishedPapersOnly);

        // Number of Users that have seen the question
        $questionStats['seen'] = count($answers);

        // Grab answer data to pass it decoded to the question type
        // it doesn't need to know the whole Answer object
        $answersData = [];

        // get corrected answers for the Item in order to compute question success percentage
        $correctedAnswers = [];

        // Number of Users that have answered the question (no blank answer)
        $questionStats['answered'] = 0;

        if (!empty($answers)) {
            // Let the handler of the question type parse and compile the data
            $definition = $this->itemDefinitions->get($question->getMimeType());

            for ($i = 0; $i < $questionStats['seen']; ++$i) {
                $answer = $answers[$i];
                if (!empty($answer->getData())) {
                    ++$questionStats['answered'];
                    $answersData[] = json_decode($answer->getData(), true);
                }

                // for each answer get corresponding correction
                if ($definition instanceof AnswerableItemDefinitionInterface && isset($answersData[$i])) {
                    $corrected = $definition->correctAnswer($question->getInteraction(), $answersData[$i]);
                    $correctedAnswers[] = $corrected;
                }
            }

            // Let the handler of the question type parse and compile the data
            if ($definition instanceof AnswerableItemDefinitionInterface) {
                $questionStats['solutions'] = $definition->getStatistics($question->getInteraction(), $answersData, $questionStats['seen']);
            }
        }

        // get the number of good answers among all
        $nbGoodAnswers = 0;

        foreach ($correctedAnswers as $corrected) {
            if ($corrected instanceof CorrectedAnswer && 0 === count($corrected->getMissing()) && 0 === count($corrected->getUnexpected())) {
                ++$nbGoodAnswers;
            }
        }
        // compute question success percentage
        $questionStats['successPercent'] = $questionStats['answered'] > 0 ? (100 * $nbGoodAnswers) / $questionStats['answered'] : 0;

        return $questionStats;
    }
1367529
public function get_page_count() {
        if ($this->pagecount) {
            return $this->pagecount;
        }

        $status = $this->get_status();

        if ($status === self::STATUS_FAILED) {
            // The empty document will be returned.
            return 1;
        }

        if ($status !== self::STATUS_COMPLETE) {
            // No pages yet.
            return 0;
        }

        // Load the PDF to determine the page count.
        $temparea = make_request_directory();
        $tempsrc = $temparea . "/source.pdf";
        $this->get_combined_file()->copy_content_to($tempsrc);

        $pdf = new pdf();
        $pagecount = $pdf->load_pdf($tempsrc);
        $pdf->Close();

        if ($pagecount <= 0) {
            // Something went wrong. Return an empty page count again.
            return 0;
        }

        $this->pagecount = $pagecount;
        return $this->pagecount;
    }
98655
function getPageCount() {
		if (!$this->limit) {
			return 1;
		}
		$rem = ($this->getTotal() % $this->limit);
		$rem = ($rem >= 0) ? $rem : 0;
		$total_pages = ($this->getTotal() - $rem) / $this->limit;
		if ($rem)
			$total_pages++;
		return $total_pages;
	}
485951
protected function _getClassCount($class)
    {
        $count = 0;
        if ($class == self::CLASS_LETTER) {
            $count = $this->_getClassCount(self::CLASS_LOWER)
                   + $this->_getClassCount(self::CLASS_UPPER);
        } else {
            if (isset ($this->_tokenCounts[$class])) {
                $count = $this->_tokenCounts[$class];
            }
        }

        return $count;
    }
336284
public function numberOfPages(){
        if($this->totalAmount == 0){
            return 0;
        }
        $cantidad= $this->totalAmount / $this->amountPerPage;
        if(is_int($cantidad)){
            return $cantidad;
        }else{
            $cantidad_int= intval($cantidad);
            if($cantidad_int > $cantidad){
                return $cantidad_int;
            }else{
                return $cantidad_int + 1;
            }
        }
    }
1274630
public function numDocs()
    {
        $docs = 0;

        foreach ($this->_indices as $index) {
            $docs += $this->_indices->numDocs();
        }

        return $docs;
    }
980339
public function getCountForPagination($columns = ['*'])
    {
        $results = $this->runPaginationCountQuery($columns);

        // Once we have run the pagination count query, we will get the resulting count and
        // take into account what type of query it was. When there is a group by we will
        // just return the count of the entire results set since that will be correct.
        if (isset($this->groups)) {
            return count($results);
        }
        if (!isset($results[0])) {
            return 0;
        }
        if (is_object($results[0])) {
            return (int) $results[0]->aggregate;
        }

        return (int) array_change_key_case((array) $results[0])['aggregate'];
    }
577618
private function generateStructure(Exercise $exercise, Paper $previousPaper = null)
    {
        // The structure of the previous paper if any
        $previousStructure = !empty($previousPaper) ? json_decode($previousPaper->getStructure(), true) : null;

        // Get JSON representation of the full exercise
        $structure = $this->exerciseSerializer->serialize($exercise);
        // Pick questions for each steps and generate structure
        $structure['steps'] = $this->pickSteps($exercise, $previousStructure);

        return $structure;
    }
355874
public function findUnfinishedPapers(Exercise $exercise, User $user)
    {
        return $this->createQueryBuilder('p')
            ->where('p.user = :user')
            ->andWhere('p.exercise = :exercise')
            ->andWhere('p.end IS NULL')
            ->orderBy('p.start', 'DESC')
            ->setParameters([
                'user' => $user,
                'exercise' => $exercise,
            ])
            ->getQuery()
            ->getResult();
    }