/**
  * Load items from the database table and return them in the same type class that getAll() returns
  * A selector string or Selectors may be provided so that this can be used as a find() by descending classes that don't load all items at once.  
  *
  * @param Selectors|string|null $selectors Selectors or a selector string to find, or NULL to load all. 
  * @return WireArray Returns the same type as specified in the getAll() method.
  *
  */
 protected function ___load(WireArray $items, $selectors = null)
 {
     $query = $this->getLoadQuery($selectors);
     $result = $this->fuel('db')->query($query);
     $lookupField = $this->getLookupField();
     while ($row = $result->fetch_assoc()) {
         $item = $this->makeBlankItem();
         $lookupValue = $row[$lookupField];
         unset($row[$lookupField]);
         $item->addLookupItem($lookupValue, $row);
         foreach ($row as $field => $value) {
             $item->{$field} = $value;
         }
         if ($items->has($item)) {
             // LEFT JOIN is adding more elements of the same item, i.e. from lookup table
             // if the item is already present in $items, then use the existing one rather
             // and throw out the one we just created
             $item = $items->get($item);
             $item->addLookupItem($lookupValue, $row);
         } else {
             // add a new item
             $items->add($item);
         }
     }
     if ($result) {
         $result->free();
     }
     $items->setTrackChanges(true);
     return $items;
 }
 /**
  * Load items from the database table and return them in the same type class that getAll() returns
  * A selector string or Selectors may be provided so that this can be used as a find() by descending classes that don't load all items at once.  
  *
  * @param Selectors|string|null $selectors Selectors or a selector string to find, or NULL to load all. 
  * @return WireArray Returns the same type as specified in the getAll() method.
  *
  */
 protected function ___load(WireArray $items, $selectors = null)
 {
     $query = $this->getLoadQuery($selectors);
     $result = $this->fuel('db')->query($query);
     $lookupField = $this->getLookupField();
     while ($row = $result->fetch_assoc()) {
         $item = $this->makeBlankItem();
         foreach ($row as $field => $value) {
             if ($field == $lookupField) {
                 $item->addLookupItem($value);
             } else {
                 $item->{$field} = $value;
             }
         }
         if ($items->has($item)) {
             // LEFT JOIN is adding more elements of the same item, i.e. from lookup table
             $items->get($item)->addLookupItem($row[$lookupField]);
             // $items->get($item)->setArray($row);
         } else {
             $items->add($item);
         }
     }
     if ($result) {
         $result->free();
     }
     $items->setTrackChanges(true);
     return $items;
 }
 /**
  * Load items from the database table and return them in the same type class that getAll() returns
  *
  * A selector string or Selectors may be provided so that this can be used as a find() by descending classes that don't load all items at once.
  *
  * @param WireArray $items
  * @param Selectors|string|null $selectors Selectors or a selector string to find, or NULL to load all.
  * @return WireArray Returns the same type as specified in the getAll() method.
  *
  */
 protected function ___load(WireArray $items, $selectors = null)
 {
     $query = $this->getLoadQuery($selectors);
     $database = $this->wire('database');
     $sql = $query->getQuery();
     $stmt = $database->prepare($sql);
     $stmt->execute();
     $lookupField = $this->getLookupField();
     while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
         $item = $this->makeBlankItem();
         $lookupValue = $row[$lookupField];
         unset($row[$lookupField]);
         $item->addLookupItem($lookupValue, $row);
         foreach ($row as $field => $value) {
             $item->{$field} = $value;
         }
         if ($items->has($item)) {
             // LEFT JOIN is adding more elements of the same item, i.e. from lookup table
             // if the item is already present in $items, then use the existing one rather
             // and throw out the one we just created
             $item = $items->get($item);
             $item->addLookupItem($lookupValue, $row);
         } else {
             // add a new item
             $items->add($item);
         }
     }
     $stmt->closeCursor();
     $items->setTrackChanges(true);
     return $items;
 }
 /**
  * Include the file for a given module, but don't instantiate it 
  *
  * @param ModulePlaceholder|Module|string Expects a ModulePlaceholder or className
  * @return bool true on success
  *
  */
 public function includeModule($module)
 {
     if (is_string($module)) {
         $module = parent::get($module);
     }
     if (!$module) {
         return false;
     }
     if ($module instanceof ModulePlaceholder) {
         include_once $module->file;
     } else {
         // it's already been included, no doubt
     }
     return true;
 }
Example #5
0
 /**
  * Is the given class name installed?
  *
  * @param string $class
  * @return bool
  *
  */
 public function isInstalled($class)
 {
     return parent::get($class) !== null;
 }
Example #6
0
 /**
  * Get a Fieldgroup property or a field. 
  *
  * It is preferable to use getField() to retrieve fields from the fieldgroup because this checks other properties of the Fieldgroup. 
  *
  * @param string|int $key
  * @return Field|string|int|null
  *
  */
 public function get($key)
 {
     if ($key == 'fields') {
         return $this;
     }
     if ($key == 'fields_id') {
         $values = array();
         foreach ($this as $field) {
             $values[] = $field->id;
         }
         return $values;
     }
     if ($key == 'removedFields') {
         return $this->removedFields;
     }
     if (isset($this->settings[$key])) {
         return $this->settings[$key];
     }
     if ($value = parent::get($key)) {
         return $value;
     }
     return $this->getField($key);
 }
 /**
  * Get a setting or custom property of the Role
  *
  * @param string $key
  * @return mixed
  *
  */
 public function get($key)
 {
     if (isset($this->settings[$key])) {
         return $this->settings[$key];
     }
     return parent::get($key);
 }
Example #8
0
 /**
  * Get a value from this Pagefiles instance
  *
  * @param string $key
  * @return mixed
  *
  */
 public function get($key)
 {
     if ($key == 'page') {
         return $this->getPage();
     }
     if ($key == 'url') {
         return $this->url();
     }
     if ($key == 'path') {
         return $this->path();
     }
     return parent::get($key);
 }
Example #9
0
 /**
  * Given a Fieldtype name (or class name) return the instantiated Fieldtype module. 
  *
  * If the requested Fieldtype is not already installed, it will be installed here automatically. 
  *
  * @param string $key Fieldtype name or class name, or dynamic property of Fieldtypes
  * @return Fieldtype|null 
  *
  */
 public function get($key)
 {
     if (strpos($key, 'Fieldtype') !== 0) {
         $key = "Fieldtype" . ucfirst($key);
     }
     if (!($fieldtype = parent::get($key))) {
         $fieldtype = $this->modules->get($key);
     }
     if ($fieldtype instanceof ModulePlaceholder) {
         $fieldtype = $this->modules->get($fieldtype->className());
         $this->set($key, $fieldtype);
     }
     return $fieldtype;
 }
Example #10
0
 /**
  * Is the given class name installed?
  *
  * @param string $class Just a ModuleClassName, or optionally: ModuleClassName>=1.2.3 (operator and version)
  * @return bool
  *
  */
 public function isInstalled($class)
 {
     if (is_object($class)) {
         $class = $this->getModuleClass($class);
     }
     $operator = null;
     $requiredVersion = null;
     $currentVersion = null;
     if (!ctype_alnum($class)) {
         // class has something other than just a classnae, likely operator + version
         if (preg_match('/^([a-zA-Z0-9_]+)\\s*([<>=!]+)\\s*([\\d.]+)$/', $class, $matches)) {
             $class = $matches[1];
             $operator = $matches[2];
             $requiredVersion = $matches[3];
         }
     }
     if ($class === 'PHP' || $class === 'ProcessWire') {
         $installed = true;
         if (!is_null($requiredVersion)) {
             $currentVersion = $class === 'PHP' ? PHP_VERSION : $this->wire('config')->version;
         }
     } else {
         $installed = parent::get($class) !== null;
         if ($installed && !is_null($requiredVersion)) {
             $info = $this->getModuleInfo($class);
             $currentVersion = $info['version'];
         }
     }
     if ($installed && !is_null($currentVersion)) {
         $installed = $this->versionCompare($currentVersion, $requiredVersion, $operator);
     }
     return $installed;
 }
 /**
  * Retrieve a Notification by index or by id
  * 
  * @param int|string $key
  * @return Notification|null
  * 
  */
 public function get($key)
 {
     if (is_string($key) && strpos($key, 'noID') === 0) {
         $found = null;
         foreach ($this as $notification) {
             if ($notification->getID() === $key) {
                 $found = $notification;
                 break;
             }
         }
         return $found;
     }
     return parent::get($key);
 }