/** * Check existing of Cabinets and shelves of user's projects * @param $year */ public static function checkLibraryStoragesForProjects($year) { if (Yii::app()->user->projectID == 'all') { $projects = Projects::model()->findAllByAttributes(array( 'Client_ID' => Yii::app()->user->clientID, )); if ($projects) { foreach ($projects as $project) { Storages::createProjectStorages($project->Project_ID, $year); } } } else { Storages::createProjectStorages(Yii::app()->user->projectID, $year); } }
/** * Add document to binder * @param $docId */ public static function addDocumentToBinder($docId) { $document = Documents::model()->findByPk($docId); if ($document) { $year = substr($document->Created, 0, 4); Storages::createProjectStorages($document->Project_ID, $year); $subsectionId = 0; if ($document->Document_Type == Documents::PM) { $payment = Payments::model()->findByAttributes(array( 'Document_ID' => $docId, )); $year = substr($payment->Payment_Check_Date, 0, 4); $subsectionId = Sections::createLogBinder($document->Project_ID, $document->Document_Type, $year); } elseif ($document->Document_Type == Documents::PO) { $po = Pos::model()->findByAttributes(array( 'Document_ID' => $docId, )); $year = substr($po->PO_Date, 0, 4); $subsectionId = Sections::createLogBinder($document->Project_ID, $document->Document_Type, $year); if ($po->PO_Backup_Document_ID != 0) { $bu = LibraryDocs::model()->findByAttributes(array( 'Document_ID' => $po->PO_Backup_Document_ID, 'Subsection_ID' => $subsectionId, )); if (!$bu) { $libDoc = new LibraryDocs(); $libDoc->Document_ID = $po->PO_Backup_Document_ID; $libDoc->Subsection_ID = $subsectionId; $libDoc->Access_Type = Storages::HAS_ACCESS; $libDoc->Sort_Numb = 0; if ($libDoc->validate()) { $libDoc->save(); } } } } $libDoc = LibraryDocs::model()->findByAttributes(array( 'Document_ID' => $docId, 'Subsection_ID' => $subsectionId, )); if (!$libDoc) { $libDoc = new LibraryDocs(); $libDoc->Document_ID = $docId; $libDoc->Subsection_ID = $subsectionId; $libDoc->Access_Type = Storages::HAS_ACCESS; $libDoc->Sort_Numb = 0; if ($libDoc->validate()) { $libDoc->save(); } } LibraryDocs::sortDocumentsInSubsection($subsectionId); } }
/** * Get Shelf for folder Create * @param $projectID * @param $year * @return CActiveRecord */ public static function getShelfForBinderCreate($projectID, $year) { // get shelf $shelf = Storages::model()->findByAttributes(array( 'Storage_Type' => Storages::SHELF, 'Created_By' => '0', 'Project_ID' => $projectID, 'Year' => $year, )); if (!$shelf) { Storages::createProjectStorages($projectID, $year); // get shelf $shelf = Storages::model()->findByAttributes(array( 'Storage_Type' => Storages::SHELF, 'Created_By' => '0', 'Project_ID' => $projectID, 'Year' => $year, )); } return $shelf; }