Give the field some data and ask it to return a value using one of many
possible modes.

@param mixed $data
@param integer $mode
@param integer $entry_id
@return array|string|null
3163
public function prepareExportValue($data, $mode, $entry_id = null)
    {
        $modes = (object)$this->getExportModes();

        $filepath = $this->getFilePath($data['file']);

        // No file, or the file that the entry is meant to have no
        // longer exists.
        if (!isset($data['file']) || !is_file($filepath)) {
            return null;
        }

        if ($mode === $modes->getFilename) {
            return $data['file'];
        }

        if ($mode === $modes->getObject) {
            $object = (object)$data;

            if (isset($object->meta)) {
                $object->meta = unserialize($object->meta);
            }

            return $object;
        }

        if ($mode === $modes->getPostdata) {
            return $data['file'];
        }
    }
423382
public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null)
    {
        $value = ($data['value'] === 'yes' ? 'Yes' : 'No');

        $wrapper->appendChild(new XMLElement($this->get('element_name'), ($encode ? General::sanitize($value) : $value)));
    }
15279
public function find($id, Data $data = null)
    {
        $id = $this->normalizeID($id);
        $registry = Registry::getInstance();

        if (!$data) {
            if ($data = $registry->get($this->class, $id)) {
                return $data;
            }
        }

        if (!$record = $this->doFind($id)) {
            return false;
        }

        $data = $this->pack($record, $data ?: null);
        $registry->set($data);

        return $data;
    }
856435
protected function _entry($mode = 'edit', $postdata = array())
    {
        $this->where_pri($this->primary_key, $this->primary_val);
        $select = $this->_build_select_details($mode);
        $where = $this->_build_where();
        $table_join = $this->_build_table_join();

        $db = Fruit_db::get_instance($this->connection);
        $db->query("SELECT {$select}\r\n FROM `{$this->table}`\r\n {$table_join}\r\n {$where}\r\n LIMIT 1");
        $this->result_row = array_merge((array )$db->row(), $postdata);

        // moved here to support conditions for buttons
        if (((!$this->is_edit($this->result_row) || $this->table_ro) && $mode == 'edit') or (!$this->is_view($this->result_row) &&
            $mode == 'view'))
            return self::error('Forbidden');

        $callback_method = 'before_' . $mode;
        if ($this->{$callback_method})
        {
            $path = $this->check_file($this->{$callback_method}['path'], $callback_method);
            include_once ($path);
            if (is_callable($this->{$callback_method}['callable']))
            {
                $postdata = new Fruit_postdata($this->result_row, $this);
                call_user_func_array($this->{$callback_method}['callable'], array(
                    $postdata,
                    $this->primary_val,
                    $this));
                $this->result_row = $postdata->to_array();
            }
        }

        $this->_set_field_names();

        /** conditions process */
        if ($this->condition)
        {
            foreach ($this->condition as $params)
            {
                if (!isset($params['mode'][$mode]))
                    continue;

                $params['value'] = $this->replace_text_variables($params['value'], $this->result_row);
                if (isset($this->result_row[$params['field']]) && $this->_compare($this->result_row[$params['field']], $params['operator'],
                    $params['value']))
                {
                    if (is_array($params['method']) && is_callable($params['method']))
                    {
                        call_user_func_array($params['method'], $params['params']);
                    }
                    elseif (is_callable(array($this, $params['method'])))
                    {
                        $this->condition_backup($params['method']);
                        call_user_func_array(array($this, $params['method']), $params['params']);
                    }
                    elseif (is_callable($params['method']))
                    {
                        call_user_func_array($params['method'], $params['params']);
                    }
                }
            }
        }
        /** hidden fields pass_var_process **/
        if ($mode == 'edit' && isset($this->pass_var['edit']))
        {
            $data = array();
            foreach ($this->result_row as $key => $val)
            {
                if (!isset($this->fields[$key]))
                {

                    foreach ($this->pass_var['edit'] as $pkey => $param)
                    {
                        $data[$key] = $val;
                    }
                }
            }
            if ($data)
                $this->pass_var['edit'][$pkey]['tmp_value'] = $this->replace_text_variables($param['value'], $data);
        }

        return $this->_render_details($mode);
    }
925056
public function get_from_course_module_id(int $id) : ?forum_entity {
        $records = $this->get_from_course_module_ids([$id]);
        return count($records) ? array_shift($records) : null;
    }
445931
protected function publishEntry(
            string $entryId,
            array $parameters,
            array $content
    ) {
        $entry = $this->entryFactory->getEntry($entryId, $parameters);
        $entry->setBody($content);
        
        $response = $this->publish($entry);
            
        $this->setStatus($entryId, $entry, $response);
    }
987579
public function getFieldValueByEntryAndField(Entry $entry, Field $field)
    {
        return $this->fieldValueRepo->findOneBy(['entry' => $entry, 'field' => $field]);
    }
150978
public function create(array $entryData)
    {
        foreach ($this->requiredProperties as $requiredPropertyName) {
            if (!isset($entryData[$requiredPropertyName])) {
                throw new ParserException('Missing required property "'.$requiredPropertyName.'"', 1);
            }
        }

        $entry = new Entry();
        $entry->setLineNumber((int)$entryData[self::KEY_LINE]);
        $entry->setColumnNumber((int)$entryData[self::KEY_CHARACTER]);

        if (isset($entryData[self::KEY_ID])) {
            $entry->setId($entryData[self::KEY_ID]);
        }

        if (isset($entryData[self::KEY_EVIDENCE])) {
            $entry->setEvidence($entryData[self::KEY_EVIDENCE]);
        }

        if (isset($entryData[self::KEY_RAW])) {
            $entry->setRaw($entryData[self::KEY_RAW]);

            if ($this->expectsParameters($entryData[self::KEY_RAW])) {
                $entry->setParameters($this->getErrorParameters($entryData));
            }
        }

        $entry->setReason($entryData[self::KEY_REASON]);

        return $entry;
    }
726977
final public function map($data, $mode)
    {
        if (null === $data) {
            return $data;
        }

        return $this->doMap($data, $mode);
    }
142362
public function write($data, $mode = 'w', $force = false)
    {
        $success = false;
        if ($this->open($mode, $force) === true) {
            if ($this->lock !== null && flock($this->handle, LOCK_EX) === false) {
                return false;
            }

            if (fwrite($this->handle, $data) !== false) {
                $success = true;
            }
            if ($this->lock !== null) {
                flock($this->handle, LOCK_UN);
            }
        }

        return $success;
    }
1347160
public function get ($id)
		{
			foreach ($this->_data as $category)
				if ($category->id == $id)
					return $category;

			return null;
		}
914361
public function find($id): EntryResult
    {
        $entry = EntryModel::on($this->connection)->whereUuid($id)->firstOrFail();

        $tags = $this->table('telescope_entries_tags')
                        ->where('entry_uuid', $id)
                        ->pluck('tag')
                        ->all();

        return new EntryResult(
            $entry->uuid,
            null,
            $entry->batch_id,
            $entry->type,
            $entry->family_hash,
            $entry->content,
            $entry->created_at,
            $tags
        );
    }
776645
public function getPageThemeById($id, $mode = AbstractQuery::HYDRATE_OBJECT)
    {
        $qb = $this->getEntityManager()->createQueryBuilder();
        /** @var $query \Doctrine\ORM\Query */

        $query = $qb->select('e, m')
            ->from($this->getEntity(), 'e')
            ->innerJoin('e.pageId', 'm')
            ->where('e.id = :id')
            ->setMaxResults(1)
            ->setParameter('id', $id)
            ->getQuery();

        return $query->getOneOrNullResult($mode);
    }
86494
protected function normalizeMode($type, $mode)
    {
        $normalizedMode = null;
        
        if (is_int($mode)) {
            $normalizedMode = $mode;
        } elseif (null !== $mode) {
            if (!is_array($mode)) {
                $mode = [$mode];
            }
            
            foreach ($mode as $m) {
                switch ($m) {
                    case 'optional':
                        if ($type == 'option') {
                            $value = InputOption::VALUE_OPTIONAL;
                        } else {
                            $value = InputArgument::OPTIONAL;
                        }
                        if (null === $normalizedMode) {
                            $normalizedMode = $value;
                        } else {
                            $normalizedMode = $normalizedMode | $value;
                        }
                        break;
                    
                    case 'required':
                        if ($type == 'option') {
                            $value = InputOption::VALUE_REQUIRED;
                        } else {
                            $value = InputArgument::REQUIRED;
                        }
                        if (null === $normalizedMode) {
                            $normalizedMode = $value;
                        } else {
                            $normalizedMode = $normalizedMode | $value;
                        }
                        break;
                    
                    case 'array':
                        if ($type == 'option') {
                            $value = InputOption::VALUE_IS_ARRAY;
                        } else {
                            $value = InputArgument::IS_ARRAY;
                        }
                        if (null === $normalizedMode) {
                            $normalizedMode = $value;
                        } else {
                            $normalizedMode = $normalizedMode | $value;
                        }
                        break;
                    
                    case 'none':
                        if ($type == 'option') {
                            if (null === $normalizedMode) {
                                $normalizedMode = InputOption::VALUE_NONE;
                            } else {
                                $normalizedMode = $normalizedMode | InputOption::VALUE_NONE;
                            }
                        }
                        break;
                    
                    default:
                        throw new Exception\InvalidArgumentException(
                            sprintf(
                                "Mode must be either 'none', 'optional', 'required' or 'array', passed '%s'",
                                $m
                            )
                        );
                        break;
                }
            }
        }
        
        return $normalizedMode;
    }
253302
private function getResult($key, $value, $mode) {
        if (is_numeric($key) && is_array($value)) return $this->createSql($value, $key);
        return $this->getConditional($key, $value, $mode);
    }
65923
public function deserialize($data, Entry $entry, array $options = [])
    {
        $this->sipe('title', 'setTitle', $data, $entry);
        $this->sipe('status', 'setStatus', $data, $entry);

        if (isset($data['user']['id'])) {
            $user = $this->userRepo->findOneBy(['uuid' => $data['user']['id']]);

            if (!empty($user)) {
                $entry->setUser($user);
            }
        }
        /* TODO: checks rights */
        $this->deserializeCategories($entry, $data['categories']);
        $this->deserializeKeywords($entry, $data['keywords']);

        if (isset($data['clacoForm']['id'])) {
            $clacoForm = $this->clacoFormRepo->findOneBy(['uuid' => $data['clacoForm']['id']]);

            if (!empty($clacoForm)) {
                $entry->setClacoForm($clacoForm);

                // Initializes status
                if (empty($entry->getStatus())) {
                    $status = $clacoForm->isModerated() ? Entry::PENDING : Entry::PUBLISHED;
                    $entry->setStatus($status);
                }

                // Sets values for fields
                $fields = $this->fieldRepo->findBy(['clacoForm' => $clacoForm]);

                foreach ($fields as $field) {
                    $uuid = $field->getUuid();

                    if (isset($data['values'][$uuid])) {
                        $fieldValue = $this->fieldValueRepo->findOneBy(['entry' => $entry, 'field' => $field]);

                        if (empty($fieldValue)) {
                            $fieldValue = new FieldValue();
                            $fieldValue->setEntry($entry);
                            $fieldValue->setField($field);

                            $fielFacetValue = new FieldFacetValue();
                            $fielFacetValue->setUser($entry->getUser());
                            $fielFacetValue->setFieldFacet($field->getFieldFacet());
                            $fielFacetValue->setValue($data['values'][$uuid]);
                            $fieldValue->setFieldFacetValue($fielFacetValue);

                            $this->om->persist($fielFacetValue);
                        } else {
                            $fieldValue->setValue($data['values'][$uuid]);
                        }
                        $this->om->persist($fieldValue);

                        $fieldsCategories = $this->fieldChoiceCategoryRepo->findBy(['field' => $field]);

                        foreach ($fieldsCategories as $fieldCategory) {
                            switch ($field->getType()) {
                                case FieldFacet::NUMBER_TYPE:
                                    $isCategoryValue = floatval($data['values'][$uuid]) === floatval($fieldCategory->getValue());
                                    break;
                                default:
                                    $isCategoryValue = $data['values'][$uuid] === $fieldCategory->getValue();
                            }
                            if ($isCategoryValue) {
                                $entry->addCategory($fieldCategory->getCategory());
                            }
                        }
                    }
                }
            }
        }
        $currentDate = new \DateTime();

        if (empty($entry->getCreationDate())) {
            $entry->setCreationDate($currentDate);
            $this->clacoFormManager->notifyCategoriesManagers($entry, [], $entry->getCategories());
        } else {
            $entry->setEditionDate($currentDate);
            $this->clacoFormManager->notifyCategoriesManagers($entry, $entry->getCategories(), $entry->getCategories());
        }

        return $entry;
    }
225821
protected function get_entry($entryid) {
        global $DB;

        if (empty($this->entriesdata[$entryid])) {
            $this->entriesdata[$entryid] = $DB->get_record('data_records', array( 'id' => $entryid ), '*', MUST_EXIST);
        }

        return $this->entriesdata[$entryid];
    }