| @@ 45-56 (lines=12) @@ | ||
| 42 | * @param self $return Variable to return found database record |
|
| 43 | * @return bool|null|self Field instance or null if 3rd parameter not passed |
|
| 44 | */ |
|
| 45 | public static function byNameOrID(QueryInterface $query, $nameOrID, self & $return = null) |
|
| 46 | { |
|
| 47 | // Create id or URL condition |
|
| 48 | $idOrUrl = new Condition('OR'); |
|
| 49 | $idOrUrl->add('FieldID', $nameOrID)->add('Name', $nameOrID); |
|
| 50 | ||
| 51 | // Perform query |
|
| 52 | $return = $query->entity(get_called_class())->where($idOrUrl)->first(); |
|
| 53 | ||
| 54 | // If only one argument is passed - return null, otherwise bool |
|
| 55 | return func_num_args() > 1 ? $return == null : $return; |
|
| 56 | } |
|
| 57 | ||
| 58 | /** @return string Get additional field value field name depending on its type */ |
|
| 59 | public function valueFieldName() |
|
| @@ 79-100 (lines=22) @@ | ||
| 76 | * @return bool|array True if material entities has been found and $return is passed |
|
| 77 | * or collection of identifiers if only two parameters is passed. |
|
| 78 | */ |
|
| 79 | public static function idsByNavigationID( |
|
| 80 | QueryInterface $query, |
|
| 81 | $navigationID, |
|
| 82 | &$return = array(), |
|
| 83 | $materialIDs = null |
|
| 84 | ) { |
|
| 85 | // Prepare query |
|
| 86 | $query->entity(CMS::MATERIAL_NAVIGATION_RELATION_ENTITY) |
|
| 87 | ->where('StructureID', $navigationID) |
|
| 88 | ->where('Active', 1); |
|
| 89 | ||
| 90 | // Add material identifier filter if passed |
|
| 91 | if (isset($materialIDs)) { |
|
| 92 | $query->where('MaterialID', $materialIDs); |
|
| 93 | } |
|
| 94 | ||
| 95 | // Perform database query and get only material identifiers collection |
|
| 96 | $return = $query->fields('MaterialID'); |
|
| 97 | ||
| 98 | // If only one argument is passed - return null, otherwise bool |
|
| 99 | return func_num_args() > 2 ? $return == null : $return; |
|
| 100 | } |
|
| 101 | ||
| 102 | /** |
|
| 103 | * Get self[] by field identifier and its value. |
|
| @@ 137-151 (lines=15) @@ | ||
| 134 | * @return bool|self[] True if material entities has been found and $return is passed |
|
| 135 | * or self[] if only two parameters is passed. |
|
| 136 | */ |
|
| 137 | public static function byNavigationID(QueryInterface $query, $navigationID, &$return = array()) |
|
| 138 | { |
|
| 139 | /** @var array $materialIds Collection of entity identifiers filtered by additional field */ |
|
| 140 | $materialIds = null; |
|
| 141 | if (static::idsByNavigationID($query, $navigationID, $materialIds)) { |
|
| 142 | $return = $query->entity(get_called_class()) |
|
| 143 | ->where('MaterialID', $materialIds) |
|
| 144 | ->where('Active', 1) |
|
| 145 | ->where('Published', 1) |
|
| 146 | ->exec(); |
|
| 147 | } |
|
| 148 | ||
| 149 | // If only one argument is passed - return null, otherwise bool |
|
| 150 | return func_num_args() > 2 ? $return == null : $return; |
|
| 151 | } |
|
| 152 | ||
| 153 | /** |
|
| 154 | * Get current entity instances collection by navigation identifier. |
|