00001 <?php
00002
00016 class TSDStandardCategory extends TSDObject {
00017 public static $ATTRIBUTES = array(
00018 'id' => false,
00019 'name' => 'edit',
00020 'gradeId' => false
00021 );
00022
00029 public function __construct($id = '') {
00030 parent::__construct('TSDCategory', self::$ATTRIBUTES, 'id', $id);
00031 }
00032
00041 public function isValid() {
00042 return (
00043 ($this->id == '' || ctype_digit((string) $this->id)) &&
00044 (is_string($this->name) && $this->name != '') &&
00045 (ctype_digit((string) $this->gradeId) && $this->gradeId > 0)
00046 );
00047 }
00048
00061 public static function getList($constraints = array(), $limit = array(), $order = array(), $cnt = false) {
00062 return self::getListImpl('TSDStandardCategory', 'TSDCategory', array_keys(self::$ATTRIBUTES),
00063 $constraints, array(), $limit, $order, $cnt);
00064 }
00065
00072 public function getParent() {
00073 if(!$this->checkInit('Retrieve grade')) return null;
00074
00075 $grade = new TSDStandardGrade($this->gradeId);
00076 if(!$grade->isValid())
00077 return null;
00078 else
00079 return $grade;
00080 }
00081
00089 public function getIdentifier() {
00090 return $this->name;
00091 }
00092
00108 public function listChildren($constraints = array(), $limit = array(), $order = array(), $cnt = false, $withAlCnt = false) {
00109 if($withAlCnt) {
00110 if(SConfig::getDefault('common.serverClass') == 'dev')
00111 $v = 'DEV';
00112 else
00113 $v = 'LIVE';
00114 $keys = array_merge(array_keys(TSDStandardObjective::$ATTRIBUTES),
00115 array('(SELECT COUNT(*) FROM TSDStandardAlignment WHERE objectiveId = id AND version=\''
00116 . $v . '\') AS numAlignments'));
00117 return self::getListImpl('TSDStandardObjective', 'TSDObjective', $keys,
00118 $constraints, array('categoryId' => $this->id), $limit, $order, $cnt);
00119 }
00120 else
00121 return self::getListImpl('TSDStandardObjective', 'TSDObjective', array_keys(TSDStandardObjective::$ATTRIBUTES),
00122 $constraints, array('categoryId' => $this->id), $limit, $order, $cnt);
00123 }
00124
00125 // provided only because it is an abstract required function
00137 public function listValidChildren($constraints = array(), $limit = array(), $order = array(), $cnt = false) {
00138 return null;
00139 }
00140
00148 public function addObjective($description) {
00149 if(!$this->checkInit('Cannot add objectives')) return null;
00150 if(!TSD::can('edit')) {
00151 $this->setError('Permission denied');
00152 return false;
00153 }
00154
00155 $objective = new TSDStandardObjective();
00156 $objective->setAttr('description', $description);
00157 $objective->setAttr('categoryId', $this->id);
00158 if(!$objective->commit())
00159 return null;
00160
00161 return $objective;
00162 }
00163
00171 public function deleteObjectiveByDescription($description) {
00172 if(!$this->checkInit('Cannot delete objective(s)')) return null;
00173 if(!TSD::can('edit')) {
00174 $this->setError('Permission denied');
00175 return false;
00176 }
00177
00178 $objective = $this->listObjectives(array('description' => $description));
00179 foreach($objective as $o)
00180 if(!$o->delete())
00181 return false;
00182 return true;
00183 }
00184 }
00185
00186 ?>