/**
  * Given an external system id and model class name, try to find the associated model if it exists. If it is
  * not found, a NotFoundException will be thrown.  Otherwise the model will be made and returned.
  * @param string $id
  * @param string $modelClassName
  * @return RedBeanModel $model
  * @throws NotFoundException
  */
 public static function getModelByExternalSystemIdAndModelClassName($id, $modelClassName)
 {
     assert('$id != null && is_string($id)');
     assert('is_string($modelClassName)');
     $tableName = $modelClassName::getTableName();
     $beans = ZurmoRedBean::find($tableName, ExternalSystemIdUtil::EXTERNAL_SYSTEM_ID_COLUMN_NAME . " = '{$id}'");
     assert('count($beans) <= 1');
     if (count($beans) == 0) {
         throw new NotFoundException();
     }
     return RedBeanModel::makeModel(end($beans), $modelClassName);
 }
示例#2
0
 public static function getSinceDateTime($dateTime)
 {
     assert('DateTimeUtil::isValidDbFormattedDateTime($dateTime)');
     return self::makeModels($beans = ZurmoRedBean::find('auditevent', "datetime >= '{$dateTime}'"));
 }
 /**
  * Gets all of the configuration entries for a module.
  * @param $user id
  * @return An array of arrays, keyed first on the module names, and
  * then the entry keys.
  */
 public static function getByModuleName($userId, $moduleName)
 {
     assert('$userId != null && is_int($userId)');
     assert('$moduleName != ""');
     $beans = ZurmoRedBean::find(UserConfiguration::getTableName(), "userId = {$userId} and moduleName = '{$moduleName}'");
     $moduleEntries = array();
     foreach ($beans as $bean) {
         if (!isset($moduleEntries[$bean->moduleName])) {
             $moduleEntries[$bean->moduleName] = array();
         }
         $moduleEntries[$bean->moduleName][$bean->key] = $bean->value;
     }
     return $moduleEntries;
 }
 /**
  * Handles constructing the relatedBeansAndModels with special attention to the case where it is PolyOneToMany
  * @param string $modelClassName
  * @param mixed $sqlOrBean
  */
 private function constructRelatedBeansAndModels($modelClassName, $sqlOrBean = '')
 {
     assert('is_string($sqlOrBean) || $sqlOrBean instanceof RedBean_OODBBean');
     $tableName = $modelClassName::getTableName();
     if (is_string($sqlOrBean)) {
         $this->relatedBeansAndModels = array_values($beans = ZurmoRedBean::find($tableName, $sqlOrBean));
     } else {
         assert('$sqlOrBean instanceof RedBean_OODBBean');
         $this->bean = $sqlOrBean;
         try {
             if ($this->bean->id > 0) {
                 if ($this->linkType == RedBeanModel::LINK_TYPE_POLYMORPHIC) {
                     $value = array();
                     $values['id'] = $this->bean->id;
                     $values['type'] = $this->bean->getMeta('type');
                     $this->relatedBeansAndModels = array_values(ZurmoRedBean::find($tableName, strtolower($this->linkName) . '_id = :id AND ' . strtolower($this->linkName) . '_type = :type', $values));
                 } else {
                     $relatedIds = ZurmoRedBeanLinkManager::getKeys($this->bean, $tableName, $this->resolveLinkNameForCasing());
                     $this->relatedBeansAndModels = array_values(ZurmoRedBean::batch($tableName, $relatedIds));
                 }
             } else {
                 $this->relatedBeansAndModels = array();
             }
         } catch (RedBean_Exception_SQL $e) {
             // SQLSTATE[42S02]: Base table or view not found...
             // SQLSTATE[42S22]: Column not found...
             if (!in_array($e->getSQLState(), array('42S02', '42S22'))) {
                 throw $e;
             }
             $this->relatedBeansAndModels = array();
         }
     }
 }
 /**
  * @param string $hashIndex row identifier for ContactWebFormEntry
  * @return array of module class names and display labels.
  */
 public static function getByHashIndex($hashIndex)
 {
     $modelClassName = get_called_class();
     $tableName = $modelClassName::getTableName();
     $columnName = self::getColumnNameByAttribute('hashIndex');
     $beans = ZurmoRedBean::find($tableName, "{$columnName} = '{$hashIndex}'");
     assert('count($beans) <= 1');
     if (count($beans) == 0) {
         return null;
     } else {
         return static::makeModel(end($beans), $modelClassName);
     }
 }
 public static function getDeptRefById($id)
 {
     return self::makeModels(ZurmoRedBean::find('departmentreference', "id =:id", array(':id' => $id)));
 }
 protected static function getByRelatedClassId($relatedModelClassName, $id, $modelClassName = null)
 {
     assert('is_string($relatedModelClassName)');
     assert('$relatedModelClassName != ""');
     assert('is_int($id)');
     //assert('$id > 0');
     assert('$modelClassName === null || is_string($modelClassName) && $modelClassName != ""');
     if ($modelClassName === null) {
         $modelClassName = get_called_class();
     }
     $tableName = $relatedModelClassName::getTableName();
     $foreignKeyName = strtolower($modelClassName) . '_id';
     $beans = ZurmoRedBean::find($tableName, "{$foreignKeyName} = {$id}");
     return self::makeModels($beans, $relatedModelClassName);
 }
示例#8
0
 public static function getByName($name)
 {
     assert('is_string($name) && $name != ""');
     return self::makeModels(ZurmoRedBean::find('contactstate', "name = :name ", array(':name' => $name)));
 }
示例#9
0
 public static function getUnitofmeasureByNameEdit($name, $id)
 {
     return self::makeModels(ZurmoRedBean::find('unitofmeasure', "name = :name AND id != :id", array(':name' => $name, ':id' => $id)));
 }
 /**
  * Given a language, is it in use as a default language by any of the users.
  * @param string $language
  * @return true if in use, otherwise returns false.
  */
 protected function isLanguageADefaultLanguageForAnyUsers($language)
 {
     assert('is_string($language)');
     $tableName = User::getTableName();
     $beans = ZurmoRedBean::find($tableName, "language = '{$language}'");
     if (count($beans) > 0) {
         return true;
     }
     return false;
 }
示例#11
0
 /**
  * Gets a currency by code.
  * @param $code String Code.
  * @return A model of type currency
  */
 public static function getByCode($code)
 {
     assert('is_string($code)');
     $tableName = Currency::getTableName();
     $beans = ZurmoRedBean::find($tableName, "code = '{$code}'");
     assert('count($beans) <= 1');
     if (count($beans) == 0) {
         throw new NotFoundException();
     }
     return static::makeModel(end($beans), 'Currency');
 }
示例#12
0
 public static function getCategoryByNameEdit($name, $id)
 {
     return self::makeModels(ZurmoRedBean::find('category', "name = :name AND id != :id", array(':name' => $name, ':id' => $id)));
 }
示例#13
0
 /**
  * Returns the display name for the model class.
  * @return dynamic label name based on module.
  */
 public static function getProductCode($productCode)
 {
     return self::makeModels(ZurmoRedBean::find('costbook', "productcode = :productcode ", array(':productcode' => $productCode)));
 }