123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?php
- class CrudObject extends ElggObject {
-
- function getCrudTemplate() {
- return crud_get_handler($this->getSubType());
- }
-
- function getParentEntity() {
- if ($this->parent_guid)
- return get_entity($this->parent_guid);
- }
-
- function getTitle($full_view=false) {
- $template = $this->getCrudTemplate();
- $title = $this->title;
- if (empty($title)) {
- $title = $template->getDefaultValue('title', '');
- }
- if ($template->title_extend && !$full_view) {
- $varname = $template->title_extend;
- $value = date(elgg_echo('crud:date_format'), $this->$varname);
- if ($title)
- $title .= ", $value";
- else
- $title = $value;
- }
- return $title;
- }
-
- function getTitleLink($full_view=false) {
- $title = $this->getTitle($full_view);
- $title_link = elgg_view('output/url', array(
- 'href' => $this->getURL(),
- 'text' => $title,
- ));
- return $title_link;
- }
-
- function listChildren() {
- $crud = $this->getCrudTemplate();
- if ($crud->children_categories) {
- return $this->listChildrenCategories();
- }
- else {
- return $this->listChildrenRaw();
- }
- }
-
- function listChildrenRaw() {
- $crud = $this->getCrudTemplate();
- $child_subtype = $crud->children_type;
- $child_options = array('full_view' => FALSE,
- 'types' => 'object',
- 'subtypes' => $child_subtype,
- 'limit' => 10,
- 'list_class' => 'list-'.$child_subtype,
- 'metadata_name_value_pairs' => array(
- array('name' => 'parent_guid',
- 'value' => $this->guid)
- ),
- );
- $children = elgg_list_entities_from_metadata($child_options);
- return $children;
- }
-
- function listChildrenCategories() {
- global $CONFIG;
- $crud = $this->getCrudTemplate();
- $category_property = $crud->children_categories;
- $categories = $this->$category_property;
- if (empty($categories)) {
- return $this->listChildrenRaw();
- }
- $child_subtype = $crud->children_type;
- foreach($categories as $category) {
- $children .= "<h4>".ucfirst($category)."</h4>";
- $child_options = array('full_view' => FALSE,
- 'types' => 'object',
- 'subtypes' => $child_subtype,
- 'limit' => 10,
- 'list_class' => 'list-'.$child_subtype,
- 'metadata_name_value_pairs' => array(
- array('name' => 'parent_guid',
- 'value' => $this->guid),
- array('name' => $category_property,
- 'value' => $category)
- ),
- );
- $children .= elgg_list_entities_from_metadata($child_options);
- }
- $children .= "<h4>".elgg_echo('crud:categories:other')."</h4>";
- $child_options = array('full_view' => FALSE,
- 'types' => 'object',
- 'subtypes' => $child_subtype,
- 'limit' => 10,
- 'list_class' => 'list-'.$child_subtype,
- 'metadata_name_value_pairs' => array(
- array('name' => 'parent_guid',
- 'value' => $this->guid))
- );
- $name_metastring_id = get_metastring_id($category_property);
- $value_metastring_ids = array();
- foreach($categories as $category) {
- $value_metastring_ids[] = get_metastring_id($category);
- }
- if (empty($value_metastring_ids)) {
- return "";
- }
- $value_metastring_id = implode(",", $value_metastring_ids);
- $child_options['wheres'][] = "NOT EXISTS (
- SELECT 1 FROM {$CONFIG->dbprefix}metadata md
- WHERE md.entity_guid = e.guid
- AND md.name_id = $name_metastring_id
- AND md.value_id IN ($value_metastring_id))";
- $children .= elgg_list_entities_from_metadata($child_options);
- return $children;
- }
-
- function getCrudIcon($size='tiny') {
- $crud = $this->getCrudTemplate();
-
- if ($crud->icon_var) {
- $var_name = $crud->icon_var;
- $status = $this->$var_name;
- if(empty($status)) {
- $status = 'new';
- }
- $icon = "mod/$crud->module/graphics/$crud->crud_type-icons/$status.png";
- }
- else {
- $icon = NULL;
- }
- return $icon;
- }
-
- function getChildren($count=FALSE) {
- $limit = 10;
- if ($count)
- $limit = 0;
- $crud = $this->getCrudTemplate();
- $child_subtype = $crud->children_type;
- $child_options = array('full_view' => FALSE,
- 'types' => 'object',
- 'subtypes' => $child_subtype,
- 'limit' => $limit,
- 'count' => $count,
- 'metadata_name_value_pairs' => array(
- array('name' => 'parent_guid',
- 'value' => $this->guid)
- )
- );
- $children = elgg_get_entities_from_metadata($child_options);
- return $children;
- }
-
- function getEmbeddedChild() {
- $embedded_children = $this->getChildren();
- if (!empty($embedded_children)) {
- if (count($embedded_children) == 1)
- $embedded_child = $embedded_children[0];
- }
- return $embedded_child;
- }
- }
|