/**
  * Returns a label or an array of labels for use as ENUMs.
  * 
  * @param string $enum ENUM specification for label
  * 
  * @return array|RedBean_OODBBean
  */
 public function enum($enum)
 {
     $oodb = $this->toolbox->getRedBean();
     if (strpos($enum, ':') === FALSE) {
         $type = $enum;
         $value = FALSE;
     } else {
         list($type, $value) = explode(':', $enum);
         $value = preg_replace('/\\W+/', '_', strtoupper(trim($value)));
     }
     $values = $oodb->find($type);
     if ($value === FALSE) {
         return $values;
     }
     foreach ($values as $enumItem) {
         if ($enumItem->name === $value) {
             return $enumItem;
         }
     }
     $newEnumItems = $this->dispenseLabels($type, array($value));
     $newEnumItem = reset($newEnumItems);
     $oodb->store($newEnumItem);
     return $newEnumItem;
 }
示例#2
0
文件: rb.php 项目: tejdeeps/tejcs.com
 /**
  * Constructor,
  * creates a new instance of DupManager.
  * @param RedBean_Toolbox $toolbox 
  */
 public function __construct(RedBean_Toolbox $toolbox)
 {
     $this->toolbox = $toolbox;
     $this->redbean = $toolbox->getRedBean();
     $this->associationManager = $this->redbean->getAssociationManager();
 }