00001 <?php
00002
00017 class TSDStandardGrade extends TSDObject {
00018 public static $ATTRIBUTES = array(
00019 'id' => false,
00020 'name' => 'edit',
00021 'organizationId' => false
00022 );
00023
00030 public function __construct($id = '') {
00031 parent::__construct('TSDGrade', self::$ATTRIBUTES, 'id', $id);
00032 }
00033
00042 public function isValid() {
00043 return (
00044 ($this->id == '' || ctype_digit((string) $this->id)) &&
00045 (is_string($this->name) && $this->name != '') &&
00046 (ctype_digit((string) $this->organizationId) && $this->organizationId > 0)
00047 );
00048 }
00049
00065 public static function getList($constraints = array(), $limit = array(), $order = array(), $cnt = false) {
00066 return self::getListImpl('TSDStandardGrade', 'TSDGrade', array_keys(self::$ATTRIBUTES),
00067 $constraints, array(), $limit, $order, $cnt);
00068 }
00069
00076 public function getParent() {
00077 if(!$this->checkInit('Retrieve organization')) return null;
00078
00079 $organization = new TSDStandardOrganization($this->organizationId);
00080 if(!$organization->isValid())
00081 return null;
00082 else
00083 return $organization;
00084 }
00085
00093 public function getIdentifier() {
00094 return $this->name;
00095 }
00096
00113 public function listChildren($constraints = array(), $limit = array(), $order = array(), $cnt = false) {
00114 return self::getListImpl('TSDStandardCategory', 'TSDCategory', array_keys(TSDStandardCategory::$ATTRIBUTES),
00115 $constraints, array('gradeId' => $this->id), $limit, $order, $cnt);
00116 }
00117
00137 public function listValidChildren($constraints = array(), $limit = array(), $order = array(), $cnt = false) {
00138 $ljoin = 'LEFT JOIN TSDCategory ON TSDCategory.gradeId = TSDGrade.id
00139 LEFT JOIN TSDObjective ON TSDObjective.categoryId = TSDCategory.id';
00140 return self::getListImpl('TSDStandardCategory', 'TSDCategory', null, $constraints,
00141 array('gradeId' => $this->id, 'IS NOT NULL', 'TSDObjective.id' => 0),
00142 $limit, $order, $cnt, $ljoin);
00143 }
00144
00152 public function addCategory($name) {
00153 if(!$this->checkInit('Cannot add categories')) return null;
00154 if(!TSD::can('edit')) {
00155 $this->setError('Permission denied');
00156 return false;
00157 }
00158
00159 $category = new TSDStandardCategory();
00160 $category->setAttr('name', $name);
00161 $category->setAttr('gradeId', $this->id);
00162 if(!$category->commit())
00163 return null;
00164
00165 return $category;
00166 }
00167
00175 public function deleteCategoryByName($name) {
00176 if(!$this->checkInit('Cannot delete category(ies)')) return null;
00177 if(!TSD::can('edit')) {
00178 $this->setError('Permission denied');
00179 return false;
00180 }
00181
00182 $category = $this->listCategories(array('name' => $name));
00183 foreach($category as $c)
00184 if(!$c->delete())
00185 return false;
00186 return true;
00187 }
00188 }
00189
00190 ?>