/** * Constructor. * If an id is supplied, will query the database * to build up the basic information about the object. * If an id is not supplied, we just create an empty * artefact, ready to be filled up. * If the $new parameter is true, we can skip the query * because we know the artefact is new. * * @param int $id artefact.id * @param mixed $data optional data supplied for artefact * @param bool $new */ public function __construct($id = 0, $data = null, $new = FALSE) { if (!empty($id)) { if (empty($data)) { if (!($data = get_record('artefact', 'id', $id))) { throw new ArtefactNotFoundException(get_string('artefactnotfound', 'error', $id)); } } $this->id = $id; } else { $this->ctime = $this->mtime = time(); $this->dirty = true; } if (empty($data)) { $data = array(); } foreach ((array) $data as $field => $value) { if (property_exists($this, $field)) { if (in_array($field, array('atime', 'ctime', 'mtime'))) { $value = strtotime($value); } if ($field == 'tags' && !is_array($value)) { $value = preg_split("/\\s*,\\s*/", trim($value)); } $this->{$field} = $value; } } if (!empty($this->parent)) { $this->oldparent = $this->parent; } $this->artefacttype = $this->get_artefact_type(); if (!empty($data->artefacttype)) { if ($this->artefacttype != $data->artefacttype) { throw new SystemException(get_string('artefacttypemismatch', 'error', $data->artefacttype, $this->artefacttype)); } } // load tags if ($this->id) { $this->tags = ArtefactType::artefact_get_tags($this->id); } // load group permissions if ($this->group && !is_array($this->rolepermissions)) { $this->load_rolepermissions(); } $this->atime = time(); }
/** * This function returns a list of the given user's cpds. * * @param limit how many cpds to display per page * @param offset current page to display * @return array (count: integer, data: array) */ public static function get_cpds($offset = 0, $limit = 10) { global $USER; ($cpds = get_records_sql_array("SELECT * FROM {artefact}\n WHERE owner = ? AND artefacttype = 'cpd'\n ORDER BY id", array($USER->get('id')), $offset, $limit)) || ($cpds = array()); foreach ($cpds as $cpd) { if (!isset($cpd->tags)) { $cpd->tags = ArtefactType::artefact_get_tags($cpd->id); } } $result = array('count' => count_records('artefact', 'owner', $USER->get('id'), 'artefacttype', 'cpd'), 'data' => $cpds, 'offset' => $offset, 'limit' => $limit); return $result; }
public static function artefactchooser_get_element_data($artefact) { require_once 'license.php'; $artefactobj = artefact_instance_from_id($artefact->id); $artefact->safelicense = render_license($artefactobj); $artefact->tags = ArtefactType::artefact_get_tags($artefact->id); $artefact->safetags = is_array($artefact->tags) ? hsc(join(', ', $artefact->tags)) : ''; return $artefact; }
/** * This function returns a list of the given user's plans. * * @param limit how many plans to display per page * @param offset current page to display * @return array (count: integer, data: array) */ public static function get_plans($offset = 0, $limit = 10) { global $USER; ($plans = get_records_sql_array("SELECT * FROM {artefact}\n WHERE owner = ? AND artefacttype = 'plan'\n ORDER BY title ASC", array($USER->get('id')), $offset, $limit)) || ($plans = array()); foreach ($plans as &$plan) { if (!isset($plan->tags)) { $plan->tags = ArtefactType::artefact_get_tags($plan->id); } $plan->description = '<p>' . preg_replace('/\\n\\n/', '</p><p>', $plan->description) . '</p>'; } $result = array('count' => count_records('artefact', 'owner', $USER->get('id'), 'artefacttype', 'plan'), 'data' => $plans, 'offset' => $offset, 'limit' => $limit); return $result; }
} } } $data[$b->artefact]->views[$b->view]['ownername'] = $ownername; $data[$b->artefact]->views[$b->view]['ownerurl'] = $ownerurl; } } if (!isset($data[$b->artefact]->blocks)) { $data[$b->artefact]->blocks = array(); } if (!isset($data[$b->artefact]->blocks[$b->block])) { $data[$b->artefact]->blocks[$b->block] = (array) $b; !isset($data[$b->artefact]->views[$b->view]['extrablocks']) ? $data[$b->artefact]->views[$b->view]['extrablocks'] = 0 : $data[$b->artefact]->views[$b->view]['extrablocks']++; } if (!isset($data[$b->artefact]->tags)) { $data[$b->artefact]->tags = ArtefactType::artefact_get_tags($b->artefact); } } } foreach ($data as $id => $n) { $n->deleteform = pieform(deletenote_form($id, $n)); } } // Get the attached files. $noteids = array(); if ($data) { $noteids = array_keys($data); } $files = ArtefactType::attachments_from_id_list($noteids); if ($files) { safe_require('artefact', 'file');
public static function get_allfacts($blockid, $offset = 0, $limit = 3) { $get_user = "******"; $result_user = get_records_sql_array($get_user, array($blockid)); $id_user = intval($result_user[0]->owner); $datenow = time(); // time now to use for formatting facts by completion ($results = get_records_sql_array("\n SELECT a.id, at.artefact AS fact, at.completed, " . db_format_tsfield('completiondate') . ",\n a.title, a.description, a.parent, a.owner\n FROM {artefact} a\n JOIN {artefact_milestones_fact} at ON at.artefact = a.id\n WHERE a.artefacttype = 'fact'\n AND a.owner = ?\n ORDER BY at.completiondate ASC, a.id", array($id_user))) || ($results = array()); $count_records = count($results); $results = array_slice($results, $offset, $limit + $offset); // format the date and setup completed for display if fact is incomplete if (!empty($results)) { foreach ($results as $result) { if (!empty($result->completiondate)) { // if record hasn't been completed and completiondate has passed mark as such for display if ($result->completiondate < $datenow && !$result->completed) { $result->completed = -1; } $result->completiondate = format_date($result->completiondate, 'strftimedate'); } $result->description = '<p>' . preg_replace('/\\n\\n/', '</p><p>', $result->description) . '</p>'; $result->tags = ArtefactType::artefact_get_tags($result->id); } } $dateFormat = get_string('dateFormat', 'blocktype.milestones/allfacts'); $result = array('count' => $count_records, 'data' => $results, 'offset' => $offset, 'limit' => $limit, 'id' => $blockid, 'dateFormat' => $dateFormat); return $result; }
/** * This function returns a list of the current plans tasks. * * @param limit how many tasks to display per page * @param offset current page to display * @return array (count: integer, data: array) */ public static function get_tasks($plan, $offset = 0, $limit = 10) { $datenow = time(); // time now to use for formatting tasks by completion ($results = get_records_sql_array("\n SELECT a.id, at.artefact AS task, at.completed, " . db_format_tsfield('completiondate') . ",\n a.title, a.description, a.parent, a.owner\n FROM {artefact} a\n JOIN {artefact_plans_task} at ON at.artefact = a.id\n WHERE a.artefacttype = 'task' AND a.parent = ?\n ORDER BY at.completiondate ASC, a.id", array($plan), $offset, $limit)) || ($results = array()); // format the date and setup completed for display if task is incomplete if (!empty($results)) { foreach ($results as $result) { if (!empty($result->completiondate)) { // if record hasn't been completed and completiondate has passed mark as such for display if ($result->completiondate < $datenow && !$result->completed) { $result->completed = -1; } $result->completiondate = format_date($result->completiondate, 'strftimedate'); } $result->description = '<p>' . preg_replace('/\\n\\n/', '</p><p>', $result->description) . '</p>'; $result->tags = ArtefactType::artefact_get_tags($result->id); } } $result = array('count' => count_records('artefact', 'artefacttype', 'task', 'parent', $plan), 'data' => $results, 'offset' => $offset, 'limit' => $limit, 'id' => $plan); return $result; }
/** * This function returns a list of the current cpds activities. * * @param limit how many activities to display per page * @param offset current page to display * @return array (grandtotalhours: number, count: integer, data: array) * */ public static function get_activities($cpd, $offset = 0, $limit = 20) { ($results = get_records_sql_array("\n SELECT a.id, at.artefact AS activity, at.location, at.hours, " . db_format_tsfield('startdate') . ", " . db_format_tsfield('enddate') . ",\n a.title, a.description, a.parent, a.owner\n FROM {artefact} a\n JOIN {artefact_cpds_activity} at ON at.artefact = a.id\n WHERE a.artefacttype = 'activity' AND a.parent = ?\n ORDER BY at.startdate DESC", array($cpd), $offset, $limit)) || ($results = array()); // format the date and calculate grand total of hours spent $grandtotalhours = 0; if (!empty($results)) { foreach ($results as $result) { $grandtotalhours = $grandtotalhours + $result->hours; if (!empty($result->startdate)) { $result->startdate = strftime(get_string('strftimedate'), $result->startdate); if (!empty($result->enddate)) { $result->enddate = strftime(get_string('strftimedate'), $result->enddate); } } //$result->description = '<p>' . preg_replace('/\n\n/','</p><p>', $result->description) . '</p>'; $result->tags = ArtefactType::artefact_get_tags($result->id); } } $result = array('grandtotalhours' => $grandtotalhours, 'count' => count_records('artefact', 'artefacttype', 'activity', 'parent', $cpd), 'data' => $results, 'offset' => $offset, 'limit' => $limit, 'id' => $cpd); return $result; }