Restore all deleted data

@param   mixed  $term  Data terms: int|array
@return  mixed
183349
public function undel($term)
    {
        if (
            false === $this->has_table() or
            true === $this->is_destructive
        ) {
            $this->set_error('Model '.get_class($this).' has no recoverable data');
            return false;
        }

        $term = $this->normalize_term($term);

        return $this->trash_it($term, false);
    }
449896
public function countLinesContaining($term)
    {
        if (is_bool($term) || is_null($term))
            trigger_error(sprintf('%s::countLinesLike - %s input seen, which results in empty string when typecast. Please check input value.', get_class($this), gettype($term)));

        if (is_scalar($term) || (is_object($term) && method_exists($term, '__toString')))
        {
            $term = (string)$term;

            if ($term === '')
                return count($this);

            $count = 0;

            for(parent::rewind(); parent::valid(); parent::next())
            {
                if (stripos(parent::current(), $term) !== false)
                    $count++;
            }

            parent::rewind();

            return $count;
        }

        throw new \InvalidArgumentException(get_class($this).'::countLinesLike - Argument 1 expected to be castable to string, "'.gettype($term).'" seen.');
    }
223451
public function search($term, $params = array())
    {
        $params = $this->getSearchParams($term, $params);
        $results = $this->http->get($this->request('search', $params))->json();

        return $results ?: $this->emptyResults();
    }
792469
public static function isReservedTerm($term)
    {
        if (! in_array($term, apply_filters('cuztom_reserved_terms', self::$reserved))) {
            return false;
        }

        return new \WP_Error('cuztom_reserved_term_used', __('Use of a reserved term.', 'cuztom'));
    }
1243551
public function getTermsData()
    {
        $data = [];

        try {
            $data = $this->getReport()->getData();
        } catch (\LogicException $e) {
            ;
        }

        foreach ($data as &$value) {
            $value['url'] = $this->getMerchandiserUrl($value['term']);
        }

        return $data;
    }
1180923
private static function generateFuzzyTermsTwice(string $term): array
    {
        $terms = [];
        foreach (self::generateFuzzyTerms($term) as $term) {
            $terms[] = $term;
            $terms = array_merge($terms, self::generateFuzzyTerms($term));
        }

        return $terms;
    }
1165110
public function restore_item($item) {
        global $CFG, $OUTPUT, $PAGE;

        require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');

        $user = get_admin();

        // Grab the course context.
        $context = \context_course::instance($this->_courseid);

        // Get the files..
        $fs = get_file_storage();
        $files = $fs->get_area_files($context->id, 'tool_recyclebin', TOOL_RECYCLEBIN_COURSE_BIN_FILEAREA, $item->id,
            'itemid, filepath, filename', false);

        if (empty($files)) {
            throw new \moodle_exception('Invalid recycle bin item!');
        }

        if (count($files) > 1) {
            throw new \moodle_exception('Too many files found!');
        }

        // Get the backup file.
        $file = reset($files);

        // Get a backup temp directory name and create it.
        $tempdir = \restore_controller::get_tempdir_name($context->id, $user->id);
        $fulltempdir = make_backup_temp_directory($tempdir);

        // Extract the backup to tempdir.
        $fb = get_file_packer('application/vnd.moodle.backup');
        $fb->extract_to_pathname($file, $fulltempdir);

        // Define the import.
        $controller = new \restore_controller(
            $tempdir,
            $this->_courseid,
            \backup::INTERACTIVE_NO,
            \backup::MODE_AUTOMATED,
            $user->id,
            \backup::TARGET_EXISTING_ADDING
        );

        // Prechecks.
        if (!$controller->execute_precheck()) {
            $results = $controller->get_precheck_results();

            // If errors are found then delete the file we created.
            if (!empty($results['errors'])) {
                fulldelete($fulltempdir);

                echo $OUTPUT->header();
                $backuprenderer = $PAGE->get_renderer('core', 'backup');
                echo $backuprenderer->precheck_notices($results);
                echo $OUTPUT->continue_button(new \moodle_url('/course/view.php', array('id' => $this->_courseid)));
                echo $OUTPUT->footer();
                exit();
            }
        }

        // Run the import.
        $controller->execute_plan();

        // Have finished with the controller, let's destroy it, freeing mem and resources.
        $controller->destroy();

        // Fire event.
        $event = \tool_recyclebin\event\course_bin_item_restored::create(array(
            'objectid' => $item->id,
            'context' => $context
        ));
        $event->add_record_snapshot('tool_recyclebin_course', $item);
        $event->trigger();

        // Cleanup.
        fulldelete($fulltempdir);
        $this->delete_item($item);
    }
80631
public function get($term = null, $limit = null, $offset = 0)
    {
        if (false === $this->has_table()) return false;

        $term = $this->normalize_term($term);

        $this->db->where($term);

        $limit !== null || $limit = $this->data_limit;

        // Limit the result if $limit is int and greater than 0
        if (false !== $limit and is_int($limit) and $limit > 0) {
            // Forget about offset for now :P
            $this->db->limit($limit, $offset);
        }

        if ( ! $data = $this->db->get($this->table)) {
            $this->set_error($this->db->error());
            return false;
        }

        return 1 === $limit ? $data->row() : $data->result();
    }
1160042
protected function getTags($term)
    {
        $source = $this->getSourceList();

        $titleField = $this->getTitleField();

        $query = $source
            ->filter($titleField . ':PartialMatch:nocase', $term)
            ->sort($titleField)
            ->limit($this->getLazyLoadItemLimit());

        // Map into a distinct list
        $items = [];
        $titleField = $this->getTitleField();
        foreach ($query->map('ID', $titleField) as $id => $title) {
            $items[$title] = [
                'id' => $title,
                'text' => $title,
            ];
        }

        return array_values($items);
    }
1185934
public function getTermsData()
    {
        if (empty($this->termsData)) {
            $this->termsData = $this->getResource()->getTermsDataFromThesaurus($this);
        }

        return $this->termsData;
    }
754343
public function withTerm(Term $term, $arguments = [])
    {
        $parameters = array_merge($arguments, [
            'tax_query' => [
                [
                    'taxonomy' => $term->taxonomy_slug,
                    'field' => 'slug',
                    'terms' => $term->slug,
                ],
            ],
        ]);

        return $this->query($parameters);
    }
789222
public function count($terms = null)
    {
        if (!$this->table()) {
            return 0;
        }

        $query = $this->select(['count(*) count']);

        $this->normalizeTerms($query, $terms);

        return (int) $query->execute()->fetch()['count'];
    }
310371
private function addTermFilterToSelect($term)
    {
        $select = $this->getSelect();

        if ($this->termsLinked === false) {
            $select->joinLeft(
                ['expansion_table' => $this->getTable(ThesaurusInterface::EXPANSION_TABLE_NAME)],
                new \Zend_Db_Expr("main_table.thesaurus_id = expansion_table.thesaurus_id"),
                [
                    'expansion_terms' => new \Zend_Db_Expr("GROUP_CONCAT( DISTINCT expansion_table.term SEPARATOR ',')"),
                ]
            );

            $select->joinLeft(
                ['reference_table' => $this->getTable(ThesaurusInterface::REFERENCE_TABLE_NAME)],
                new \Zend_Db_Expr(
                    "reference_table.term_id = expansion_table.term_id " .
                    "AND main_table." . ThesaurusInterface::THESAURUS_ID . " = reference_table." . ThesaurusInterface::THESAURUS_ID
                ),
                ['reference_terms' => new \Zend_Db_Expr("GROUP_CONCAT( DISTINCT reference_table.term SEPARATOR ',')")]
            );

            $select->group("main_table." . ThesaurusInterface::THESAURUS_ID);

            $select->where("expansion_table.term LIKE '%{$term}%'", $term)
                ->orWhere("reference_table.term LIKE '%{$term}%'", $term);

            $this->termsLinked = true;
        }

        return $select;
    }
526835
public static function query($terms)
    {
        return 'query='.urlencode(json_encode(array_map(function ($input, $field) {
            return [$field, '=', $input];
        }, $terms, array_keys($terms))));
    }
906084
protected function prepare_links( $term ) {
		$base = $this->namespace . '/' . $this->rest_base;
		$links = array(
			'self'       => array(
				'href' => rest_url( trailingslashit( $base ) . $term->term_id ),
			),
			'collection' => array(
				'href' => rest_url( $base ),
			),
			'about'      => array(
				'href' => rest_url( sprintf( 'wp/v2/taxonomies/%s', $this->taxonomy ) ),
			),
		);

		if ( $term->parent ) {
			$parent_term = get_term( (int) $term->parent, $term->taxonomy );
			if ( $parent_term ) {
				$links['up'] = array(
					'href'       => rest_url( trailingslashit( $base ) . $parent_term->term_id ),
					'embeddable' => true,
				);
			}
		}

		$taxonomy_obj = get_taxonomy( $term->taxonomy );
		if ( empty( $taxonomy_obj->object_type ) ) {
			return $links;
		}

		$post_type_links = array();
		foreach ( $taxonomy_obj->object_type as $type ) {
			$post_type_object = get_post_type_object( $type );
			if ( empty( $post_type_object->show_in_rest ) ) {
				continue;
			}
			$rest_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
			$post_type_links[] = array(
				'href' => add_query_arg( $this->rest_base, $term->term_id, rest_url( sprintf( 'wp/v2/%s', $rest_base ) ) ),
			);
		}
		if ( ! empty( $post_type_links ) ) {
			$links['https://api.w.org/post_type'] = $post_type_links;
		}

		return $links;
	}
137970
def drop_unused_terms(self):
		'''
		
		'''
		self.term_doc_mat = self.term_doc_mat.remove_terms(
			set(self.term_doc_mat.get_terms()) - set(self.priors.index)
		)
		self._reindex_priors()
		return self
729163
protected function _updateObject( $term, $fields ) {
		$fields = array_merge( array( 'taxonomy' => $this->_taxonomy ), $fields );
		$taxonomy = is_object( $term ) ? $term->taxonomy : $this->_taxonomy;

		$term_id_pair = wp_update_term( $term, $taxonomy, $fields );
		if ( is_wp_error( $term_id_pair ) ) {
			$this->_debug(
				'Update failed for term %d with message [%s] %s',
				is_object( $term ) ? $term->term_id : $term,
				$term_id_pair->get_error_code(),
				$term_id_pair->get_error_message()
			);

			return $term_id_pair;
		}

		$this->_debug( 'Updated term ' . $term_id_pair['term_id'] );

		return $term_id_pair['term_id'];
	}