Esempio n. 1
0
 /**
  * Overloaded getter.
  * 
  * @param $limit string SQL
  * @param $offset int
  * @param $filter string SQL
  * @param $sort string SQL
  * @param $join string SQL
  * @return ComponentSet
  */
 public function Members($limit = "", $offset = "", $filter = "", $sort = "", $join = "")
 {
     $table = "Group_Members";
     if ($filter) {
         $filter = is_array($filter) ? $filter : array($filter);
     }
     if (is_numeric($limit)) {
         if (is_numeric($offset)) {
             $limit = "{$offset}, {$limit}";
         } else {
             $limit = "0, {$limit}";
         }
     } else {
         $limit = "";
     }
     // Get all of groups that this group contains
     $groupFamily = implode(", ", $this->collateFamilyIDs());
     $filter[] = "`{$table}`.GroupID IN ({$groupFamily})";
     $join .= " INNER JOIN `{$table}` ON `{$table}`.MemberID = `Member`.ID" . Convert::raw2sql($join);
     $result = singleton("Member")->instance_get($filter, $sort, $join, $limit, "ComponentSet");
     if (!$result) {
         $result = new ComponentSet();
     }
     $result->setComponentInfo("many-to-many", $this, "Group", $table, "Member");
     foreach ($result as $item) {
         $item->GroupID = $this->ID;
     }
     return $result;
 }
Esempio n. 2
0
	/**
	 * Returns a many-to-many component, as a ComponentSet.
	 * @param string $componentName Name of the many-many component
	 * @return ComponentSet The set of components
	 *
	 * @todo Implement query-params
	 */
	public function getManyManyComponents($componentName, $filter = "", $sort = "", $join = "", $limit = "") {
		$sum = md5("{$filter}_{$sort}_{$join}_{$limit}");
		if(isset($this->componentCache[$componentName . '_' . $sum]) && false != $this->componentCache[$componentName . '_' . $sum]) {
			return $this->componentCache[$componentName . '_' . $sum];
		}

		list($parentClass, $componentClass, $parentField, $componentField, $table) = $this->many_many($componentName);

		// Join expression is done on SiteTree.ID even if we link to Page; it helps work around
		// database inconsistencies
		$componentBaseClass = ClassInfo::baseDataClass($componentClass);

		if($this->ID && is_numeric($this->ID)) {
				
			if($componentClass) {
				$query = $this->getManyManyComponentsQuery($componentName, $filter, $sort, $join, $limit);
				$records = $query->execute();
				$result = $this->buildDataObjectSet($records, "ComponentSet", $query, $componentBaseClass);
				if($result) $result->parseQueryLimit($query); // for pagination support
				if(!$result) {
					$result = new ComponentSet();
				}
			}
		} else {
			$result = new ComponentSet();
		}
		$result->setComponentInfo("many-to-many", $this, $parentClass, $table, $componentClass);

		// If this record isn't in the database, then we want to hold onto this specific ComponentSet,
		// because it's the only copy of the data that we have.
		if(!$this->isInDB()) {
			$this->setComponent($componentName . '_' . $sum, $result);
		}

		return $result;
	}
Esempio n. 3
0
 /**
  * Returns a many-to-many component, as a ComponentSet.
  * @param string $componentName Name of the many-many component
  * @return ComponentSet The set of components
  *
  * @todo Implement query-params
  */
 public function getManyManyComponents($componentName, $filter = "", $sort = "", $join = "", $limit = "")
 {
     $sum = md5("{$filter}_{$sort}_{$join}_{$limit}");
     if (isset($this->componentCache[$componentName . '_' . $sum]) && false != $this->componentCache[$componentName . '_' . $sum]) {
         return $this->componentCache[$componentName . '_' . $sum];
     }
     list($parentClass, $componentClass, $parentField, $componentField, $table) = $this->many_many($componentName);
     if ($this->ID && is_numeric($this->ID)) {
         if ($componentClass) {
             $componentObj = singleton($componentClass);
             // Join expression is done on SiteTree.ID even if we link to Page; it helps work around
             // database inconsistencies
             $componentBaseClass = ClassInfo::baseDataClass($componentClass);
             $query = $componentObj->extendedSQL("`{$table}`.{$parentField} = {$this->ID}", $sort, $limit, "INNER JOIN `{$table}` ON `{$table}`.{$componentField} = `{$componentBaseClass}`.ID");
             array_unshift($query->select, "`{$table}`.*");
             if ($filter) {
                 $query->where[] = $filter;
             }
             if ($join) {
                 $query->from[] = $join;
             }
             $records = $query->execute();
             $result = $this->buildDataObjectSet($records, "ComponentSet", $query, $componentBaseClass);
             if (!$result) {
                 $result = new ComponentSet();
             }
         }
     } else {
         $result = new ComponentSet();
     }
     $result->setComponentInfo("many-to-many", $this, $parentClass, $table, $componentClass);
     // If this record isn't in the database, then we want to hold onto this specific ComponentSet,
     // because it's the only copy of the data that we have.
     if (!$this->isInDB()) {
         $this->setComponent($componentName . '_' . $sum, $result);
     }
     return $result;
 }