Example #1
0
 /** @return static */
 public function setStatus($status)
 {
     if (!empty($status) && !static::GetNameForStatus($status)) {
         Exception::ThrowError(Exception::ENUM_BAD_VALUE, 'status', $status);
     }
     return $this->set('status', $status);
 }
Example #2
0
 /** @return static */
 public function removeLevel($level)
 {
     if (!empty($level) && !static::GetNameForLevel($level)) {
         Exception::ThrowError(Exception::ENUM_BAD_VALUE, 'level', $level);
     }
     return $this->bitRemove('level', $level);
 }
Example #3
0
 /**
  * Связь многие-к-многим через внешнюю таблицу
  * Если внешняя таблица $join_table не указана - название формируется из названий двух таблиц
  * $foreign_col - столбец запрашиваемого объекта в объединяющей таблице
  * $my_col - столбец текущего объекта в объединяющей таблице
  * $foreign_id - столбец Primary Key в таблице запрашиваемого объекта
  * $my_id - столбец Primary Key в таблице текущего объекта
  * $name - название связи для генерации методов
  * $one - название одного элемента
  */
 public function addManyToMany($schema, $join_table = null, $foreign_col = null, $my_col = null, $foreign_id = null, $my_id = null, $name = null, $one = null)
 {
     $m = $this->getManager();
     $s = $schema instanceof Schema ? $schema : $m->getSchema($schema, true);
     $n = $name ?: $s->getName();
     if (!($foreign_id = $foreign_id ?: $s->getPrimaryKey())) {
         Exception::ThrowError(Exception::PK_NOT_SET, $s->getName());
     }
     if ($join_table instanceof Schema) {
         $join_table = $join_table->getTable();
     }
     if (!$join_table) {
         $arr = array($this->getName(), $s->getName());
         asort($arr);
         $join_table = StaticStringy::underscored(join(' ', $arr));
     }
     $this->relations[$n] = array('type' => static::RELATION_MANY_TO_MANY, 'column' => $my_col ?: StaticStringy::underscored($this->getItemClass(false) . '_id'), 'schema' => $s, 'foreign_id' => $foreign_id, 'foreign_col' => $foreign_col ?: StaticStringy::underscored($s->getItemClass(false) . '_id'), 'my_id' => $my_id ?: $this->getPrimaryKey(), 'table' => $join_table, 'name' => $n, 'one' => $one ?: $s->getItemClass(false));
     return $this;
 }
Example #4
0
 /**
  * Класс для коллекции
  * @return static
  */
 public function setRepositoryClass($name, $class)
 {
     if (!class_exists($class) || !in_array('SQRT\\DB\\Repository', class_parents($class))) {
         Exception::ThrowError(Exception::NOT_REPOSITORY, $class);
     }
     $this->repositories[strtolower($name)] = $class;
     return $this;
 }
Example #5
0
File: Item.php Project: sqrt-pro/db
 /** Перенос загруженного или копирование файла */
 protected function copyFile($source, $dest)
 {
     $dir = dirname($dest);
     if (!is_dir($dir)) {
         mkdir($dir, 0777, true);
     }
     if (is_uploaded_file($source)) {
         $res = @move_uploaded_file($source, $dest);
     } else {
         $res = @copy($source, $dest);
     }
     if (!$res) {
         $err = error_get_last();
         Exception::ThrowError(Exception::PROCESSING_FILE, $err['message']);
     }
 }