/** * Assign LB or GF document to subsection * @param $subsId * @param $docId * @param $access */ public static function assignLBDocumentToSubsection($subsId, $docId, $access) { $subsId = intval($subsId); $docId = intval($docId); $access = intval($access); if ($subsId > 0 && $docId > 0 && $access <= 1) { $libDoc = LibraryDocs::model()->findByAttributes(array( 'Document_ID' => $docId, 'Subsection_ID' => $subsId, )); if (!$libDoc) { $condition = new CDbCriteria(); $condition->select = 'max(Sort_Numb) as Sort_Numb'; $condition->condition = "t.Subsection_ID = '" . $subsId . "'"; $sortNumRes = LibraryDocs::model()->find($condition); if ($sortNumRes) { $sortNum = intval($sortNumRes->Sort_Numb) + 1; } else { $sortNum = 0; } $libDoc = new LibraryDocs(); $libDoc->Access_Type = $access; $libDoc->Document_ID = $docId; $libDoc->Subsection_ID = $subsId; $libDoc->Sort_Numb = $sortNum; if ($libDoc->validate()) { $libDoc->save(); } } } }
/** * Delete subsection * @param $id */ public static function deleteSubsection($id) { $subsection = Subsections::model()->findByPk($id); LibraryDocs::model()->deleteAllByAttributes(array( 'Subsection_ID' => $subsection->Subsection_ID, )); $subsection->delete(); }
/** * Delete Storage with sections and subsections * @param $id */ public static function deleteStorage($id) { $storage = Storages::model()->with('sections.subsections')->findByPk($id); if ($storage) { if (count($storage->sections) > 0) { foreach($storage->sections as $section) { if (count($section->subsections)) { foreach ($section->subsections as $subsection) { LibraryDocs::model()->deleteAllByAttributes(array( 'Subsection_ID' => $subsection->Subsection_ID, )); $subsection->delete(); } } $section->delete(); } } $storage->delete(); } }
/** * Delete sub section * @param $id */ public static function deleteSubsection($section_id,$subsection_id) { $subsection = Subsections::model()->findByAttributes(array( 'Subsection_ID' =>$subsection_id )); if ($subsection) { LibraryDocs::model()->deleteAllByAttributes(array( 'Subsection_ID' => $subsection->Subsection_ID, )); $subsection->delete(); } //delete section if it is now have no panels $section = Sections::model()->findByPk($section_id); if (!count($section->subsections)) { $section->delete(); } }