Example #1
0
 /**
  * @param int $id
  *
  * @return ProductModel|bool
  */
 public static function fromPk($id)
 {
     $product = new self();
     if ($product->loadByPK($id)) {
         return $product;
     }
     return false;
 }
Example #2
0
 /**
  * @param bool $accessChecks
  * @param bool $load
  *
  * @return bool|NodeModel
  */
 public function findRoot($accessChecks = true, $load = true)
 {
     $node = new self();
     if ($accessChecks === false) {
         $node->ignoreAccessControl = true;
     }
     $lastParent = $this->getPK();
     $parent = $this->has('parent') ? $this->getParent(false) : false;
     while ($parent) {
         $lastParent = $parent;
         $node->loadByPK($parent);
         $parent = $node->has('parent') ? $node->getParent(false) : false;
     }
     if ($lastParent === $this->getPK()) {
         return $this;
     } else {
         if ($lastParent) {
             if ($load) {
                 $root = new self();
                 if (!$accessChecks) {
                     $root->ignoreAccessControl = true;
                 }
                 $root->loadByPK($lastParent);
                 return $root;
             } else {
                 return (string) $lastParent;
             }
         }
     }
     // TODO: we can never reach this?
     return false;
 }
Example #3
0
 public static function getNameFromId($metaId)
 {
     $meta = new self();
     $meta->loadByPK((int) $metaId);
     return $meta->displayField();
 }