src/Application.php
public function __async_priority()
    {
        $result = array('status' => true);

        // If we have changed priority of images
        if (isset($_POST['ids'])) {
            // For each received image id
            for ($i = 0; $i < count($_POST['ids']); $i++) {
                /** @var \samson\activerecord\gallery $photo Variable to store image info */
                $photo = null;
                // If we have such image in database
                if ($this->query->entity(CMS::MATERIAL_IMAGES_RELATION_ENTITY)->where('PhotoID', $_POST['ids'][$i])->first($photo)) {
                    // Reset it's priority and save it
                    $photo->priority = $i;
                    $photo->save();
                } else {
                    $result['status'] = false;
                    $result['message'] = 'Can not find images with specified ids!';
                }
            }
        } else {
            $result['status'] = false;
            $result['message'] = 'There are no images to sort!';
        }
        return $result;
    }
public function __async_priority()
    {
        $result = array('status' => true);

        // If we have changed priority of images
        if (isset($_POST['ids'])) {
            // For each received image id
            for ($i = 0; $i < count($_POST['ids']); $i++) {
                /** @var \samson\activerecord\gallery $photo Variable to store image info */
                $photo = null;
                // If we have such image in database
                if ($this->query->entity(CMS::MATERIAL_IMAGES_RELATION_ENTITY)->where('PhotoID', $_POST['ids'][$i])->first($photo)) {
                    // Reset it's priority and save it
                    $photo->priority = $i;
                    $photo->save();
                } else {
                    $result['status'] = false;
                    $result['message'] = 'Can not find images with specified ids!';
                }
            }
        } else {
            $result['status'] = false;
            $result['message'] = 'There are no images to sort!';
        }
        return $result;
    }
public function __async_priority ( ) { $ result = array ( 'status' => true ) ; // If we have changed priority of images if ( isset ( $ _POST [ 'ids' ] ) ) { // For each received image id for ( $ i = 0 ; $ i < count ( $ _POST [ 'ids' ] ) ; $ i ++ ) { /** @var \samson\activerecord\gallery $photo Variable to store image info */ $ photo = null ; // If we have such image in database if ( $ this -> query -> entity ( CMS :: MATERIAL_IMAGES_RELATION_ENTITY ) -> where ( 'PhotoID' , $ _POST [ 'ids' ] [ $ i ] ) -> first ( $ photo ) ) { // Reset it's priority and save it $ photo -> priority = $ i ; $ photo -> save ( ) ; } else { $ result [ 'status' ] = false ; $ result [ 'message' ] = 'Can not find images with specified ids!' ; } } } else { $ result [ 'status' ] = false ; $ result [ 'message' ] = 'There are no images to sort!' ; } return $ result ; }
Function to save image priority
@return array Async response array
Function to save image priority